@chevre/domain 20.4.0-alpha.9 → 20.4.0

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 (81) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +2 -1
  2. package/example/src/chevre/deleteMovieTicketCategoryChargePriceSpecs.ts +21 -0
  3. package/example/src/chevre/{deleteReservationTicketUnderNames.ts → deleteTasksByName.ts} +4 -2
  4. package/example/src/chevre/reIndex.ts +25 -0
  5. package/example/src/chevre/searchEventTicketOffers.ts +7 -4
  6. package/example/src/chevre/searchOfferCatalogs.ts +14 -16
  7. package/example/src/chevre/searchOffersByCatalog.ts +2 -1
  8. package/example/src/chevre/searchProductOffers.ts +38 -0
  9. package/example/src/chevre/searchTasks.ts +22 -0
  10. package/example/src/chevre/unsetUnnecessaryFields.ts +6 -11
  11. package/lib/chevre/errorHandler.js +1 -0
  12. package/lib/chevre/repo/accountTransaction.d.ts +0 -5
  13. package/lib/chevre/repo/accountTransaction.js +44 -38
  14. package/lib/chevre/repo/code.d.ts +0 -7
  15. package/lib/chevre/repo/code.js +0 -17
  16. package/lib/chevre/repo/event.d.ts +5 -4
  17. package/lib/chevre/repo/event.js +8 -17
  18. package/lib/chevre/repo/mongoose/model/accountTransaction.js +0 -5
  19. package/lib/chevre/repo/mongoose/model/member.js +5 -2
  20. package/lib/chevre/repo/mongoose/model/offer.js +19 -9
  21. package/lib/chevre/repo/mongoose/model/priceSpecification.js +19 -52
  22. package/lib/chevre/repo/mongoose/model/product.js +15 -2
  23. package/lib/chevre/repo/offer.d.ts +17 -2
  24. package/lib/chevre/repo/offer.js +77 -44
  25. package/lib/chevre/repo/offerCatalog.d.ts +3 -5
  26. package/lib/chevre/repo/offerCatalog.js +78 -37
  27. package/lib/chevre/repo/priceSpecification.d.ts +11 -0
  28. package/lib/chevre/repo/priceSpecification.js +44 -66
  29. package/lib/chevre/repo/task.d.ts +8 -0
  30. package/lib/chevre/repo/task.js +21 -9
  31. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -0
  32. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +93 -96
  33. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +3 -1
  34. package/lib/chevre/service/assetTransaction/moneyTransfer.js +2 -3
  35. package/lib/chevre/service/assetTransaction/pay.js +2 -3
  36. package/lib/chevre/service/assetTransaction/registerService/factory.d.ts +1 -1
  37. package/lib/chevre/service/assetTransaction/registerService/factory.js +6 -3
  38. package/lib/chevre/service/assetTransaction/registerService.js +3 -1
  39. package/lib/chevre/service/assetTransaction/reserve/factory/price.d.ts +1 -1
  40. package/lib/chevre/service/assetTransaction/reserve/factory/price.js +0 -7
  41. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +2 -2
  42. package/lib/chevre/service/assetTransaction/reserve/factory.js +0 -1
  43. package/lib/chevre/service/assetTransaction/reserve.js +47 -17
  44. package/lib/chevre/service/assetTransaction.d.ts +1 -1
  45. package/lib/chevre/service/code.d.ts +0 -8
  46. package/lib/chevre/service/code.js +1 -38
  47. package/lib/chevre/service/event.js +20 -3
  48. package/lib/chevre/service/moneyTransfer.d.ts +1 -1
  49. package/lib/chevre/service/moneyTransfer.js +7 -8
  50. package/lib/chevre/service/offer/event/authorize.js +5 -5
  51. package/lib/chevre/service/offer/event/factory.js +1 -1
  52. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +7 -7
  53. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +222 -346
  54. package/lib/chevre/service/offer/factory.d.ts +8 -3
  55. package/lib/chevre/service/offer/factory.js +44 -26
  56. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +11 -1
  57. package/lib/chevre/service/offer/product/searchProductOffers.js +15 -7
  58. package/lib/chevre/service/offer/product.d.ts +11 -4
  59. package/lib/chevre/service/offer/product.js +59 -50
  60. package/lib/chevre/service/payment/any/factory.js +30 -21
  61. package/lib/chevre/service/payment/any.js +11 -4
  62. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +22 -0
  63. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +183 -0
  64. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  65. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +13 -0
  66. package/lib/chevre/service/payment/movieTicket/getCredentials.js +45 -0
  67. package/lib/chevre/service/payment/movieTicket/validation.d.ts +15 -0
  68. package/lib/chevre/service/{assetTransaction/pay → payment}/movieTicket/validation.js +8 -7
  69. package/lib/chevre/service/payment/movieTicket.d.ts +10 -22
  70. package/lib/chevre/service/payment/movieTicket.js +15 -210
  71. package/lib/chevre/service/permit.d.ts +5 -1
  72. package/lib/chevre/service/permit.js +18 -11
  73. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +25 -53
  74. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -0
  75. package/lib/chevre/service/transaction/orderProgramMembership.js +5 -6
  76. package/lib/chevre/settings.d.ts +4 -1
  77. package/lib/chevre/settings.js +7 -1
  78. package/package.json +3 -3
  79. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.d.ts +0 -14
  80. package/lib/chevre/service/task/deleteAuthorization.d.ts +0 -6
  81. package/lib/chevre/service/task/deleteAuthorization.js +0 -29
