@chevre/domain 20.4.0-alpha.8 → 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 (89) 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/migrateMoneyTransferPendingTransactionIdentifier.ts +96 -0
  5. package/example/src/chevre/reIndex.ts +25 -0
  6. package/example/src/chevre/searchEventTicketOffers.ts +7 -4
  7. package/example/src/chevre/searchOfferCatalogs.ts +14 -16
  8. package/example/src/chevre/searchOffersByCatalog.ts +2 -1
  9. package/example/src/chevre/searchProductOffers.ts +38 -0
  10. package/example/src/chevre/searchTasks.ts +22 -0
  11. package/example/src/chevre/unsetUnnecessaryFields.ts +6 -11
  12. package/lib/chevre/errorHandler.js +1 -0
  13. package/lib/chevre/repo/accountTransaction.d.ts +0 -5
  14. package/lib/chevre/repo/accountTransaction.js +44 -38
  15. package/lib/chevre/repo/assetTransaction.d.ts +1 -0
  16. package/lib/chevre/repo/assetTransaction.js +5 -0
  17. package/lib/chevre/repo/code.d.ts +0 -7
  18. package/lib/chevre/repo/code.js +0 -17
  19. package/lib/chevre/repo/event.d.ts +5 -4
  20. package/lib/chevre/repo/event.js +8 -17
  21. package/lib/chevre/repo/mongoose/model/accountTransaction.js +0 -5
  22. package/lib/chevre/repo/mongoose/model/member.js +5 -2
  23. package/lib/chevre/repo/mongoose/model/offer.js +19 -9
  24. package/lib/chevre/repo/mongoose/model/priceSpecification.js +19 -52
  25. package/lib/chevre/repo/mongoose/model/product.js +15 -2
  26. package/lib/chevre/repo/offer.d.ts +17 -2
  27. package/lib/chevre/repo/offer.js +77 -44
  28. package/lib/chevre/repo/offerCatalog.d.ts +3 -5
  29. package/lib/chevre/repo/offerCatalog.js +78 -37
  30. package/lib/chevre/repo/priceSpecification.d.ts +11 -0
  31. package/lib/chevre/repo/priceSpecification.js +44 -66
  32. package/lib/chevre/repo/task.d.ts +8 -0
  33. package/lib/chevre/repo/task.js +21 -9
  34. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -0
  35. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +93 -96
  36. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +3 -1
  37. package/lib/chevre/service/assetTransaction/moneyTransfer.js +19 -11
  38. package/lib/chevre/service/assetTransaction/pay.js +2 -3
  39. package/lib/chevre/service/assetTransaction/registerService/factory.d.ts +1 -1
  40. package/lib/chevre/service/assetTransaction/registerService/factory.js +6 -3
  41. package/lib/chevre/service/assetTransaction/registerService.js +3 -1
  42. package/lib/chevre/service/assetTransaction/reserve/factory/price.d.ts +1 -1
  43. package/lib/chevre/service/assetTransaction/reserve/factory/price.js +0 -7
  44. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +2 -2
  45. package/lib/chevre/service/assetTransaction/reserve/factory.js +0 -1
  46. package/lib/chevre/service/assetTransaction/reserve.js +47 -17
  47. package/lib/chevre/service/assetTransaction.d.ts +1 -1
  48. package/lib/chevre/service/code.d.ts +0 -8
  49. package/lib/chevre/service/code.js +1 -38
  50. package/lib/chevre/service/delivery.js +12 -3
  51. package/lib/chevre/service/event.js +0 -3
  52. package/lib/chevre/service/moneyTransfer.d.ts +1 -1
  53. package/lib/chevre/service/moneyTransfer.js +7 -8
  54. package/lib/chevre/service/offer/event/authorize.js +5 -5
  55. package/lib/chevre/service/offer/event/factory.js +1 -1
  56. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +7 -7
  57. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +222 -346
  58. package/lib/chevre/service/offer/factory.d.ts +8 -3
  59. package/lib/chevre/service/offer/factory.js +44 -26
  60. package/lib/chevre/service/offer/moneyTransfer/authorize.js +0 -1
  61. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +0 -1
  62. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +11 -1
  63. package/lib/chevre/service/offer/product/searchProductOffers.js +15 -7
  64. package/lib/chevre/service/offer/product.d.ts +11 -4
  65. package/lib/chevre/service/offer/product.js +59 -50
  66. package/lib/chevre/service/payment/any/factory.js +30 -21
  67. package/lib/chevre/service/payment/any.js +11 -4
  68. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +22 -0
  69. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +183 -0
  70. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  71. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +13 -0
  72. package/lib/chevre/service/payment/movieTicket/getCredentials.js +45 -0
  73. package/lib/chevre/service/payment/movieTicket/validation.d.ts +15 -0
  74. package/lib/chevre/service/{assetTransaction/pay → payment}/movieTicket/validation.js +8 -7
  75. package/lib/chevre/service/payment/movieTicket.d.ts +10 -22
  76. package/lib/chevre/service/payment/movieTicket.js +15 -210
  77. package/lib/chevre/service/permit.d.ts +5 -1
  78. package/lib/chevre/service/permit.js +18 -11
  79. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +25 -53
  80. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -0
  81. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  82. package/lib/chevre/service/transaction/orderProgramMembership.js +5 -6
  83. package/lib/chevre/settings.d.ts +4 -0
  84. package/lib/chevre/settings.js +8 -2
  85. package/package.json +3 -3
  86. package/example/src/chevre/migrateAccountTitleAdditionalProperties.ts +0 -157
  87. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.d.ts +0 -14
  88. package/lib/chevre/service/task/deleteAuthorization.d.ts +0 -6
  89. package/lib/chevre/service/task/deleteAuthorization.js +0 -29
