@chevre/domain 23.0.0-alpha.2 → 23.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +102 -40
  2. package/example/src/chevre/event/updateSellerMakesOffersByIdentifier.ts +106 -0
  3. package/example/src/chevre/note/findNotes.ts +34 -0
  4. package/example/src/chevre/note/upsertNotesByIdentifier.ts +10 -5
  5. package/example/src/chevre/offerCatalog/updateManyOfferCatalogsByIds.ts +49 -0
  6. package/example/src/chevre/paymentServices/findPaymentServices.ts +37 -0
  7. package/example/src/chevre/product/findHasOfferCatalog.ts +31 -0
  8. package/example/src/chevre/reIndex.ts +1 -3
  9. package/example/src/chevre/roles/addAdminNotePermissionIfNotExists.ts +48 -0
  10. package/example/src/chevre/roles/{addAdminProductOfferPermissionIfNotExists.ts → addAdminPaymentServiceReadPermissionIfNotExists.ts} +20 -19
  11. package/example/src/chevre/roles/addAdminProductHasOfferCatalogReadPermissionIfNotExists.ts +33 -0
  12. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +1 -1
  13. package/example/src/chevre/roles/removePermissionIfExists.ts +1 -6
  14. package/example/src/chevre/unsetUnnecessaryFields.ts +5 -7
  15. package/example/src/objectId.ts +12 -0
  16. package/example/src/signPayload.ts +12 -7
  17. package/lib/chevre/errorHandler.d.ts +6 -2
  18. package/lib/chevre/errorHandler.js +18 -2
  19. package/lib/chevre/repo/categoryCode.d.ts +50 -7
  20. package/lib/chevre/repo/categoryCode.js +56 -15
  21. package/lib/chevre/repo/event.d.ts +14 -11
  22. package/lib/chevre/repo/event.js +44 -35
  23. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +24 -39
  24. package/lib/chevre/repo/eventSellerMakesOffer.js +88 -43
  25. package/lib/chevre/repo/mongoose/schemas/eventSeries.d.ts +2 -2
  26. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +5 -14
  27. package/lib/chevre/repo/mongoose/schemas/note.js +9 -0
  28. package/lib/chevre/repo/mongoose/schemas/product.d.ts +4 -4
  29. package/lib/chevre/repo/mongoose/schemas/product.js +2 -2
  30. package/lib/chevre/repo/note.d.ts +2 -9
  31. package/lib/chevre/repo/note.js +52 -18
  32. package/lib/chevre/repo/noteAboutOrder.d.ts +4 -0
  33. package/lib/chevre/repo/noteAboutOrder.js +17 -0
  34. package/lib/chevre/repo/offerCatalog.d.ts +17 -2
  35. package/lib/chevre/repo/offerCatalog.js +5 -2
  36. package/lib/chevre/repo/product.js +15 -14
  37. package/lib/chevre/repo/productHasOfferCatalog.d.ts +43 -0
  38. package/lib/chevre/repo/productHasOfferCatalog.js +71 -0
  39. package/lib/chevre/repository.d.ts +5 -0
  40. package/lib/chevre/repository.js +14 -1
  41. package/lib/chevre/service/assetTransaction/reserve/start.js +2 -2
  42. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +15 -0
  43. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +159 -0
  44. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +16 -0
  45. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +184 -0
  46. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +4 -1
  47. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +25 -138
  48. package/lib/chevre/service/event.js +1 -1
  49. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -3
  50. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +3 -3
  51. package/lib/chevre/service/offer/onEventChanged.js +2 -1
  52. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +19 -105
  53. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +1 -1
  54. package/lib/chevre/service/task/onResourceUpdated.js +1 -1
  55. package/package.json +4 -4
  56. package/example/src/chevre/aggregateEventSellerMakesOffer.ts +0 -32
  57. package/example/src/chevre/searchCategoryCodesByAggregate.ts +0 -31
  58. package/example/src/chevre/searchOfferCatalogItems.ts +0 -59
  59. package/example/src/chevre/searchPaymentServices.ts +0 -32
  60. package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +0 -50
  61. package/example/src/chevre/unsetUnnecessaryFieldsInTransaction.ts +0 -46