@@ -32,37 +32,23 @@ class MongoRepository {
32
32
  }
33
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
34
34
  static CREATE_MONGO_CONDITIONS(params) {
35
+ var _a, _b, _c, _d, _e, _f, _g;
35
36
  const andConditions = [];
36
- // tslint:disable-next-line:no-single-line-block-comment
37
- /* istanbul ignore else */
38
- if (params.project !== undefined && params.project !== null) {
39
- if (params.project.id !== undefined && params.project.id !== null) {
40
- if (typeof params.project.id.$eq === 'string') {
41
- andConditions.push({
42
- 'project.id': {
43
- $eq: params.project.id.$eq
44
- }
45
- });
46
- }
47
- }
37
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
38
+ if (typeof projectIdEq === 'string') {
39
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
48
40
  }
49
41
  // tslint:disable-next-line:no-single-line-block-comment
50
42
  /* istanbul ignore else */
51
43
  if (params.id !== undefined && params.id !== null) {
52
44
  if (typeof params.id.$eq === 'string') {
53
- andConditions.push({
54
- _id: {
55
- $eq: params.id.$eq
56
- }
57
- });
45
+ andConditions.push({ _id: { $eq: params.id.$eq } });
58
46
  }
59
47
  }
60
48
  // tslint:disable-next-line:no-single-line-block-comment
61
49
  /* istanbul ignore else */
62
50
  if (params.typeOf !== undefined) {
63
- andConditions.push({
64
- typeOf: params.typeOf
65
- });
51
+ andConditions.push({ typeOf: params.typeOf });
66
52
  }
67
53
  if (params.appliesToCategoryCode !== undefined && params.appliesToCategoryCode !== null) {
68
54
  if (params.appliesToCategoryCode.$elemMatch !== undefined && params.appliesToCategoryCode.$elemMatch !== null) {
@@ -122,15 +108,23 @@ class MongoRepository {
122
108
  }
123
109
  });
124
110
  }
125
- if (params.appliesToMovieTicket !== undefined) {
126
- if (Array.isArray(params.appliesToMovieTicket.serviceTypes)) {
127
- andConditions.push({
128
- 'appliesToMovieTicket.serviceType': {
129
- $exists: true,
130
- $in: params.appliesToMovieTicket.serviceTypes
131
- }
132
- });
133
- }
111
+ const appliesToMovieTicketServiceTypeIn = (_c = params.appliesToMovieTicket) === null || _c === void 0 ? void 0 : _c.serviceTypes;
112
+ if (Array.isArray(appliesToMovieTicketServiceTypeIn)) {
113
+ andConditions.push({
114
+ 'appliesToMovieTicket.serviceType': {
115
+ $exists: true,
116
+ $in: appliesToMovieTicketServiceTypeIn
117
+ }
118
+ });
119
+ }
120
+ const appliesToMovieTicketServiceOutputTypeOfEq = (_f = (_e = (_d = params.appliesToMovieTicket) === null || _d === void 0 ? void 0 : _d.serviceOutput) === null || _e === void 0 ? void 0 : _e.typeOf) === null || _f === void 0 ? void 0 : _f.$eq;
121
+ if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
122
+ andConditions.push({
123
+ 'appliesToMovieTicket.serviceOutput.typeOf': {
124
+ $exists: true,
125
+ $eq: appliesToMovieTicketServiceOutputTypeOfEq
126
+ }
127
+ });
134
128
  }
135
129
  // tslint:disable-next-line:no-single-line-block-comment
136
130
  /* istanbul ignore else */
@@ -152,45 +146,12 @@ class MongoRepository {
152
146
  }
153
147
  });
154
148
  }
149
+ const priceEq = (_g = params.price) === null || _g === void 0 ? void 0 : _g.$eq;
150
+ if (typeof priceEq === 'number') {
151
+ andConditions.push({ price: { $eq: priceEq } });
152
+ }
155
153
  return andConditions;
156
154
  }