@@ -13,234 +13,116 @@ exports.searchEventTicketOffers = void 0;
13
13
  const moment = require("moment-timezone");
14
14
  const factory = require("../../../factory");
15
15
  const factory_1 = require("../factory");
16
- /**
17
- * 旅客オファー検索
18
- */
19
- function searchTransportationEventTicketOffers(params) {
20
- // tslint:disable-next-line:max-func-body-length
16
+ function searchTicketOffersByItemOffered(params) {
21
17
  return (repos) => __awaiter(this, void 0, void 0, function* () {
22
18
  var _a, _b, _c, _d;
23
- const screeningEvent = params.event;
24
- const soundFormatTypes = [];
25
- const videoFormatTypes = [];
26
- let availableOffers = [];
27
- // 興行設定があれば興行のカタログを参照する(2022-08-31~)
28
- const eventOffers = screeningEvent.offers;
29
- if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
30
- const transportation = yield repos.product.findById({ id: eventOffers.itemOffered.id });
31
- if (typeof ((_b = transportation.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
32
- availableOffers = yield repos.offer.findOffersByOfferCatalogId({
33
- ids: params.ids,
34
- offerCatalog: { id: transportation.hasOfferCatalog.id },
35
- availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
36
- sort: params.sort
37
- });
19
+ let catalogId;
20
+ if (typeof ((_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
21
+ const eventService = yield repos.product.findById({ id: (_b = params.itemOffered) === null || _b === void 0 ? void 0 : _b.id });
22
+ if (typeof ((_c = eventService.hasOfferCatalog) === null || _c === void 0 ? void 0 : _c.id) === 'string') {
23
+ catalogId = eventService.hasOfferCatalog.id;
38
24
  }
39
25
  }
40
- else {
41
- // hasOfferCatalog参照廃止(2022-09-02~)
42
- throw new factory.errors.NotFound('event.offers.itemOffered.id');
26
+ if (typeof catalogId !== 'string') {
27
+ throw new factory.errors.NotFound('itemOffered.hasOfferCatalog');
43
28
  }
44
- const { soundFormatChargeSpecifications, videoFormatChargeSpecifications, movieTicketTypeChargeSpecs } = yield searchPriceSpecs4event({ project: { id: screeningEvent.project.id }, soundFormatTypes, videoFormatTypes })(repos);
45
- const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event: screeningEvent });
46
- // 不許可決済方法があれば、該当オファーを除外
47
- if (Array.isArray(unacceptedPaymentMethod) && unacceptedPaymentMethod.length > 0) {
48
- availableOffers = availableOffers.filter((o) => {
49
- var _a;
50
- // 複数決済カード対応(2022-07-11~)
51
- const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
52
- if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
53
- return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
54
- return !unacceptedPaymentMethod.includes(appliesToMovieTicket.serviceOutput.typeOf);
55
- });
56
- }
57
- else {
58
- // Arrayでないケースは廃止(2022-09-10~)
59
- return true;
60
- }
61
- });
62
- }
63
- // 適用決済カード条件がある場合、決済カード加算料金が存在しないオファーは除外する
64
- availableOffers = availableOffers.filter((o) => {
65
- var _a;
66
- // 複数決済カード対応(2022-07-26~)
67
- const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
68
- if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
69
- // 適用決済カード数が0であれば除外
70
- if (priceSpecificationAppliesToMovieTicket.length === 0) {
71
- return false;
72
- }
73
- // 上映方式がなければ除外(2022-11-03~)
74
- if (videoFormatTypes.length === 0) {
75
- return false;
76
- }
77
- return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
78
- // すべての上映方式について検証する(2022-10-29~)
79
- return videoFormatTypes.every((videoFormat) => {
80
- return movieTicketTypeChargeSpecs.some((s) => {
81
- var _a, _b, _c, _d;
82
- return ((_b = (_a = s.appliesToMovieTicket) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.typeOf) === ((_c = appliesToMovieTicket.serviceOutput) === null || _c === void 0 ? void 0 : _c.typeOf)
83
- && ((_d = s.appliesToMovieTicket) === null || _d === void 0 ? void 0 : _d.serviceType) === appliesToMovieTicket.serviceType
84
- && s.appliesToVideoFormat === videoFormat;
85
- });
86
- });
87
- });
88
- }
89
- else {
90
- // Arrayでないケースは廃止(2022-09-10~)
91
- return true;
92
- }
93
- });
94
- let offers4event = availableOffers.map((availableOffer) => {
95
- return (0, factory_1.createCompoundPriceSpec4event)({
96
- eligibleQuantity: eventOffers.eligibleQuantity,
97
- offer: availableOffer,
98
- videoFormatChargeSpecifications,
99
- soundFormatChargeSpecifications,
100
- movieTicketTypeChargeSpecs,
101
- videoFormatTypes
102
- });
29
+ const { offers, sortedOfferIds } = yield repos.offer.findOffersByOfferCatalogId({
30
+ ids: params.ids,
31
+ offerCatalog: { id: catalogId },
32
+ availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id },
33
+ unacceptedPaymentMethod: params.unacceptedPaymentMethod,
34
+ excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
35
+ onlyValid: params.onlyValid === true,
36
+ // Mongoのpagingを利用するオプション(2023-02-21~)
37
+ limit: params.limit,
38
+ page: params.page,
39
+ sort: false
103
40
  });
104
- if (params.validateOfferRateLimit) {
105
- // レート制限を確認
106
- offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
107
- return checkAvailability({ event: screeningEvent, offer })(repos);
108
- })));
109
- }
110
- // アドオン設定があれば、プロダクトオファーを検索
111
- for (const offer of offers4event) {
112
- const offerAddOn = [];
113
- if (Array.isArray(offer.addOn)) {
114
- for (const addOn of offer.addOn) {
115
- const productId = (_d = addOn.itemOffered) === null || _d === void 0 ? void 0 : _d.id;
116
- if (typeof productId === 'string') {
117
- const productOffers = yield searchAddOns({
118
- product: { id: productId },
119
- store: params.store
120
- })(repos);
121
- offerAddOn.push(...productOffers);
122
- }
123
- }
124
- }
125
- offer.addOn = offerAddOn;
126
- }
127
- return {
128
- ticketOffers: offers4event,
129
- unitPriceOffers: availableOffers
130
- };
41
+ return { availableOffers: offers, sortedOfferIds };
131
42
  });