@@ -0,0 +1,12 @@
1
+
2
+ // tslint:disable:no-console no-magic-numbers no-null-keyword
3
+ import * as mongoose from 'mongoose';
4
+
5
+ // const MONGOLAB_URI = String(process.env.MONGOLAB_URI);
6
+
7
+ async function main() {
8
+ console.log(new mongoose.Types.ObjectId());
9
+ }
10
+
11
+ main()
12
+ .catch(console.error);
@@ -3,13 +3,18 @@ import * as jwt from 'jsonwebtoken';
3
3
 
4
4
  async function main(): Promise<void> {
5
5
  const payload = {
6
- member: {
7
- memberOf: {
8
- identifier: 'bronze',
9
- isTierOf: {
10
- identifier: 'DefaultMemberProgram'
11
- }
12
- }
6
+ /**
7
+ * アプリケーションオファーコード
8
+ */
9
+ identifier: 'LegacyReservation',
10
+ validFrom: '2025-10-20T00:00:00Z',
11
+ validThrough: '2025-10-25T00:00:00Z',
12
+ eligibleQuantity: { maxValue: 1 },
13
+ itemOffered: {
14
+ /**
15
+ * イベント識別子
16
+ */
17
+ identifier: '251025001001010900'
13
18
  }
14
19
  };
15
20
 
@@ -1,7 +1,11 @@
1
+ /**
2
+ * https://www.mongodb.com/ja-jp/docs/manual/reference/error-codes/
3
+ */
1
4
  export declare enum MongoErrorCode {
2
- DuplicateKey = 11000,
5
+ ConflictUpdateOperator = 40,
3
6
  MaxTimeMSExpired = 50,
4
- ExceededTimeLimit = 262
7
+ ExceededTimeLimit = 262,
8
+ DuplicateKey = 11000
5
9
  }
6
10
  export declare function isMongoError(error: unknown): Promise<boolean>;
7
11
  export declare function handleMongoError(error: unknown): Promise<unknown>;
@@ -24,11 +24,16 @@ exports.handleAWSError = handleAWSError;
24
24
  const http_status_1 = require("http-status");
25
25
  const factory_1 = require("./factory");
26
26
  let mongo;
27
+ let mongooseError;
28
+ /**
29
+ * https://www.mongodb.com/ja-jp/docs/manual/reference/error-codes/
30
+ */
27
31
  var MongoErrorCode;
28
32
  (function (MongoErrorCode) {
29
- MongoErrorCode[MongoErrorCode["DuplicateKey"] = 11000] = "DuplicateKey";
33
+ MongoErrorCode[MongoErrorCode["ConflictUpdateOperator"] = 40] = "ConflictUpdateOperator";
30
34
  MongoErrorCode[MongoErrorCode["MaxTimeMSExpired"] = 50] = "MaxTimeMSExpired";
31
35
  MongoErrorCode[MongoErrorCode["ExceededTimeLimit"] = 262] = "ExceededTimeLimit";
36
+ MongoErrorCode[MongoErrorCode["DuplicateKey"] = 11000] = "DuplicateKey";
32
37
  })(MongoErrorCode || (exports.MongoErrorCode = MongoErrorCode = {}));
33
38
  function isMongoError(error) {
34
39
  return __awaiter(this, void 0, void 0, function* () {
@@ -40,15 +45,21 @@ function isMongoError(error) {
40
45
  }
41
46
  function handleMongoError(error) {
42
47
  return __awaiter(this, void 0, void 0, function* () {
48
+ var _a;
43
49
  if (mongo === undefined) {
44
50
  mongo = (yield Promise.resolve().then(() => require('mongoose'))).mongo;
45
51
  }
52
+ if (mongooseError === undefined) {
53
+ mongooseError = (yield Promise.resolve().then(() => require('mongoose'))).Error;
54
+ }
46
55
  let handledError = error;
47
56
  if (handledError instanceof mongo.MongoError || handledError instanceof mongo.MongoServerError) {
48
57
  switch (handledError.code) {
58
+ case MongoErrorCode.ConflictUpdateOperator:
59
+ handledError = new factory_1.errors.Argument('', `Some updating fields conflict. code:${handledError.code} message:${handledError.message}`);
60
+ break;
49
61
  case MongoErrorCode.DuplicateKey:
50
62
  handledError = new factory_1.errors.AlreadyInUse('', [], `Some fields already in use. code:${handledError.code} message:${handledError.message}`);
51
- // no op
52
63
  break;
53
64
  case MongoErrorCode.MaxTimeMSExpired:
54
65
  case MongoErrorCode.ExceededTimeLimit:
@@ -60,6 +71,11 @@ function handleMongoError(error) {
60
71
  if (mongo.BSON.BSONError.isBSONError(handledError)) {
61
72
  handledError = new factory_1.errors.Argument('', handledError.message);
62
73
  }
74
+ // handle CastError(2025-10-27~)
75
+ // CastError: Cast to ObjectId failed for value "xxx" (type string) at path "_id" for model "xxxxxxxxxxxxx"
76
+ if (handledError instanceof mongooseError.CastError) {
77
+ handledError = new factory_1.errors.Argument(`${(_a = handledError.model) === null || _a === void 0 ? void 0 : _a.modelName}.${handledError.path}`, (handledError.reason instanceof Error) ? handledError.reason.message : handledError.message);
78
+ }
63
79
  return handledError;
64
80
  });
65
81
  }
@@ -1,31 +1,74 @@
1
1
  import { AnyExpression, Connection, FilterQuery, Types } from 'mongoose';
2
2
  import * as factory from '../factory';
3
- type IKeyOfProjection = keyof factory.categoryCode.ICategoryCode;
4
3
  type IUnset = {
5
4
  [key in keyof Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'color' | 'image' | 'paymentMethod'>]?: 1;
6
5
  };
6
+ type CategorySetIdentifierExceptMovieTicketType = Exclude<factory.categoryCode.CategorySetIdentifier, factory.categoryCode.CategorySetIdentifier.MovieTicketType>;
7
+ type ICategoryCodeExceptMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf'> & {
8
+ inCodeSet: {
9
+ typeOf: 'CategoryCodeSet';
10
+ identifier: CategorySetIdentifierExceptMovieTicketType;
11
+ };
12
+ };
13
+ type IMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf' | 'paymentMethod'> & {
14
+ inCodeSet: {
15
+ typeOf: 'CategoryCodeSet';
16
+ identifier: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
17
+ };
18
+ };
19
+ type IKeyOfProjection = keyof factory.categoryCode.ICategoryCode;
20
+ type IKeyOfProjectionExceptMovieTicketType = keyof ICategoryCodeExceptMovieTicketType;
7
21
  /**
8
22
  * 区分リポジトリ
9
23
  */
10
24
  export declare class CategoryCodeRepo {
11
25
  private readonly categoryCodeModel;
12
26
  constructor(connection: Connection);
13
- static CREATE_MONGO_CONDITIONS(params: factory.categoryCode.ISearchConditions): FilterQuery<factory.categoryCode.ICategoryCode>[];
27
+ static CREATE_MONGO_CONDITIONS(params: factory.categoryCode.ISearchConditions, options?: {
28
+ excludeMovieTicketType?: boolean;
29
+ }): FilterQuery<factory.categoryCode.ICategoryCode>[];
14
30
  static CREATE_AGGREGATE_PROJECTION(inclusion: IKeyOfProjection[]): {
15
31
  [field: string]: AnyExpression;
16
32
  };
17
33
  /**
18
- * 集計検索(publicな属性検索が目的)
34
+ * 区分集計検索(publicな属性検索が目的)
19
35
  */
20
- searchByAggregate(conditions: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.categoryCode.ICategoryCode[]>;
36
+ findCategoryCodesByAggregate(conditions: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjectionExceptMovieTicketType[]): Promise<(ICategoryCodeExceptMovieTicketType & {
37
+ id: string;
38
+ })[]>;
21
39
  /**
22
- * 検索
40
+ * 区分検索
23
41
  */
24
- projectFields(params: factory.categoryCode.ISearchConditions,
42
+ projectCategoryCodeFields(params: Omit<factory.categoryCode.ISearchConditions, 'inCodeSet' | 'paymentMethod'> & {
43
+ inCodeSet?: {
44
+ identifier?: {
45
+ $eq?: CategorySetIdentifierExceptMovieTicketType;
46
+ $in?: CategorySetIdentifierExceptMovieTicketType[];
47
+ };
48
+ };
49
+ },
50
+ /**
51
+ * 空の場合無効
52
+ */
53
+ inclusion: IKeyOfProjection[], options?: {
54
+ excludeMovieTicketType?: boolean;
55
+ }): Promise<(ICategoryCodeExceptMovieTicketType & {
56
+ id: string;
57
+ })[]>;
58
+ /**
59
+ * 決済カード区分検索
60
+ */
61
+ projectMovieTicketTypeFields(params: Omit<factory.categoryCode.ISearchConditions, 'inCodeSet'> & {
62
+ inCodeSet?: {
63
+ identifier?: {
64
+ $eq?: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
65
+ };
66
+ };
67
+ },
25
68
  /**
26
69
  * 空の場合無効
27
70
  */
28
- inclusion: IKeyOfProjection[]): Promise<(factory.categoryCode.ICategoryCode & {
71
+ inclusion: IKeyOfProjection[]): Promise<(IMovieTicketType & {
29
72
  id: string;
30
73
  })[]>;
31
74
  save(params: {
@@ -36,9 +36,29 @@ class CategoryCodeRepo {
36
36
  this.categoryCodeModel = connection.model(categoryCode_1.modelName, (0, categoryCode_1.createSchema)());
37
37
  }
38
38
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
39
- static CREATE_MONGO_CONDITIONS(params) {
39
+ static CREATE_MONGO_CONDITIONS(params, options) {
40
40
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
41
+ const excludeMovieTicketType = (options === null || options === void 0 ? void 0 : options.excludeMovieTicketType) === true;
41
42
  const andConditions = [];
43
+ if (excludeMovieTicketType) {
44
+ andConditions.push({
45
+ 'inCodeSet.identifier': {
46
+ $in: [
47
+ factory.categoryCode.CategorySetIdentifier.ContentRatingType,
48
+ factory.categoryCode.CategorySetIdentifier.CurrencyType,
49
+ factory.categoryCode.CategorySetIdentifier.CustomerType,
50
+ factory.categoryCode.CategorySetIdentifier.DistributorType,
51
+ factory.categoryCode.CategorySetIdentifier.MembershipType,
52
+ factory.categoryCode.CategorySetIdentifier.OfferCategoryType,
53
+ factory.categoryCode.CategorySetIdentifier.PaymentMethodType,
54
+ factory.categoryCode.CategorySetIdentifier.SeatingType,
55
+ factory.categoryCode.CategorySetIdentifier.ServiceType,
56
+ factory.categoryCode.CategorySetIdentifier.SoundFormatType,
57
+ factory.categoryCode.CategorySetIdentifier.VideoFormatType
58
+ ]
59
+ }
60
+ });
61
+ }
42
62
  // tslint:disable-next-line:no-single-line-block-comment
43
63
  /* istanbul ignore else */
44
64
  if (params.project !== undefined && params.project !== null) {
@@ -99,7 +119,6 @@ class CategoryCodeRepo {
99
119
  if (typeof params.inCodeSet.identifier.$eq === 'string') {
100
120
  andConditions.push({
101
121
  'inCodeSet.identifier': {
102
- $exists: true,
103
122
  $eq: params.inCodeSet.identifier.$eq
104
123
  }
105
124
  });
@@ -110,7 +129,6 @@ class CategoryCodeRepo {
110
129
  if (Array.isArray(inCodeSetIdentifierIn)) {
111
130
  andConditions.push({
112
131
  'inCodeSet.identifier': {
113
- $exists: true,
114
132
  $in: inCodeSetIdentifierIn
115
133
  }
116
134
  });
@@ -174,9 +192,9 @@ class CategoryCodeRepo {
174
192
  return projectStage;
175
193
  }
176
194
  /**
177
- * 集計検索(publicな属性検索が目的)
195
+ * 区分集計検索(publicな属性検索が目的)
178
196
  */
179
- searchByAggregate(conditions, inclusion) {
197
+ findCategoryCodesByAggregate(conditions, inclusion) {
180
198
  return __awaiter(this, void 0, void 0, function* () {
181
199
  var _a;
182
200
  const matchStages = CategoryCodeRepo.CREATE_MONGO_CONDITIONS(conditions)
@@ -190,8 +208,6 @@ class CategoryCodeRepo {
190
208
  : [],
191
209
  { $project: projectStage }
192
210
  ]);
193
- // tslint:disable-next-line:no-single-line-block-comment
194
- /* istanbul ignore else */
195
211
  if (typeof conditions.limit === 'number' && conditions.limit > 0) {
196
212
  const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
197
213
  aggregate.limit(conditions.limit * page)
@@ -201,9 +217,40 @@ class CategoryCodeRepo {
201
217
  });
202
218
  }
203
219
  /**
204
- * 検索
220
+ * 区分検索
221
+ */
222
+ projectCategoryCodeFields(params,
223
+ /**
224
+ * 空の場合無効
225
+ */
226
+ inclusion, options) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ const conditions = CategoryCodeRepo.CREATE_MONGO_CONDITIONS(params, options);
229
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
230
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
231
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
232
+ }
233
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
234
+ const query = this.categoryCodeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
235
+ if (typeof params.limit === 'number' && params.limit > 0) {
236
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
237
+ query.limit(params.limit)
238
+ .skip(params.limit * (page - 1));
239
+ }
240
+ // tslint:disable-next-line:no-single-line-block-comment
241
+ /* istanbul ignore else */
242
+ if (params.sort !== undefined) {
243
+ query.sort(params.sort);
244
+ }
245
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
246
+ .lean() // 2024-08-19~
247
+ .exec();
248
+ });
249
+ }
250
+ /**
251
+ * 決済カード区分検索
205
252
  */
206
- projectFields(params,
253
+ projectMovieTicketTypeFields(params,
207
254
  /**
208
255
  * 空の場合無効
209
256
  */
@@ -214,11 +261,6 @@ class CategoryCodeRepo {
214
261
  if (Array.isArray(inclusion) && inclusion.length > 0) {
215
262
  positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
216
263
  }
217
- else {
218
- // if (Array.isArray(exclusion) && exclusion.length > 0) {
219
- // positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
220
- // }
221
- }
222
264
  const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
223
265
  const query = this.categoryCodeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
224
266
  if (typeof params.limit === 'number' && params.limit > 0) {
@@ -280,7 +322,6 @@ class CategoryCodeRepo {
280
322
  'project.id': { $eq: p.attributes.project.id },
281
323
  codeValue: { $eq: p.attributes.codeValue },
282
324
  'inCodeSet.identifier': {
283
- $exists: true,
284
325
  $eq: p.attributes.inCodeSet.identifier
285
326
  }
286
327
  },
@@ -1,5 +1,5 @@
1
1
  import type { BulkWriteResult } from 'mongodb';
2
- import type { Connection, Document, FilterQuery } from 'mongoose';
2
+ import { Connection, FilterQuery } from 'mongoose';
3
3
  import * as factory from '../factory';
4
4
  import * as EventFactory from '../factory/event';
5
5
  export interface IAttributes4patchUpdate {
@@ -63,6 +63,10 @@ export type ICreatingEvent4ttts = Pick<factory.event.screeningEvent.IAttributes,
63
63
  export declare class EventRepo {
64
64
  private readonly eventModel;
65
65
  constructor(connection: Connection);
66
+ /**
67
+ * イベントIDを生成する
68
+ */
69
+ static CREATE_ID(): string;
66
70
  static CREATE_MONGO_CONDITIONS(conditions: ISearchConditions): FilterQuery<factory.event.screeningEvent.IEvent>[];
67
71
  /**
68
72
  * 複数イベントを作成する
@@ -136,19 +140,18 @@ export declare class EventRepo {
136
140
  attributes: IAttributes4patchUpdate;
137
141
  }): Promise<void>;
138
142
  /**
139
- * イベントを保管する
143
+ * 単一イベント編集
140
144
  */
141
- saveEvent(params: {
142
- id?: string;
143
- attributes: factory.event.screeningEvent.IAttributes;
145
+ updateEventById(params: {
146
+ id: string;
147
+ attributes: factory.event.screeningEvent.IAttributes & {
148
+ id?: never;
149
+ };
144
150
  /**
145
151
  * ドキュメント作成時には無視される
146
152
  */
147
153
  $unset?: IUnset;
148
- upsert: false;
149
- }): Promise<{
150
- id: string;
151
- }>;
154
+ }): Promise<void>;
152
155
  /**
153
156
  * sskts専用
154
157
  */
@@ -334,7 +337,7 @@ export declare class EventRepo {
334
337
  validationErrors: import("mongoose").Error[];
335
338
  } | undefined;
336
339
  }>;
337
- getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
340
+ getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
338
341
  _id: string;
339
342
  aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
340
343
  }> & import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
@@ -342,7 +345,7 @@ export declare class EventRepo {
342
345
  aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
343
346
  } & Required<{
344
347
  _id: string;
345
- }>, import("mongoose").QueryOptions<Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
348
+ }>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
346
349
  _id: string;
347
350
  aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
348
351
  }> & import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
@@ -21,11 +21,14 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.EventRepo = void 0;
24
+ const mongoose_1 = require("mongoose");
25
+ const uniqid = require("uniqid");
26
+ const errorHandler_1 = require("../errorHandler");
24
27
  const factory = require("../factory");
25
28
  const EventFactory = require("../factory/event");
26
- const event_1 = require("./mongoose/schemas/event");
27
- const errorHandler_1 = require("../errorHandler");
28
29
  const settings_1 = require("../settings");
30
+ const event_1 = require("./mongoose/schemas/event");
31
+ const USE_OBJECT_ID_AS_EVENT_ID = process.env.USE_OBJECT_ID_AS_EVENT_ID === '1';
29
32
  const AVAILABLE_PUBLIC_PROJECT_FIELDS = [
30
33
  'additionalProperty', 'aggregateReservation', 'attendeeCount', 'checkInCount', 'coaInfo',
31
34
  // 'description',
@@ -41,6 +44,13 @@ class EventRepo {
41
44
  constructor(connection) {
42
45
  this.eventModel = connection.model(event_1.modelName, (0, event_1.createSchema)());
43
46
  }
47
+ /**
48
+ * イベントIDを生成する
49
+ */
50
+ static CREATE_ID() {
51
+ // implement using ObjectId(2025-10-17~)
52
+ return (USE_OBJECT_ID_AS_EVENT_ID) ? new mongoose_1.Types.ObjectId().toHexString() : uniqid();
53
+ }
44
54
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
45
55
  static CREATE_MONGO_CONDITIONS(conditions) {
46
56
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
@@ -260,9 +270,8 @@ class EventRepo {
260
270
  */
261
271
  createManyEvents(params) {
262
272
  return __awaiter(this, void 0, void 0, function* () {
263
- const uniqid = yield Promise.resolve().then(() => require('uniqid'));
264
273
  const insertingDocs = params.attributes.map((p) => {
265
- return Object.assign({ _id: uniqid() }, p);
274
+ return Object.assign({ _id: EventRepo.CREATE_ID() }, p);
266
275
  });
267
276
  try {
268
277
  yield this.eventModel.insertMany(insertingDocs, { rawResult: true } // rawResult(2024-08-02~)
@@ -292,7 +301,6 @@ class EventRepo {
292
301
  upsertManyByAdditionalProperty(params, options) {
293
302
  return __awaiter(this, void 0, void 0, function* () {
294
303
  const { update } = options;
295
- const uniqid = yield Promise.resolve().then(() => require('uniqid'));
296
304
  const bulkWriteOps = [];
297
305
  const additionalProperties = [];
298
306
  const { events, additionalPropertyFilter, eventSeries, screeningRoom } = params;
@@ -347,7 +355,7 @@ class EventRepo {
347
355
  maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation, // ←適用しない
348
356
  eventStatus, superEvent } = creatingEventParams, // <-上書き可能な属性を限定的に
349
357
  setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent"]);
350
- const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() });
358
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { _id: EventRepo.CREATE_ID() });
351
359
  bulkWriteOps.push({
352
360
  updateOne: {
353
361
  filter,
@@ -389,7 +397,6 @@ class EventRepo {
389
397
  upsertManyScreeningEventByIdentifier(params, options) {
390
398
  return __awaiter(this, void 0, void 0, function* () {
391
399
  const { update } = options;
392
- const uniqid = yield Promise.resolve().then(() => require('uniqid'));
393
400
  const bulkWriteOps = [];
394
401
  const queryFilters = [];
395
402
  if (Array.isArray(params)) {
@@ -423,7 +430,7 @@ class EventRepo {
423
430
  }
424
431
  else {
425
432
  const { id, coaInfo, description, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation } = $set, setOnInsertFields = __rest($set, ["id", "coaInfo", "description", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation"]);
426
- const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { identifier, _id: uniqid() });
433
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { identifier, _id: EventRepo.CREATE_ID() });
427
434
  const updateOne = {
428
435
  filter,
429
436
  update: {
@@ -473,37 +480,41 @@ class EventRepo {
473
480
  });
474
481
  }
475
482
  /**
476
- * イベントを保管する
483
+ * 単一イベント編集
477
484
  */
478
- saveEvent(params) {
485
+ updateEventById(params) {
479
486
  return __awaiter(this, void 0, void 0, function* () {
480
- let savedEventId;
481
487
  let doc;
482
- const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
488
+ const _a = params.attributes, { identifier, project, typeOf, organizer, aggregateReservation, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, coaInfo } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "organizer", "aggregateReservation", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "coaInfo"])
489
+ // maximumPhysicalAttendeeCapacity, additionalProperty,
490
+ // eventStatus, location, name, superEvent, offers,
491
+ // doorTime, endDate, startDate
492
+ ;
483
493
  if (typeof typeOf !== 'string' || typeOf.length === 0) {
484
494
  throw new factory.errors.ArgumentNull('attributes.typeOf');
485
495
  }
496
+ if (typeof params.id !== 'string' || params.id === '') {
497
+ throw new factory.errors.ArgumentNull('id');
498
+ }
486
499
  try {
487
- if (params.id === undefined) {
488
- const uniqid = yield Promise.resolve().then(() => require('uniqid'));
489
- const id = uniqid();
490
- doc = yield this.eventModel.create(Object.assign(Object.assign({}, params.attributes), { _id: id }));
491
- savedEventId = id;
492
- }
493
- else {
494
- // const upsert: boolean = params.upsert === true;
495
- const upsert = false; // always false(2025-05-15~)
496
- doc = yield this.eventModel.findOneAndUpdate({
497
- _id: { $eq: params.id },
498
- typeOf: { $eq: typeOf }
499
- }, Object.assign({
500
- // 上書き禁止属性を除外(2022-08-24~)
501
- $setOnInsert: Object.assign({ typeOf,
502
- project }, (typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined), $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert, new: true, projection: { _id: 1 } })
503
- .lean()
504
- .exec();
505
- savedEventId = params.id;
506
- }
500
+ doc = yield this.eventModel.findOneAndUpdate({
501
+ _id: { $eq: params.id },
502
+ typeOf: { $eq: typeOf }
503
+ }, Object.assign({
504
+ // 編集のためのみのメソッドになったので、setOnInsertは廃止(2025-10-27~)
505
+ // 上書き禁止属性を除外(2022-08-24~)
506
+ // $setOnInsert: {
507
+ // typeOf,
508
+ // project,
509
+ // ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
510
+ // },
511
+ $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), {
512
+ upsert: false,
513
+ new: true,
514
+ projection: { _id: 1 }
515
+ })
516
+ .lean()
517
+ .exec();
507
518
  }
508
519
  catch (error) {
509
520
  if (yield (0, errorHandler_1.isMongoError)(error)) {
@@ -516,7 +527,6 @@ class EventRepo {
516
527
  if (doc === null) {
517
528
  throw new factory.errors.NotFound(this.eventModel.modelName);
518
529
  }
519
- return { id: savedEventId }; // optimize(2024-07-31~)
520
530
  });
521
531
  }
522
532
  /**
@@ -566,8 +576,7 @@ class EventRepo {
566
576
  if (typeof identifier !== 'string' || identifier.length === 0) {
567
577
  throw new factory.errors.ArgumentNull('identifier');
568
578
  }
569
- const uniqid = yield Promise.resolve().then(() => require('uniqid'));
570
- const id = uniqid();
579
+ const id = EventRepo.CREATE_ID();
571
580
  const doc = yield this.eventModel.findOneAndUpdate(
572
581
  // 全イベントにidentifierを保証したので、additionalPropertyによるフィルターからidentifierによるフィルターへ変更(2025-09-05~)
573
582
  // {
@@ -1,54 +1,39 @@
1
+ import type { BulkWriteResult } from 'mongodb';
1
2
  import type { Connection } from 'mongoose';
2
3
  import * as factory from '../factory';
3
- type IAggregateMakesOfferResult = Pick<factory.event.screeningEvent.ISellerMakesOffer, 'availabilityEnds' | 'availabilityStarts' | 'validFrom' | 'validThrough'> & {
4
- itemOffered: {
5
- serviceOutput: {
6
- reservationFor: {
7
- /**
8
- * イベントID
9
- */
10
- id: string;
11
- };
12
- };
13
- };
14
- };
15
4
  /**
16
- * イベントの販売者makesOfferリポジトリ
5
+ * イベントのアプリケーションオファーリポジトリ
17
6
  */
18
7
  export declare class EventSellerMakesOfferRepo {
19
8
  private readonly eventModel;
20
9
  constructor(connection: Connection);
21
10
  /**
22
- * 指定クライアントのオファーを集計する(2024-10-09~)
11
+ * 単一イベントのmakesOfferを更新する
23
12
  */
24
- aggregateMakesOffer(conditions: {
25
- limit?: number;
26
- page?: number;
13
+ updateOffersByEventId(params: {
27
14
  project: {
28
- id: {
29
- $eq: string;
30
- };
31
- };
32
- /**
33
- * アプリケーション(指定必須)
34
- */
35
- availableAtOrFrom: {
36
- id: {
37
- $eq: string;
38
- };
15
+ id: string;
39
16
  };
17
+ offers: factory.event.screeningEvent.ISellerMakesOffer[];
40
18
  itemOffered: {
41
- serviceOutput: {
42
- reservationFor: {
43
- /**
44
- * イベントID
45
- */
46
- id: {
47
- $in?: string[];
48
- };
49
- };
19
+ id: string;
20
+ };
21
+ }): Promise<void>;
22
+ /**
23
+ * イベントコードをキーにして複数編集
24
+ * 2025-10-27~
25
+ */
26
+ updateSellerMakesOffersByEventIdentifier(params: {
27
+ $set: Pick<factory.event.screeningEvent.IAttributes, 'project'> & {
28
+ identifier: string;
29
+ offers: {
30
+ seller: Pick<factory.event.screeningEvent.ISeller, 'makesOffer'>;
50
31
  };
51
32
  };
52
- }): Promise<IAggregateMakesOfferResult[]>;
33
+ }[]): Promise<{
34
+ bulkWriteResult: BulkWriteResult;
35
+ modifiedEvents: {
36
+ id: string;
37
+ }[];
38
+ } | void>;
53
39
  }
54
- export {};