157
- // public async countCompoundPriceSpecifications<T extends factory.priceSpecificationType>(
158
- // params: factory.compoundPriceSpecification.ISearchConditions<T>
159
- // ): Promise<number> {
160
- // const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
161
- // return this.priceSpecificationModel.countDocuments(
162
- // { $and: conditions }
163
- // )
164
- // .setOptions({ maxTimeMS: 10000 })
165
- // .exec();
166
- // }
167
- // public async searchCompoundPriceSpecifications<T extends factory.priceSpecificationType>(
168
- // params: factory.compoundPriceSpecification.ISearchConditions<T>
169
- // ): Promise<factory.compoundPriceSpecification.IPriceSpecification<T>[]> {
170
- // const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
171
- // const query = this.priceSpecificationModel.find(
172
- // { $and: conditions },
173
- // {
174
- // __v: 0,
175
- // createdAt: 0,
176
- // updatedAt: 0
177
- // }
178
- // );
179
- // // tslint:disable-next-line:no-single-line-block-comment
180
- // /* istanbul ignore else */
181
- // if (params.limit !== undefined && params.page !== undefined) {
182
- // query.limit(params.limit)
183
- // .skip(params.limit * (params.page - 1));
184
- // }
185
- // // tslint:disable-next-line:no-single-line-block-comment
186
- // /* istanbul ignore else */
187
- // if (params.sort !== undefined) {
188
- // query.sort(params.sort);
189
- // }
190
- // return query.setOptions({ maxTimeMS: 10000 })
191
- // .exec()
192
- // .then((docs) => docs.map((doc) => doc.toObject()));
193
- // }
194
155
  count(params) {
195
156
  return __awaiter(this, void 0, void 0, function* () {
196
157
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
@@ -277,10 +238,27 @@ class MongoRepository {
277
238
  .exec();
278
239
  });
279
240
  }
241
+ deleteUnnecessaryMovieTicketTypeChargePriceSpecs(params) {
242
+ var _a;
243
+ return __awaiter(this, void 0, void 0, function* () {
244
+ return this.priceSpecificationModel.deleteMany(Object.assign({ typeOf: { $eq: factory.priceSpecificationType.MovieTicketTypeChargeSpecification }, price: { $eq: 0 } }, (typeof ((_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === 'string')
245
+ ? { 'project.id': { $eq: params.project.id } }
246
+ : undefined))
247
+ .exec();
248
+ });
249
+ }
280
250
  getCursor(conditions, projection) {
281
251
  return this.priceSpecificationModel.find(conditions, projection)
282
252
  .sort({ price: factory.sortType.Ascending })
283
253
  .cursor();
284
254
  }
255
+ reIndex() {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ // return this.priceSpecificationModel.collection.name;
258
+ return this.priceSpecificationModel.db.db.command({
259
+ reIndex: this.priceSpecificationModel.collection.name
260
+ });
261
+ });
262
+ }
285
263
  }
286
264
  exports.MongoRepository = MongoRepository;
@@ -55,6 +55,14 @@ export declare class MongoRepository {
55
55
  id: string;
56
56
  };
57
57
  }): Promise<void>;