132
43
  }
133
44
  /**
134
- * 興行オファー全検索
45
+ * イベントから興行(旅客)オファーを検索する
135
46
  */
136
- function searchScreeningEventTicketOffers(params) {
47
+ function searchEventTicketOffersByEvent(params) {
137
48
  // tslint:disable-next-line:max-func-body-length
138
49
  return (repos) => __awaiter(this, void 0, void 0, function* () {
139
- var _a, _b, _c, _d;
140
- // イベント取得属性最適化(2023-01-23~)
141
- // const screeningEvent = await repos.event.findById<factory.eventType.ScreeningEvent>({ id: params.eventId });
142
- const screeningEvent = params.event;
143
- // 取得属性最適化(2023-01-25~)
144
- const superEvent = yield repos.event.findById({ id: screeningEvent.superEvent.id }, { soundFormat: 1, videoFormat: 1 });
145
- const soundFormatTypes = (Array.isArray(superEvent.soundFormat)) ? superEvent.soundFormat.map((f) => f.typeOf) : [];
146
- const videoFormatTypes = (Array.isArray(superEvent.videoFormat)) ? superEvent.videoFormat.map((f) => f.typeOf) : [];
147
- let availableOffers = [];
50
+ var _a, _b;
51
+ const event = params.event;
52
+ let soundFormatTypes = [];
53
+ let videoFormatTypes = [];
54
+ if (event.typeOf === factory.eventType.ScreeningEvent) {
55
+ // 取得属性最適化(2023-01-25~)
56
+ const superEvent = yield repos.event.findById({ id: event.superEvent.id }, { soundFormat: 1, videoFormat: 1 });
57
+ soundFormatTypes = (Array.isArray(superEvent.soundFormat)) ? superEvent.soundFormat.map((f) => f.typeOf) : [];
58
+ videoFormatTypes = (Array.isArray(superEvent.videoFormat)) ? superEvent.videoFormat.map((f) => f.typeOf) : [];
59
+ }
60
+ const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event });
61
+ // 上映方式がなければMovieTicket除外(2023-02-21~)
62
+ const excludeAppliesToMovieTicket = videoFormatTypes.length === 0;
148
63
  // 興行設定があれば興行のカタログを参照する(2022-08-31~)
149
- const eventOffers = screeningEvent.offers;
150
- if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
151
- const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id });
152
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
153
- availableOffers = yield repos.offer.findOffersByOfferCatalogId({
154
- ids: params.ids,
155
- offerCatalog: { id: eventService.hasOfferCatalog.id },
156
- availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
157
- sort: params.sort
158
- });
64
+ const eventOffers = event.offers;
65
+ const { availableOffers, sortedOfferIds } = yield searchTicketOffersByItemOffered({
66
+ itemOffered: { id: (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id },
67
+ ids: params.ids,
68
+ store: params.store,
69
+ limit: params.limit,
70
+ page: params.page,
71
+ onlyValid: params.onlyValid,
72
+ unacceptedPaymentMethod,
73
+ excludeAppliesToMovieTicket
74
+ })(repos);
75
+ // 冗長な検索について最適化(2023-03-03~)
76
+ const { soundFormatChargeSpecs, videoFormatChargeSpecs, movieTicketTypeChargeSpecs } = yield searchPriceSpecs4event({
77
+ project: { id: event.project.id },
78
+ soundFormatTypes,
79
+ videoFormatTypes,
80
+ availableOffers
81
+ })(repos);
82
+ const offers4event = [];
83
+ // 単価オファーから興行オファーを生成(順に処理)
84
+ for (const availableOffer of availableOffers) {
85
+ let sortIndex;
86
+ if (params.addSortIndex) {
87
+ sortIndex = sortedOfferIds.indexOf(String(availableOffer.id));
159
88
  }
160
- }
161
- else {
162
- // hasOfferCatalog参照廃止(2022-09-02~)
163
- throw new factory.errors.NotFound('event.offers.itemOffered.id');
164
- }
165
- const { soundFormatChargeSpecifications, videoFormatChargeSpecifications, movieTicketTypeChargeSpecs } = yield searchPriceSpecs4event({ project: { id: screeningEvent.project.id }, soundFormatTypes, videoFormatTypes })(repos);
166
- const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event: screeningEvent });
167
- // 不許可決済方法があれば、該当オファーを除外
168
- if (Array.isArray(unacceptedPaymentMethod) && unacceptedPaymentMethod.length > 0) {
169
- availableOffers = availableOffers.filter((o) => {
170
- var _a;
171
- // 複数決済カード対応(2022-07-11~)
172
- const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
173
- if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
174
- return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
175
- return !unacceptedPaymentMethod.includes(appliesToMovieTicket.serviceOutput.typeOf);
176
- });
89
+ let availability;
90
+ if (params.validateOfferRateLimit) {
91
+ // レート制限を確認
92
+ availability = yield checkAvailability({ event, unitPriceOffer: availableOffer })(repos);
93
+ }
94
+ // アドオン設定があれば、プロダクトオファーを検索
95
+ let offerAddOn = [];
96
+ if (Array.isArray(availableOffer.addOn)) {
97
+ if (params.searchAddOns) {
98
+ for (const addOn of availableOffer.addOn) {
99
+ const productId = (_b = addOn.itemOffered) === null || _b === void 0 ? void 0 : _b.id;
100
+ if (typeof productId === 'string') {
101
+ const productOffers = yield searchAddOns({
102
+ product: { id: productId },
103
+ store: params.store,
104
+ addSortIndex: params.addSortIndex,
105
+ onlyValid: params.onlyValid
106
+ })(repos);
107
+ offerAddOn.push(...productOffers);
108
+ }
109
+ }
177
110
  }
178
111
  else {
179
- // Arrayでないケースは廃止(2022-09-10~)
180
- return true;
181
- }
182
- });
183
- }
184
- // 適用決済カード条件がある場合、決済カード加算料金が存在しないオファーは除外する
185
- availableOffers = availableOffers.filter((o) => {
186
- var _a;
187
- // 複数決済カード対応(2022-07-26~)
188
- const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
189
- if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
190
- // 適用決済カード数が0であれば除外
191
- if (priceSpecificationAppliesToMovieTicket.length === 0) {
192
- return false;
193
- }
194
- // 上映方式がなければ除外(2022-11-03~)
195
- if (videoFormatTypes.length === 0) {
196
- return false;
112
+ offerAddOn = availableOffer.addOn;
197
113
  }
198
- return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
199
- // すべての上映方式について検証する(2022-10-29~)
200
- return videoFormatTypes.every((videoFormat) => {
201
- return movieTicketTypeChargeSpecs.some((s) => {
202
- var _a, _b, _c, _d;
203
- return ((_b = (_a = s.appliesToMovieTicket) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.typeOf) === ((_c = appliesToMovieTicket.serviceOutput) === null || _c === void 0 ? void 0 : _c.typeOf)
204
- && ((_d = s.appliesToMovieTicket) === null || _d === void 0 ? void 0 : _d.serviceType) === appliesToMovieTicket.serviceType
205
- && s.appliesToVideoFormat === videoFormat;
206
- });
207
- });
208
- });
209
- }
210
- else {
211
- // Arrayでないケースは廃止(2022-09-10~)
212
- return true;
213
114
  }
