@chevre/domain 20.2.0-alpha.3 → 20.2.0-alpha.4

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.
@@ -13,6 +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
21
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
22
+ var _a, _b, _c;
23
+ const screeningEvent = yield repos.event.findById({ id: params.eventId });
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
+ offerCatalog: { id: transportation.hasOfferCatalog.id }
34
+ });
35
+ }
36
+ }
37
+ else {
38
+ // hasOfferCatalog参照廃止(2022-09-02~)
39
+ throw new factory.errors.NotFound('event.offers.itemOffered.id');
40
+ }
41
+ const { soundFormatChargeSpecifications, videoFormatChargeSpecifications, movieTicketTypeChargeSpecs } = yield searchPriceSpecs4event({ project: { id: screeningEvent.project.id }, soundFormatTypes, videoFormatTypes })(repos);
42
+ const screeningEventOfferSettings = screeningEvent.offers;
43
+ if (screeningEventOfferSettings === undefined) {
44
+ throw new factory.errors.NotFound('event.offers');
45
+ }
46
+ const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event: screeningEvent });
47
+ // 不許可決済方法があれば、該当オファーを除外
48
+ if (Array.isArray(unacceptedPaymentMethod) && unacceptedPaymentMethod.length > 0) {
49
+ availableOffers = availableOffers.filter((o) => {
50
+ var _a;
51
+ // 複数決済カード対応(2022-07-11~)
52
+ const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
53
+ if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
54
+ return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
55
+ return !unacceptedPaymentMethod.includes(appliesToMovieTicket.serviceOutput.typeOf);
56
+ });
57
+ }
58
+ else {
59
+ // Arrayでないケースは廃止(2022-09-10~)
60
+ return true;
61
+ }
62
+ });
63
+ }
64
+ // 適用決済カード条件がある場合、決済カード加算料金が存在しないオファーは除外する
65
+ availableOffers = availableOffers.filter((o) => {
66
+ var _a;
67
+ // 複数決済カード対応(2022-07-26~)
68
+ const priceSpecificationAppliesToMovieTicket = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket;
69
+ if (Array.isArray(priceSpecificationAppliesToMovieTicket)) {
70
+ // 適用決済カード数が0であれば除外
71
+ if (priceSpecificationAppliesToMovieTicket.length === 0) {
72
+ return false;
73
+ }
74
+ // 上映方式がなければ除外(2022-11-03~)
75
+ if (videoFormatTypes.length === 0) {
76
+ return false;
77
+ }
78
+ return priceSpecificationAppliesToMovieTicket.every((appliesToMovieTicket) => {
79
+ // すべての上映方式について検証する(2022-10-29~)
80
+ return videoFormatTypes.every((videoFormat) => {
81
+ return movieTicketTypeChargeSpecs.some((s) => {
82
+ var _a, _b, _c, _d;
83
+ 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)
84
+ && ((_d = s.appliesToMovieTicket) === null || _d === void 0 ? void 0 : _d.serviceType) === appliesToMovieTicket.serviceType
85
+ && s.appliesToVideoFormat === videoFormat;
86
+ });
87
+ });
88
+ });
89
+ }
90
+ else {
91
+ // Arrayでないケースは廃止(2022-09-10~)
92
+ return true;
93
+ }
94
+ });
95
+ let offers4event = availableOffers.map((availableOffer) => {
96
+ return (0, factory_1.createCompoundPriceSpec4event)({
97
+ eligibleQuantity: screeningEventOfferSettings.eligibleQuantity,
98
+ offer: availableOffer,
99
+ videoFormatChargeSpecifications,
100
+ soundFormatChargeSpecifications,
101
+ movieTicketTypeChargeSpecs,
102
+ videoFormatTypes
103
+ });
104
+ });
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
+ for (const offer of offers4event) {
111
+ const offerAddOn = [];
112
+ if (Array.isArray(offer.addOn)) {
113
+ for (const addOn of offer.addOn) {
114
+ const productId = (_c = addOn.itemOffered) === null || _c === void 0 ? void 0 : _c.id;
115
+ if (typeof productId === 'string') {
116
+ const productOffers = yield searchAddOns({ product: { id: productId } })(repos);
117
+ offerAddOn.push(...productOffers);
118
+ }
119
+ }
120
+ }
121
+ offer.addOn = offerAddOn;
122
+ }
123
+ return offers4event;
124
+ });
125
+ }
16
126
  /**
17
127
  * 興行オファー全検索
18
128
  */
@@ -243,9 +353,7 @@ function searchEventTicketOffers(params) {
243
353
  var _a;
244
354
  const now = moment();
245
355
  let event;
246
- event = yield repos.event.findById({
247
- id: params.event.id
248
- });
356
+ event = yield repos.event.findById({ id: params.event.id });
249
357
  let offers;
250
358
  const eventOffers = event.offers;
251
359
  if (eventOffers === undefined) {
@@ -259,7 +367,15 @@ function searchEventTicketOffers(params) {
259
367
  throw new factory.errors.NotImplemented(`booking service '${eventOffers.offeredThrough.identifier}' not implemented`);
260
368
  default:
261
369
  // Chevreで券種オファーを検索
262
- offers = yield searchScreeningEventTicketOffers({ eventId: params.event.id })(repos);
370
+ if (event.typeOf === factory.eventType.ScreeningEvent) {
371
+ offers = yield searchScreeningEventTicketOffers({ eventId: params.event.id })(repos);
372
+ }
373
+ else if (event.typeOf === factory.eventType.Event) {
374
+ offers = yield searchTransportationEventTicketOffers({ eventId: params.event.id })(repos);
375
+ }
376
+ else {
377
+ throw new factory.errors.NotImplemented(`'${event.typeOf}' not implemented`);
378
+ }
263
379
  const specifiedStoreId = (_a = params.store) === null || _a === void 0 ? void 0 : _a.id;
264
380
  if (typeof specifiedStoreId === 'string') {
265
381
  // アプリケーションが利用可能なオファーに絞る
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.3"
123
+ "version": "20.2.0-alpha.4"
124
124
  }