58
+ deleteByName(params: {
59
+ name: factory.taskName;
60
+ }): Promise<{
61
+ ok?: number | undefined;
62
+ n?: number | undefined;
63
+ } & {
64
+ deletedCount?: number | undefined;
65
+ }>;
58
66
  aggregateTask(params: {
59
67
  project?: {
60
68
  id?: {
@@ -29,9 +29,13 @@ class MongoRepository {
29
29
  }
30
30
  // tslint:disable-next-line:max-func-body-length
31
31
  static CREATE_MONGO_CONDITIONS(params) {
32
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
33
33
  const andConditions = [];
34
- const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
34
+ const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
35
+ if (typeof idEq === 'string') {
36
+ andConditions.push({ _id: { $eq: idEq } });
37
+ }
38
+ const projectIdEq = (_c = (_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.$eq;
35
39
  if (typeof projectIdEq === 'string') {
36
40
  andConditions.push({ 'project.id': { $eq: projectIdEq } });
37
41
  }
@@ -39,11 +43,11 @@ class MongoRepository {
39
43
  andConditions.push({ name: { $eq: params.name } });
40
44
  }
41
45
  else {
42
- const nameIn = (_c = params.name) === null || _c === void 0 ? void 0 : _c.$in;
46
+ const nameIn = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$in;
43
47
  if (Array.isArray(nameIn)) {
44
48
  andConditions.push({ name: { $in: nameIn } });
45
49
  }
46
- const nameNin = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$nin;
50
+ const nameNin = (_e = params.name) === null || _e === void 0 ? void 0 : _e.$nin;
47
51
  if (Array.isArray(nameNin)) {
48
52
  andConditions.push({ name: { $nin: nameNin } });
49
53
  }
@@ -89,7 +93,7 @@ class MongoRepository {
89
93
  }
90
94
  });
91
95
  }
92
- const dateAbortedGte = (_e = params.dateAborted) === null || _e === void 0 ? void 0 : _e.$gte;
96
+ const dateAbortedGte = (_f = params.dateAborted) === null || _f === void 0 ? void 0 : _f.$gte;
93
97
  if (dateAbortedGte instanceof Date) {
94
98
  andConditions.push({
95
99
  dateAborted: {
@@ -98,7 +102,7 @@ class MongoRepository {
98
102
  }
99
103
  });
100
104
  }
101
- const dateAbortedLte = (_f = params.dateAborted) === null || _f === void 0 ? void 0 : _f.$lte;
105
+ const dateAbortedLte = (_g = params.dateAborted) === null || _g === void 0 ? void 0 : _g.$lte;
102
106
  if (dateAbortedLte instanceof Date) {
103
107
  andConditions.push({
104
108
  dateAborted: {
@@ -107,7 +111,7 @@ class MongoRepository {
107
111
  }
108
112
  });
109
113
  }
110
- const objectTransactionNumberEq = (_j = (_h = (_g = params.data) === null || _g === void 0 ? void 0 : _g.object) === null || _h === void 0 ? void 0 : _h.transactionNumber) === null || _j === void 0 ? void 0 : _j.$eq;
114
+ const objectTransactionNumberEq = (_k = (_j = (_h = params.data) === null || _h === void 0 ? void 0 : _h.object) === null || _j === void 0 ? void 0 : _j.transactionNumber) === null || _k === void 0 ? void 0 : _k.$eq;
111
115
  if (typeof objectTransactionNumberEq === 'string') {
112
116
  andConditions.push({
113
117
  'data.object.transactionNumber': {
@@ -116,7 +120,7 @@ class MongoRepository {
116
120
  }
117
121
  });
118
122
  }
119
- const objectPurposeIdEq = (_m = (_l = (_k = params.data) === null || _k === void 0 ? void 0 : _k.purpose) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq;
123
+ const objectPurposeIdEq = (_o = (_m = (_l = params.data) === null || _l === void 0 ? void 0 : _l.purpose) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$eq;
120
124
  if (typeof objectPurposeIdEq === 'string') {
121
125
  andConditions.push({
122
126
  'data.purpose.id': {
@@ -125,7 +129,7 @@ class MongoRepository {
125
129
  }
126
130
  });
127
131
  }
128
- const objectPurposeOrderNumberEq = (_q = (_p = (_o = params.data) === null || _o === void 0 ? void 0 : _o.purpose) === null || _p === void 0 ? void 0 : _p.orderNumber) === null || _q === void 0 ? void 0 : _q.$eq;
132
+ const objectPurposeOrderNumberEq = (_r = (_q = (_p = params.data) === null || _p === void 0 ? void 0 : _p.purpose) === null || _q === void 0 ? void 0 : _q.orderNumber) === null || _r === void 0 ? void 0 : _r.$eq;
129
133
  if (typeof objectPurposeOrderNumberEq === 'string') {
130
134
  andConditions.push({
131
135
  'data.purpose.orderNumber': {
@@ -306,6 +310,14 @@ class MongoRepository {
306
310
  .exec();
307
311
  });
308
312
  }
313
+ deleteByName(params) {
314
+ return __awaiter(this, void 0, void 0, function* () {
315
+ return this.taskModel.deleteMany({
316
+ name: { $eq: params.name }
317
+ })
318
+ .exec();
319
+ });
320
+ }
309
321
  aggregateTask(params) {
310
322
  return __awaiter(this, void 0, void 0, function* () {
311
323
  const statuses = yield Promise.all([
@@ -1,6 +1,7 @@
1
1
  import { MongoRepository as EventRepo } from '../../../repo/event';
2
2
  import { RedisRepository as EventAvailabilityRepo } from '../../../repo/itemAvailability/screeningEvent';
3
3
  import { MongoRepository as OfferRepo } from '../../../repo/offer';
4
+ import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
4
5
  import { MongoRepository as PlaceRepo } from '../../../repo/place';
5
6
  import { MongoRepository as ProductRepo } from '../../../repo/product';
6
7
  import { MongoRepository as ProjectRepo } from '../../../repo/project';
@@ -12,6 +13,7 @@ export declare type IAggregateScreeningEventOperation<T> = (repos: {
12
13
  event: EventRepo;
13
14
  eventAvailability: EventAvailabilityRepo;
14
15
  offer: OfferRepo;
16
+ offerCatalog: OfferCatalogRepo;
15
17
  offerRateLimit: OfferRateLimitRepo;
16
18
  place: PlaceRepo;
17
19
  product: ProductRepo;
@@ -17,6 +17,7 @@ const createDebug = require("debug");
17
17
  const moment = require("moment-timezone");
18
18
  const event_1 = require("../../../repo/event");
19
19
  const factory = require("../../../factory");
20
+ const settings_1 = require("../../../settings");
20
21
  const debug = createDebug('chevre-domain:service');
21
22
  /**
22
23
  * イベントデータをID指定で集計する
@@ -28,31 +29,34 @@ function aggregateScreeningEvent(params) {
28
29
  // const event = await repos.event.findById<factory.eventType.ScreeningEvent | factory.eventType.Event>(params);
29
30
  const event = yield repos.event.findMinimizedIndividualEventById(params);
30
31
  let aggregatingEvents = [event];
31
- const availableOffers = yield findOffers({ event })(repos);
32
- const offerRateLimitExists = availableOffers.some((o) => { var _a; return typeof ((_a = o.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope) === 'string'; });
33
- if (offerRateLimitExists) {
34
- // 同location、かつ同時間帯、のイベントに関しても集計する(ttts暫定対応)
35
- const startFrom = moment(event.startDate)
36
- .startOf('hour')
37
- .toDate();
38
- const startThrough = moment(startFrom)
39
- .add(1, 'hour')
40
- .add(-1, 'second')
41
- .toDate();
42
- // 取得属性最適化(2023-01-25~)
43
- aggregatingEvents = yield repos.event.search({
44
- limit: 100,
45
- page: 1,
46
- project: { id: { $eq: event.project.id } },
47
- typeOf: event.typeOf,
48
- eventStatuses: [factory.eventStatusType.EventScheduled],
49
- startFrom: startFrom,
50
- startThrough: startThrough,
51
- location: { branchCode: { $eq: event.location.branchCode } }
52
- }, event_1.PROJECTION_MINIMIZED_EVENT);
53
- // ID指定されたイベントについてはEventScheduledでなくても集計したいので、集計対象を調整
54
- aggregatingEvents = aggregatingEvents.filter((e) => e.id !== event.id);
55
- aggregatingEvents = [event, ...aggregatingEvents];
32
+ // プロジェクト限定(2023-02-22~)
33
+ if (settings_1.settings.useOfferRateLimitProjects.includes(event.project.id)) {
34
+ const availableOffers = yield findOffers({ event })(repos);
35
+ const offerRateLimitExists = availableOffers.some((o) => { var _a; return typeof ((_a = o.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope) === 'string'; });
36
+ if (offerRateLimitExists) {
37
+ // 同location、かつ同時間帯、のイベントに関しても集計する(ttts暫定対応)
38
+ const startFrom = moment(event.startDate)
39
+ .startOf('hour')
40
+ .toDate();
41
+ const startThrough = moment(startFrom)
42
+ .add(1, 'hour')
43
+ .add(-1, 'second')
44
+ .toDate();
45
+ // 取得属性最適化(2023-01-25~)
46
+ aggregatingEvents = yield repos.event.search({
47
+ limit: 100,
48
+ page: 1,
49
+ project: { id: { $eq: event.project.id } },
50
+ typeOf: event.typeOf,
51
+ eventStatuses: [factory.eventStatusType.EventScheduled],
52
+ startFrom: startFrom,
53
+ startThrough: startThrough,
54
+ location: { branchCode: { $eq: event.location.branchCode } }
55
+ }, event_1.PROJECTION_MINIMIZED_EVENT);
56
+ // ID指定されたイベントについてはEventScheduledでなくても集計したいので、集計対象を調整
57
+ aggregatingEvents = aggregatingEvents.filter((e) => e.id !== event.id);
58
+ aggregatingEvents = [event, ...aggregatingEvents];
59
+ }
56
60
  }
57
61
  debug(aggregatingEvents.length, 'aggregatingEvents found', aggregatingEvents.map((e) => e.id));
58
62
  for (const aggregatingEvent of aggregatingEvents) {
@@ -79,20 +83,6 @@ function aggregateByEvent(params) {
79
83
  branchCode: { $eq: event.location.branchCode },
80
84
  containedInPlace: { id: { $eq: movieTheaterId } }
81
85
  });
82
- // 施設取得
83
- // const movieTheater = await findLocation(params)(repos);
84
- // // 万が一施設が存在しなければ処理終了
85
- // if (movieTheater === undefined) {
86
- // return;
87
- // }
88
- // const screeningRoom = <factory.place.screeningRoom.IPlace | undefined>
89
- // movieTheater.containsPlace.find((p) => p.branchCode === event.location.branchCode);
90
- // if (screeningRoom === undefined) {
91
- // // 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま
92
- // // tslint:disable-next-line:no-console
93
- // console.error(new Error(`Screening room not found. branchCode: ${event.location.branchCode}`));
94
- // return;
95
- // }
96
86
  // 予約集計
97
87
  const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByEvent({
98
88
  aggregateDate: now,
@@ -100,7 +90,8 @@ function aggregateByEvent(params) {
100
90
  screeningRoom: screeningRoom
101
91
  })(repos);
102
92
  // オファーごとの集計
103
- const aggregateOffer = yield aggregateOfferByEvent({
93
+ let aggregateOffer;
94
+ aggregateOffer = yield aggregateOfferByEvent({
104
95
  aggregateDate: now,
105
96
  event: Object.assign(Object.assign({}, event), { maximumAttendeeCapacity,
106
97
  remainingAttendeeCapacity }),
@@ -109,11 +100,9 @@ function aggregateByEvent(params) {
109
100
  debug('offers aggregated', aggregateOffer);
110
101
  // 値がundefinedの場合に更新しないように注意
111
102
  const update = {
112
- $set: Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
113
- // aggregateEntranceGate,
114
- aggregateReservation,
115
- aggregateOffer }, (maximumAttendeeCapacity !== undefined) ? { maximumAttendeeCapacity: maximumAttendeeCapacity } : undefined), (remainingAttendeeCapacity !== undefined) ? { remainingAttendeeCapacity: remainingAttendeeCapacity } : undefined), (aggregateReservation.checkInCount !== undefined) ? { checkInCount: aggregateReservation.checkInCount } : undefined), (aggregateReservation.attendeeCount !== undefined) ? { attendeeCount: aggregateReservation.attendeeCount } : undefined),
116
- $unset: Object.assign(Object.assign({ noExistingAttributeName: 1 }, (maximumAttendeeCapacity === undefined) ? { maximumAttendeeCapacity: '' } : undefined), (remainingAttendeeCapacity === undefined) ? { remainingAttendeeCapacity: '' } : undefined)
103
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
104
+ aggregateReservation }, (typeof (aggregateOffer === null || aggregateOffer === void 0 ? void 0 : aggregateOffer.typeOf) === 'string') ? { aggregateOffer: aggregateOffer } : undefined), (maximumAttendeeCapacity !== undefined) ? { maximumAttendeeCapacity: maximumAttendeeCapacity } : undefined), (remainingAttendeeCapacity !== undefined) ? { remainingAttendeeCapacity: remainingAttendeeCapacity } : undefined), (aggregateReservation.checkInCount !== undefined) ? { checkInCount: aggregateReservation.checkInCount } : undefined), (aggregateReservation.attendeeCount !== undefined) ? { attendeeCount: aggregateReservation.attendeeCount } : undefined),
105
+ $unset: Object.assign(Object.assign(Object.assign({ noExistingAttributeName: 1 }, (typeof (aggregateOffer === null || aggregateOffer === void 0 ? void 0 : aggregateOffer.typeOf) !== 'string') ? { aggregateOffer: '' } : undefined), (maximumAttendeeCapacity === undefined) ? { maximumAttendeeCapacity: '' } : undefined), (remainingAttendeeCapacity === undefined) ? { remainingAttendeeCapacity: '' } : undefined)
117
106
  };
118
107
  debug('update:', update);
119
108
  // 保管
@@ -125,37 +114,6 @@ function aggregateByEvent(params) {
125
114
  });
126
115
  }
127
116
  exports.aggregateByEvent = aggregateByEvent;
128
- /**
129
- * イベントロケーション取得
130
- * NotFoundエラーをハンドリングする
131
- */
132
- // function findLocation(params: {
133
- // event: factory.event.screeningEvent.IEvent | factory.event.event.IEvent;
134
- // }) {
135
- // return async (repos: {
136
- // place: PlaceRepo;
137
- // }): Promise<factory.place.movieTheater.IPlace | undefined> => {
138
- // let movieTheater: factory.place.movieTheater.IPlace | undefined;
139
- // try {
140
- // if (params.event.typeOf === factory.eventType.ScreeningEvent) {
141
- // movieTheater = await repos.place.findById({ id: params.event.superEvent.location.id });
142
- // } else {
143
- // const movieTheaterId: string =
144
- // String(params.event.offers?.itemOffered.availableChannel.serviceLocation.containedInPlace.id);
145
- // movieTheater = await repos.place.findById({ id: movieTheaterId });
146
- // }
147
- // } catch (error) {
148
- // let throwsError = true;
149
- // if (error instanceof factory.errors.NotFound) {
150
- // throwsError = false;
151
- // }
152
- // if (throwsError) {
153
- // throw error;
154
- // }
155
- // }
156
- // return movieTheater;
157
- // };
158
- // }
159
117
  /**
160
118
  * 集計後アクション
161
119
  */
@@ -172,26 +130,36 @@ function reservedSeatsAvailable(params) {
172
130
  function aggregateOfferByEvent(params) {
173
131
  return (repos) => __awaiter(this, void 0, void 0, function* () {
174
132
  var _a, _b, _c;
175
- const availableOffers = yield findOffers(params)(repos);
176
- // オファーごとの予約集計
177
- const offersWithAggregateReservation = [];
178
- for (const o of availableOffers) {
179
- const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByOffer({
180
- aggregateDate: params.aggregateDate,
181
- event: params.event,
182
- screeningRoom: params.screeningRoom,
183
- offer: o
184
- })(repos);
185
- offersWithAggregateReservation.push(Object.assign(Object.assign(Object.assign({ typeOf: o.typeOf, id: o.id, identifier: o.identifier, aggregateReservation: aggregateReservation, name: {
186
- en: (_a = o.name) === null || _a === void 0 ? void 0 : _a.en,
187
- ja: (_b = o.name) === null || _b === void 0 ? void 0 : _b.ja
188
- } }, (typeof maximumAttendeeCapacity === 'number') ? { maximumAttendeeCapacity } : undefined), (typeof remainingAttendeeCapacity === 'number') ? { remainingAttendeeCapacity } : undefined), (typeof ((_c = o.category) === null || _c === void 0 ? void 0 : _c.codeValue) === 'string') ? { category: o.category } : undefined));
133
+ // プロジェクト限定(2023-02-22~)
134
+ if (settings_1.settings.useAggregateOfferProjects.includes(params.event.project.id)) {
135
+ const availableOffers = yield findOffers(params)(repos);
136
+ // オファーごとの予約集計
137
+ const offersWithAggregateReservation = [];
138
+ for (const o of availableOffers) {
139
+ const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByOffer({
140
+ aggregateDate: params.aggregateDate,
141
+ event: params.event,
142
+ screeningRoom: params.screeningRoom,
143
+ offer: o
144
+ })(repos);
145
+ offersWithAggregateReservation.push(Object.assign(Object.assign(Object.assign({ typeOf: o.typeOf, id: o.id, identifier: o.identifier, aggregateReservation: aggregateReservation, name: {
146
+ en: (_a = o.name) === null || _a === void 0 ? void 0 : _a.en,
147
+ ja: (_b = o.name) === null || _b === void 0 ? void 0 : _b.ja
148
+ } }, (typeof maximumAttendeeCapacity === 'number') ? { maximumAttendeeCapacity } : undefined), (typeof remainingAttendeeCapacity === 'number') ? { remainingAttendeeCapacity } : undefined), (typeof ((_c = o.category) === null || _c === void 0 ? void 0 : _c.codeValue) === 'string') ? { category: o.category } : undefined));
149
+ }
150
+ return {
151
+ typeOf: factory.offerType.AggregateOffer,
152
+ offerCount: availableOffers.length,
153
+ offers: offersWithAggregateReservation
154
+ };
155
+ }
156
+ else {
157
+ const { offerCount } = yield calculateOfferCount({ event: params.event })(repos);
158
+ return {
159
+ typeOf: factory.offerType.AggregateOffer,
160
+ offerCount
161
+ };
189
162
  }
190
- return {
191
- typeOf: factory.offerType.AggregateOffer,
192
- offerCount: availableOffers.length,
193
- offers: offersWithAggregateReservation
194
- };
195
163
  });
196
164
  }
197
165
  /**
@@ -208,10 +176,12 @@ function findOffers(params) {
208
176
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
209
177
  const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id });
210
178
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
211
- availableOffers = yield repos.offer.findOffersByOfferCatalogId({
179
+ const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId({
212
180
  offerCatalog: { id: eventService.hasOfferCatalog.id },
181
+ excludeAppliesToMovieTicket: false,
213
182
  sort: false // ソート不要(2023-01-27~)
214
183
  });
184
+ availableOffers = findOffersByOfferCatalogIdResult.offers;
215
185
  }
216
186
  }
217
187
  else {
@@ -231,6 +201,33 @@ function findOffers(params) {
231
201
  return availableOffers;
232
202
  });
233
203
  }
204
+ function calculateOfferCount(params) {
205
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
206
+ var _a, _b, _c;
207
+ let offerCount = 0;
208
+ try {
209
+ const eventOffers = params.event.offers;
210
+ if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
211
+ const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id });
212
+ if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
213
+ const catalogs = yield repos.offerCatalog.search({
214
+ limit: 1,
215
+ page: 1,
216
+ id: { $in: [eventService.hasOfferCatalog.id] }
217
+ });
218
+ const numberOfItems = (_c = catalogs.shift()) === null || _c === void 0 ? void 0 : _c.numberOfItems;
219
+ if (typeof numberOfItems === 'number') {
220
+ offerCount = numberOfItems;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ catch (error) {
226
+ throw error;
227
+ }
228
+ return { offerCount };
229
+ });
230
+ }
234
231
  function aggregateReservationByOffer(params) {
235
232
  return (repos) => __awaiter(this, void 0, void 0, function* () {
236
233
  let reservationCount4offer;
@@ -91,10 +91,12 @@ function findOffers(params) {
91
91
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
92
92
  const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id });
93
93
  if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
94
- availableOffers = yield repos.offer.findOffersByOfferCatalogId({
94
+ const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId({
95
95
  offerCatalog: { id: eventService.hasOfferCatalog.id },
96
+ excludeAppliesToMovieTicket: false,
96
97
  sort: false // ソート不要(2023-01-27~)
97
98
  });
99
+ availableOffers = findOffersByOfferCatalogIdResult.offers;
98
100
  }
99
101
  }
100
102
  else {
@@ -122,13 +122,12 @@ function authorizeAccount(params) {
122
122
  return (repos) => __awaiter(this, void 0, void 0, function* () {
123
123
  var _a, _b, _c;
124
124
  const transaction = params.transaction;
125
- let pendingTransaction;
126
125
  const fromLocation = transaction.object.fromLocation;
127
126
  const toLocation = transaction.object.toLocation;
128
127
  if (typeof ((_a = transaction.object.pendingTransaction) === null || _a === void 0 ? void 0 : _a.typeOf) !== 'string') {
129
128
  throw new factory.errors.NotFound('transaction.object.pendingTransaction.typeOf');
130
129
  }
131
- pendingTransaction = yield MoneyTransferService.authorize({
130
+ yield MoneyTransferService.authorize({
132
131
  typeOf: transaction.object.pendingTransaction.typeOf,
133
132
  identifier: transaction.object.pendingTransaction.identifier,
134
133
  transactionNumber: transaction.object.pendingTransaction.transactionNumber,
@@ -152,7 +151,7 @@ function authorizeAccount(params) {
152
151
  recipient: transaction.recipient,
153
152
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
154
153
  })(repos);
155
- return pendingTransaction;
154
+ // return pendingTransaction;
156
155
  });
157
156
  }
158
157
  function fixMonetaryAmount(params, product) {
@@ -269,11 +269,10 @@ function processAuthorizeCreditCard(params, transaction, paymentServiceId) {
269
269
  }
270
270
  function processAuthorizeMovieTicket(params, transaction, paymentServiceId) {
271
271
  return (repos) => __awaiter(this, void 0, void 0, function* () {
272
- var _a, _b;
273
- const authorizeResult = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId)(repos);
272
+ const { accountId, checkResult, payAction } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId)(repos);
274
273
  return saveAuthorizeResult({
275
274
  id: transaction.id,
276
- update: Object.assign({ 'object.accountId': (_a = authorizeResult.checkResult) === null || _a === void 0 ? void 0 : _a.movieTickets[0].identifier, 'object.paymentMethod.accountId': (_b = authorizeResult.checkResult) === null || _b === void 0 ? void 0 : _b.movieTickets[0].identifier, 'object.checkResult': authorizeResult.checkResult }, (authorizeResult.payAction !== undefined) ? { 'object.payAction': authorizeResult.payAction } : undefined)
275
+ update: Object.assign({ 'object.accountId': accountId, 'object.paymentMethod.accountId': accountId, 'object.payAction': payAction }, (checkResult !== undefined) ? { 'object.checkResult': checkResult } : undefined)
277
276
  })(repos);
278
277
  });
279
278
  }
@@ -6,7 +6,7 @@ export declare type IUnitPriceSpecification = factory.priceSpecification.IPriceS
6
6
  export declare function createPointAward(params: {
7
7
  acceptedOffer: factory.assetTransaction.registerService.IAcceptedOfferWithoutDetail;
8
8
  offer: factory.product.ITicketOffer;
9
- }): factory.product.IPointAward | undefined;
9
+ }): factory.action.transfer.moneyTransfer.IPointAward | undefined;
10
10
  /**
11
11
  * サービスアウトプットを作成する
12
12
  */
@@ -20,7 +20,6 @@ function createPointAward(params) {
20
20
  && typeof (pointAwardToLocation === null || pointAwardToLocation === void 0 ? void 0 : pointAwardToLocation.identifier) === 'string'
21
21
  && typeof (pointAwardToLocation === null || pointAwardToLocation === void 0 ? void 0 : pointAwardToLocation.issuedThrough.id) === 'string') {
22
22
  pointAward = Object.assign(Object.assign(Object.assign({ amount: pointAwardAmount, toLocation: {
23
- // ひとまず'Permit'で固定
24
23
  typeOf: factory.permit.PermitType.Permit,
25
24
  identifier: pointAwardToLocation.identifier,
26
25
  issuedThrough: { id: pointAwardToLocation.issuedThrough.id }
@@ -58,7 +57,8 @@ function createServiceOutput(params) {
58
57
  throw new factory.errors.ArgumentNull('object.itemOffered.serviceOutput.accessCode');
59
58
  }
60
59
  paymentAccount = {
61
- project: { typeOf: product.project.typeOf, id: product.project.id },
60
+ // 廃止(2023-02-20~)
61
+ // project: { typeOf: product.project.typeOf, id: product.project.id },
62
62
  // ひとまず固定
63
63
  // 口座は複数のプロダクトに結合する可能性もあり、どのように利用されるかは知らない。ただbalanceを管理するだけ。通貨は知っている。
64
64
  typeOf: factory.accountType.Account,
@@ -74,7 +74,10 @@ function createServiceOutput(params) {
74
74
  default:
75
75
  throw new factory.errors.NotImplemented(`Product type ${product.typeOf} not implemented`);
76
76
  }
77
- const issuedThrough = Object.assign({ project: { typeOf: product.project.typeOf, id: product.project.id }, typeOf: product.typeOf, id: product.id }, (typeof ((_m = product.serviceType) === null || _m === void 0 ? void 0 : _m.typeOf) === 'string') ? { serviceType: product.serviceType } : undefined);
77
+ const issuedThrough = Object.assign({
78
+ // 廃止(2023-02-20~)
79
+ // project: { typeOf: product.project.typeOf, id: product.project.id },
80
+ typeOf: product.typeOf, id: product.id }, (typeof ((_m = product.serviceType) === null || _m === void 0 ? void 0 : _m.typeOf) === 'string') ? { serviceType: product.serviceType } : undefined);
78
81
  return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ project: { typeOf: product.project.typeOf, id: product.project.id }, identifier: identifier, issuedThrough, typeOf: serviceOutputType, dateIssued: params.dateIssued }, (typeof accessCode === 'string') ? { accessCode } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : undefined), (typeof validFor === 'string') ? { validFor } : undefined), (name !== undefined) ? { name } : undefined), (amount !== undefined) ? { amount } : undefined), (depositAmount !== undefined) ? { depositAmount } : undefined), (paymentAmount !== undefined) ? { paymentAmount } : undefined), (paymentAccount !== undefined) ? { paymentAccount } : undefined), (issuedBy !== undefined) ? { issuedBy } : undefined);
79
82
  }
80
83
  exports.createServiceOutput = createServiceOutput;
@@ -94,8 +94,10 @@ function createTransactionObject(params) {
94
94
  return (repos) => __awaiter(this, void 0, void 0, function* () {
95
95
  // オファー検索
96
96
  const offers = yield (0, searchProductOffers_1.searchProductOffers)({
97
+ ids: params.acceptedOffers.map((o) => o.id),
97
98
  itemOffered: { id: String(params.product.id) },
98
- sort: false // ソート不要(2023-01-27~)
99
+ onlyValid: true,
100
+ addSortIndex: false
99
101
  })(repos);
100
102
  const transactionObject = [];
101
103
  for (const acceptedOffer of params.acceptedOffers) {