214
- });
215
- let offers4event = availableOffers.map((availableOffer) => {
216
- return (0, factory_1.createCompoundPriceSpec4event)({
115
+ offers4event.push((0, factory_1.createCompoundPriceSpec4event)({
217
116
  eligibleQuantity: eventOffers.eligibleQuantity,
218
117
  offer: availableOffer,
219
- videoFormatChargeSpecifications,
220
- soundFormatChargeSpecifications,
118
+ videoFormatChargeSpecs,
119
+ soundFormatChargeSpecs,
221
120
  movieTicketTypeChargeSpecs,
222
- videoFormatTypes
223
- });
224
- });
225
- if (params.validateOfferRateLimit) {
226
- // レート制限を確認
227
- offers4event = yield Promise.all(offers4event.map((offer) => __awaiter(this, void 0, void 0, function* () {
228
- return checkAvailability({ event: screeningEvent, offer })(repos);
229
- })));
230
- }
231
- // アドオン設定があれば、プロダクトオファーを検索
232
- for (const offer of offers4event) {
233
- const offerAddOn = [];
234
- if (Array.isArray(offer.addOn)) {
235
- for (const addOn of offer.addOn) {
236
- const productId = (_d = addOn.itemOffered) === null || _d === void 0 ? void 0 : _d.id;
237
- if (typeof productId === 'string') {
238
- const productOffers = yield searchAddOns({ product: { id: productId } })(repos);
239
- offerAddOn.push(...productOffers);
240
- }
241
- }
242
- }
243
- offer.addOn = offerAddOn;
121
+ videoFormatTypes,
122
+ availability,
123
+ addOn: offerAddOn,
124
+ sortIndex
125
+ }));
244
126
  }
245
127
  return {
246
128
  ticketOffers: offers4event,
@@ -253,10 +135,6 @@ function getUnacceptedPaymentMethodByEvent(params) {
253
135
  const eventOffers = params.event.offers;
254
136
  const unacceptedPaymentMethodByEvent = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.unacceptedPaymentMethod;
255
137
  // 施設コンテンツを参照する必要はない(2022-10-31~)
256
- // if (Array.isArray(unacceptedPaymentMethodBySuperEvent)) {
257
- // unacceptedPaymentMethod = unacceptedPaymentMethodBySuperEvent;
258
- // }
259
- // イベントにunacceptedPaymentMethod設定があれば上書き
260
138
  if (Array.isArray(unacceptedPaymentMethodByEvent)) {
261
139
  unacceptedPaymentMethod = unacceptedPaymentMethodByEvent;
262
140
  }
@@ -264,47 +142,67 @@ function getUnacceptedPaymentMethodByEvent(params) {
264
142
  }
265
143
  function searchPriceSpecs4event(params) {
266
144
  return (repos) => __awaiter(this, void 0, void 0, function* () {
267
- const soundFormatChargeSpecifications = (params.soundFormatTypes.length > 0)
268
- ? yield repos.priceSpecification.search({
269
- project: { id: { $eq: params.project.id } },
270
- typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
271
- appliesToCategoryCode: {
272
- $elemMatch: {
273
- codeValue: { $in: params.soundFormatTypes },
274
- 'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.SoundFormatType }
275
- }
145
+ let soundFormatChargeSpecs = [];
146
+ let videoFormatChargeSpecs = [];
147
+ let movieTicketTypeChargeSpecs = [];
148
+ const movieTicketServiceTypes = [...new Set(params.availableOffers.reduce((a, b) => {
149
+ if (!Array.isArray(b.priceSpecification.appliesToMovieTicket)) {
150
+ return a;
276
151
  }
277
- })
278
- : [];
279
- const videoFormatChargeSpecifications = (params.videoFormatTypes.length > 0)
280
- ? yield repos.priceSpecification.search({
281
- project: { id: { $eq: params.project.id } },
282
- typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
283
- appliesToCategoryCode: {
284
- $elemMatch: {
285
- codeValue: { $in: params.videoFormatTypes },
286
- 'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.VideoFormatType }
152
+ return [
153
+ ...a,
154
+ ...b.priceSpecification.appliesToMovieTicket.map((movieTicket) => movieTicket.serviceType)
155
+ ];
156
+ }, []))];
157
+ if (params.soundFormatTypes.length > 0) {
158
+ soundFormatChargeSpecs =
159
+ yield repos.priceSpecification.search({
160
+ project: { id: { $eq: params.project.id } },
161
+ typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
162
+ appliesToCategoryCode: {
163
+ $elemMatch: {
164
+ codeValue: { $in: params.soundFormatTypes },
165
+ 'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.SoundFormatType }
166
+ }
287
167
  }
288
- }
289
- })
290
- : [];
291
- const movieTicketTypeChargeSpecs = (params.videoFormatTypes.length > 0)
292
- ? yield repos.priceSpecification.search({
293
- project: { id: { $eq: params.project.id } },
294
- typeOf: factory.priceSpecificationType.MovieTicketTypeChargeSpecification,
295
- appliesToVideoFormats: params.videoFormatTypes
296
- })
297
- : [];
298
- return { soundFormatChargeSpecifications, videoFormatChargeSpecifications, movieTicketTypeChargeSpecs };
168
+ });
169
+ }
170
+ if ((params.videoFormatTypes.length > 0)) {
171
+ videoFormatChargeSpecs =
172
+ yield repos.priceSpecification.search({
173
+ project: { id: { $eq: params.project.id } },
174
+ typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
175
+ appliesToCategoryCode: {
176
+ $elemMatch: {
177
+ codeValue: { $in: params.videoFormatTypes },
178
+ 'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.VideoFormatType }
179
+ }
180
+ }
181
+ });
182
+ // 存在する適用決済カード区分の分だけ検索する(2023-03-03~)
183
+ if (movieTicketServiceTypes.length > 0) {
184
+ movieTicketTypeChargeSpecs =
185
+ yield repos.priceSpecification.search({
186
+ project: { id: { $eq: params.project.id } },
187
+ typeOf: factory.priceSpecificationType.MovieTicketTypeChargeSpecification,
188
+ appliesToVideoFormats: params.videoFormatTypes,
189
+ appliesToMovieTicket: {
190
+ serviceTypes: movieTicketServiceTypes
191
+ }
192
+ });
193
+ }
194
+ }
195
+ return { soundFormatChargeSpecs, videoFormatChargeSpecs, movieTicketTypeChargeSpecs };
299
196
  });
300
197
  }
301
198
  function checkAvailability(params) {
302
199
  return (repos) => __awaiter(this, void 0, void 0, function* () {
303
200
  var _a, _b;
304
- const offer4event = params.offer;
201
+ const unitPriceOffer = params.unitPriceOffer;
202
+ let availability;
305
203
  // レート制限を確認
306
- const scope = (_a = offer4event.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope;
307
- const unitInSeconds = (_b = offer4event.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
204
+ const scope = (_a = unitPriceOffer.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope;
205
+ const unitInSeconds = (_b = unitPriceOffer.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
308
206
  if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
309
207
  const rateLimitKey = {
310
208
  reservedTicket: {
@@ -324,10 +222,10 @@ function checkAvailability(params) {
324
222
  const holder = yield repos.offerRateLimit.getHolder(rateLimitKey);
325
223
  // ロックされていればOutOfStock
326
224
  if (typeof holder === 'string' && holder.length > 0) {
327
- offer4event.availability = factory.itemAvailability.OutOfStock;
225
+ availability = factory.itemAvailability.OutOfStock;
328
226
  }
329
227
  }
330
- return offer4event;
228
+ return availability;
331
229
  });
332
230
  }
333
231
  /**
@@ -336,45 +234,54 @@ function checkAvailability(params) {
336
234
  function searchAddOns(params) {
337
235
  return (repos) => __awaiter(this, void 0, void 0, function* () {
338
236
  var _a, _b, _c;
339
- let offers = [];
237
+ let addOns = [];
340
238
  const productId = (_a = params.product) === null || _a === void 0 ? void 0 : _a.id;
341
239
  if (typeof productId === 'string') {
342
240
  const productWithAddOns = yield repos.product.findById({ id: productId });
343
241
  const offerCatalogId = (_b = productWithAddOns.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id;
344
242
  if (typeof offerCatalogId === 'string') {
345
- offers = yield repos.offer.findOffersByOfferCatalogId({
243
+ const { offers, sortedOfferIds } = yield repos.offer.findOffersByOfferCatalogId({
346
244
  offerCatalog: { id: offerCatalogId },
347
245
  availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
246
+ excludeAppliesToMovieTicket: false,
247
+ onlyValid: params.onlyValid === true,
348
248
  sort: true
349
249
  });
350
- offers = offers.map((o) => {
351
- return Object.assign(Object.assign({ additionalProperty: Array.isArray(o.additionalProperty) ? o.additionalProperty : [], alternateName: o.alternateName, availability: o.availability, availableAtOrFrom: o.availableAtOrFrom, color: o.color, description: o.description, id: o.id, identifier: o.identifier, itemOffered: {
352
- description: productWithAddOns.description,
353
- id: productWithAddOns.id,
354
- name: productWithAddOns.name,
355
- productID: productWithAddOns.productID,
356
- project: productWithAddOns.project,
357
- typeOf: productWithAddOns.typeOf
358
- }, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: o.priceSpecification, project: o.project, typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
250
+ const unitPriceOffers = offers;
251
+ addOns = unitPriceOffers.map((o) => {
252
+ let sortIndex;
253
+ if (params.addSortIndex) {
254
+ sortIndex = sortedOfferIds.indexOf(String(o.id));
255
+ }
256
+ const itemOffered4addOn = {
257
+ description: productWithAddOns.description,
258
+ id: productWithAddOns.id,
259
+ name: productWithAddOns.name,
260
+ productID: productWithAddOns.productID,
261
+ // project: productWithAddOns.project,
262
+ typeOf: productWithAddOns.typeOf
263
+ };
264
+ return Object.assign(Object.assign(Object.assign({
265
+ // additionalProperty: Array.isArray(o.additionalProperty) ? o.additionalProperty : [],
266
+ alternateName: o.alternateName, availability: o.availability,
267
+ // availableAtOrFrom: o.availableAtOrFrom,
268
+ // color: o.color,
269
+ description: o.description, id: String(o.id), identifier: o.identifier, itemOffered: itemOffered4addOn, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: o.priceSpecification,
270
+ // project: o.project,
271
+ typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined), (typeof sortIndex === 'number') ? { sortIndex } : undefined);
359
272
  });
360
273
  }
361
274
  }
362
- return offers;
275
+ return addOns;
363
276
  });
364
277
  }
365
278
  /**
366
279
  * 興行オファー検索
367
280
  */
368
281
  function searchEventTicketOffers(params) {
369
- // tslint:disable-next-line:max-func-body-length
370
282
  return (repos) => __awaiter(this, void 0, void 0, function* () {
371
- const now = moment();
372
- let event;
373
- // イベント取得属性最適化(2023-01-23~)
374
- // event = await repos.event.findById<factory.eventType.ScreeningEvent | factory.eventType.Event>({ id: params.event.id });
375
- event = yield repos.event.findMinimizedIndividualEventById({
376
- id: params.event.id
377
- });
283
+ // const now = moment();
284
+ const event = yield repos.event.findMinimizedIndividualEventById({ id: params.event.id });
378
285
  let offers;
379
286
  let unitPriceOffers;
380
287
  const eventOffers = event.offers;
@@ -388,86 +295,55 @@ function searchEventTicketOffers(params) {
388
295
  case factory.service.webAPI.Identifier.COA:
389
296
  throw new factory.errors.NotImplemented(`booking service '${eventOffers.offeredThrough.identifier}' not implemented`);
390
297
  default:
391
- // Chevreで券種オファーを検索
392
- if (event.typeOf === factory.eventType.ScreeningEvent) {
393
- const searchOffersResult = yield searchScreeningEventTicketOffers({
394
- ids: params.ids,
395
- event,
396
- store: params.store,
397
- sort: params.sort,
398
- validateOfferRateLimit: params.validateOfferRateLimit
399
- })(repos);
400
- offers = searchOffersResult.ticketOffers;
401
- unitPriceOffers = searchOffersResult.unitPriceOffers;
402
- }
403
- else if (event.typeOf === factory.eventType.Event) {
404
- const searchOffersResult = yield searchTransportationEventTicketOffers({
405
- ids: params.ids,
406
- event,
407
- store: params.store,
408
- sort: params.sort,
409
- validateOfferRateLimit: params.validateOfferRateLimit
410
- })(repos);
411
- offers = searchOffersResult.ticketOffers;
412
- unitPriceOffers = searchOffersResult.unitPriceOffers;
413
- }
414
- else {
415
- throw new factory.errors.NotImplemented(`'${event.typeOf}' not implemented`);
416
- }
417
- // store.idでのフィルターをmongoに移行(2023-01-27~)
418
- // const specifiedStoreId = params.store?.id;
419
- // if (typeof specifiedStoreId === 'string') {
420
- // // アプリケーションが利用可能なオファーに絞る
421
- // offers = offers.filter((o) => {
422
- // return Array.isArray(o.availableAtOrFrom)
423
- // && o.availableAtOrFrom.some((availableApplication) => availableApplication.id === specifiedStoreId);
424
- // });
425
- // }
426
- // 有効期間を適用
427
- if (params.onlyValid === true) {
428
- offers = offers.filter((o) => {
429
- let isvalid = true;
430
- if (o.validFrom !== undefined && moment(o.validFrom)
431
- .isAfter(now)) {
432
- isvalid = false;
433
- }
434
- if (o.validThrough !== undefined && moment(o.validThrough)
435
- .isBefore(now)) {
436
- isvalid = false;
437
- }
438
- return isvalid;
439
- });
440
- }
441
- for (const offer of offers) {
442
- if (Array.isArray(offer.addOn)) {
443
- // store.idでのフィルターをmongoに移行(2023-01-27~)
444
- // addOnsに対しても利用可能アプリケーション設定を適用
445
- // if (typeof specifiedStoreId === 'string') {
446
- // // アプリケーションが利用可能なオファーに絞る
447
- // offer.addOn = offer.addOn.filter((offer4addOn) => {
448
- // return Array.isArray(offer4addOn.availableAtOrFrom)
449
- // && offer4addOn.availableAtOrFrom.some(
450
- // (availableApplication) => availableApplication.id === specifiedStoreId
451
- // );
452
- // });
453
- // }
454
- // addOnsに対しても有効期間を適用
455
- if (params.onlyValid === true) {
456
- offer.addOn = offer.addOn.filter((offer4addOn) => {
457
- let isvalid = true;
458
- if (offer4addOn.validFrom !== undefined && moment(offer4addOn.validFrom)
459
- .isAfter(now)) {
460
- isvalid = false;
461
- }
462
- if (offer4addOn.validThrough !== undefined && moment(offer4addOn.validThrough)
463
- .isBefore(now)) {
464
- isvalid = false;
465
- }
466
- return isvalid;
467
- });
468
- }
469
- }
470
- }
298
+ const searchOffersResult = yield searchEventTicketOffersByEvent({
299
+ ids: params.ids,
300
+ event,
301
+ store: params.store,
302
+ limit: params.limit,
303
+ page: params.page,
304
+ addSortIndex: params.addSortIndex,
305
+ validateOfferRateLimit: params.validateOfferRateLimit,
306
+ onlyValid: params.onlyValid === true,
307
+ searchAddOns: params.searchAddOns
308
+ })(repos);
309
+ offers = searchOffersResult.ticketOffers;
310
+ unitPriceOffers = searchOffersResult.unitPriceOffers;
311
+ // mongo条件へ移行(2023-02-24~)
312
+ // 有効期間を適用
313
+ // if (params.onlyValid === true) {
314
+ // offers = offers.filter((o) => {
315
+ // let isvalid = true;
316
+ // if (o.validFrom !== undefined && moment(o.validFrom)
317
+ // .isAfter(now)) {
318
+ // isvalid = false;
319
+ // }
320
+ // if (o.validThrough !== undefined && moment(o.validThrough)
321
+ // .isBefore(now)) {
322
+ // isvalid = false;
323
+ // }
324
+ // return isvalid;
325
+ // });
326
+ // }
327
+ // mongo条件へ移行(2023-02-27~)
328
+ // for (const offer of offers) {
329
+ // if (Array.isArray(offer.addOn)) {
330
+ // // addOnsに対しても有効期間を適用
331
+ // if (params.onlyValid === true) {
332
+ // offer.addOn = offer.addOn.filter((offer4addOn) => {
333
+ // let isvalid = true;
334
+ // if (offer4addOn.validFrom !== undefined && moment(offer4addOn.validFrom)
335
+ // .isAfter(now)) {
336
+ // isvalid = false;
337
+ // }
338
+ // if (offer4addOn.validThrough !== undefined && moment(offer4addOn.validThrough)
339
+ // .isBefore(now)) {
340
+ // isvalid = false;
341
+ // }
342
+ // return isvalid;
343
+ // });
344
+ // }
345
+ // }
346
+ // }
471
347
  }
472
348
  return { ticketOffers: offers, unitPriceOffers };
473
349
  });