@chevre/domain 23.1.0-alpha.9 → 23.2.0-alpha.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 (100) hide show
  1. package/example/src/chevre/{eventOffer/adminEventOffers.ts → acceptedPaymentMethodOffer/adminAcceptedPaymentMethodOffers.ts} +12 -11
  2. package/example/src/chevre/actions/checkAcceptPayActions.ts +60 -0
  3. package/example/src/chevre/assetTransaction/checkPayTransactionsTicketToken.ts +67 -0
  4. package/example/src/chevre/event/importEventSeriesFromCOAByTitle.ts +83 -0
  5. package/example/src/chevre/event/importEventsFromCOAByTitle.ts +148 -0
  6. package/example/src/chevre/eventSeries/migrateEventSeriesUnacceptedPaymentMethod.ts +93 -0
  7. package/example/src/chevre/importEventsFromCOA.ts +5 -5
  8. package/example/src/chevre/pendingReservation/findEventSeatOffersBySection.ts +46 -0
  9. package/example/src/chevre/place/checkSectionCount.ts +27 -0
  10. package/example/src/chevre/place/findSectionsByRoom.ts +50 -0
  11. package/example/src/chevre/project/unsetProjectSettings.ts +73 -0
  12. package/example/src/chevre/reIndex.ts +0 -1
  13. package/example/src/chevre/roles/{addAdminSellerEventIfNotExists.ts → addAdminSellerEventOfferIfNotExists.ts} +1 -1
  14. package/example/src/chevre/stockHolder/findSeatsBySection.ts +59 -0
  15. package/example/src/chevre/stockHolder/searchSeats.ts +2 -2
  16. package/lib/chevre/repo/acceptedPaymentMethod.d.ts +41 -0
  17. package/lib/chevre/repo/acceptedPaymentMethod.js +180 -0
  18. package/lib/chevre/repo/authorization.d.ts +3 -2
  19. package/lib/chevre/repo/authorization.js +13 -5
  20. package/lib/chevre/repo/event.d.ts +1 -35
  21. package/lib/chevre/repo/event.js +2 -102
  22. package/lib/chevre/repo/eventOffer.js +3 -3
  23. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.d.ts +10 -0
  24. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.js +97 -0
  25. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +9 -0
  26. package/lib/chevre/repo/note.js +4 -2
  27. package/lib/chevre/repo/pendingReservation.js +28 -71
  28. package/lib/chevre/repo/place/seat.d.ts +24 -0
  29. package/lib/chevre/repo/place/seat.js +103 -21
  30. package/lib/chevre/repo/place/section.d.ts +20 -0
  31. package/lib/chevre/repo/place/section.js +47 -0
  32. package/lib/chevre/repo/ticket.d.ts +7 -1
  33. package/lib/chevre/repo/ticket.js +14 -1
  34. package/lib/chevre/repository.d.ts +5 -0
  35. package/lib/chevre/repository.js +15 -2
  36. package/lib/chevre/service/aggregation/event/importFromCOA.js +2 -2
  37. package/lib/chevre/service/assetTransaction/pay/factory.d.ts +1 -1
  38. package/lib/chevre/service/assetTransaction/pay/factory.js +8 -3
  39. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.d.ts +16 -0
  40. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.js +94 -0
  41. package/lib/chevre/service/assetTransaction/pay.d.ts +6 -1
  42. package/lib/chevre/service/assetTransaction/pay.js +6 -1
  43. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.d.ts +1 -2
  44. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +7 -7
  45. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +6 -2
  46. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +30 -30
  47. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +0 -1
  48. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +7 -51
  49. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +6 -8
  50. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +29 -1
  51. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +9 -9
  52. package/lib/chevre/service/event/factory.d.ts +22 -0
  53. package/lib/chevre/service/event/factory.js +2 -0
  54. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +24 -0
  55. package/lib/chevre/service/event/processUpdateMovieTheater.js +190 -0
  56. package/lib/chevre/service/event/saveScreeningEventSeries.d.ts +63 -0
  57. package/lib/chevre/service/event/saveScreeningEventSeries.js +277 -0
  58. package/lib/chevre/service/event/saveScreeningEvents.d.ts +46 -0
  59. package/lib/chevre/service/event/saveScreeningEvents.js +321 -0
  60. package/lib/chevre/service/event.d.ts +4 -34
  61. package/lib/chevre/service/event.js +12 -698
  62. package/lib/chevre/service/eventOld.d.ts +60 -0
  63. package/lib/chevre/service/eventOld.js +864 -0
  64. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +1 -1
  65. package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +48 -0
  66. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +123 -0
  67. package/lib/chevre/service/offer/event.d.ts +2 -1
  68. package/lib/chevre/service/offer/event.js +3 -1
  69. package/lib/chevre/service/offer.d.ts +31 -1
  70. package/lib/chevre/service/offer.js +104 -34
  71. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +9 -0
  72. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +22 -11
  73. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +19 -2
  74. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +87 -9
  75. package/lib/chevre/service/payment/any/factory.d.ts +20 -3
  76. package/lib/chevre/service/payment/any/factory.js +26 -6
  77. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +4 -0
  78. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +15 -11
  79. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.d.ts +6 -3
  80. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +8 -22
  81. package/lib/chevre/service/payment/any.d.ts +5 -1
  82. package/lib/chevre/service/payment/any.js +22 -13
  83. package/lib/chevre/service/payment/factory.js +0 -5
  84. package/lib/chevre/service/payment/movieTicket/authorize.js +0 -5
  85. package/lib/chevre/service/task/authorizePayment.js +2 -0
  86. package/lib/chevre/service/task/publishPaymentUrl.js +4 -0
  87. package/lib/chevre/service/transaction/placeOrder/confirm/publishCode.js +1 -1
  88. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +9 -0
  89. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.js +2 -0
  90. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.d.ts +8 -0
  91. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.js +45 -0
  92. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.d.ts +3 -0
  93. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +38 -0
  94. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +2 -8
  95. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +5 -35
  96. package/package.json +3 -3
  97. package/example/src/chevre/checkReplaceActions.ts +0 -65
  98. package/example/src/chevre/upsertManyEventsByAdditionalProperty.ts +0 -193
  99. package/lib/chevre/service/code.d.ts +0 -8
  100. package/lib/chevre/service/code.js +0 -7
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.validateStartRequest = validateStartRequest;
13
+ exports.validEventOfferByApplicationExists = validEventOfferByApplicationExists;
13
14
  const moment = require("moment");
14
15
  const factory = require("../../../factory");
15
16
  const fixExtendedEventOffer_1 = require("./validateStartRequest/fixExtendedEventOffer");
@@ -33,12 +34,12 @@ function validateStartRequest(params) {
33
34
  object: params.object,
34
35
  instrument: params.instrument
35
36
  })(repos);
36
- yield validateApplicationOffer({
37
+ yield validEventOfferByApplicationExists({
37
38
  event,
38
39
  now,
39
40
  availableAt: { id: params.store.id },
40
- object: params.object,
41
- acceptedEventOffer
41
+ acceptedEventOffer,
42
+ numAcceptedOffers: (Array.isArray(params.object.acceptedOffer)) ? params.object.acceptedOffer.length : 0
42
43
  })(repos);
43
44
  }
44
45
  if (params.validateEvent === true) {
@@ -47,11 +48,11 @@ function validateStartRequest(params) {
47
48
  });
48
49
  }
49
50
  /**
50
- * アプリケーションごとのオファーを検証する
51
+ * アプリケーションに対して有効なイベントオファーが存在するかどうかを検証する
51
52
  */
52
- function validateApplicationOffer(params) {
53
+ function validEventOfferByApplicationExists(params) {
53
54
  return (repos) => __awaiter(this, void 0, void 0, function* () {
54
- const { event, availableAt, acceptedEventOffer } = params;
55
+ const { event, availableAt, acceptedEventOffer, numAcceptedOffers } = params;
55
56
  const acceptedDate = moment(params.now);
56
57
  const eventOffers = event.offers;
57
58
  // アプリケーションごとの設定を参照する(2022-11-19~)
@@ -85,9 +86,9 @@ function validateApplicationOffer(params) {
85
86
  yield (0, validateIssuedOfferIfExists_1.validateIssuedOfferIfExists)({
86
87
  event,
87
88
  now: params.now,
88
- object: params.object,
89
89
  eventOffer: existingEventOffer,
90
- acceptedEventOffer
90
+ acceptedEventOffer,
91
+ numAcceptedOffers
91
92
  })(repos);
92
93
  }
93
94
  else {
@@ -96,7 +97,6 @@ function validateApplicationOffer(params) {
96
97
  yield (0, validateMemberTierIfExists_1.validateMemberTierIfExists)({
97
98
  event,
98
99
  now: params.now,
99
- object: params.object,
100
100
  makesOfferOnApplication,
101
101
  acceptedEventOffer
102
102
  })(repos);
@@ -0,0 +1,22 @@
1
+ import * as factory from '../../factory';
2
+ export interface IImportFromCOAParams {
3
+ project: {
4
+ id: string;
5
+ typeOf: factory.organizationType.Project;
6
+ };
7
+ /**
8
+ * 施設コード
9
+ */
10
+ locationBranchCode: string;
11
+ importFrom: Date;
12
+ importThrough: Date;
13
+ /**
14
+ * 施設を保管するかどうか
15
+ */
16
+ saveMovieTheater: boolean;
17
+ /**
18
+ * 施設コンテンツを保管するかどうか
19
+ */
20
+ saveScreeningEventSeries: boolean;
21
+ saveScreeningEventSeriesPeriodInMonth: number;
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ import type * as COA from '@motionpicture/coa-service';
2
+ import type { ActionRepo } from '../../repo/action';
3
+ import type { CategoryCodeRepo } from '../../repo/categoryCode';
4
+ import type { MovieTheaterRepo } from '../../repo/place/movieTheater';
5
+ import type { ScreeningRoomRepo } from '../../repo/place/screeningRoom';
6
+ import type { SellerRepo } from '../../repo/seller';
7
+ import * as factory from '../../factory';
8
+ import { IImportFromCOAParams } from './factory';
9
+ type IMovieTheater = Pick<factory.place.movieTheater.IPlace, 'id' | 'typeOf' | 'branchCode' | 'name' | 'kanaName'>;
10
+ declare function processUpdateMovieTheater(params: IImportFromCOAParams): (repos: {
11
+ masterService: COA.service.Master;
12
+ action: ActionRepo;
13
+ categoryCode: CategoryCodeRepo;
14
+ movieTheater: MovieTheaterRepo;
15
+ screeningRoom: ScreeningRoomRepo;
16
+ seller: SellerRepo;
17
+ }) => Promise<{
18
+ seller: {
19
+ id: string;
20
+ };
21
+ movieTheater: IMovieTheater;
22
+ screeningRooms: Omit<factory.place.screeningRoom.IPlace, "containsPlace" | "parentOrganization">[];
23
+ }>;
24
+ export { processUpdateMovieTheater };
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.processUpdateMovieTheater = processUpdateMovieTheater;
13
+ const factory = require("../../factory");
14
+ // tslint:disable-next-line:max-func-body-length
15
+ function processUpdateMovieTheater(params) {
16
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
17
+ const actionAttributes = {
18
+ project: { typeOf: factory.organizationType.Project, id: params.project.id },
19
+ typeOf: factory.actionType.ReplaceAction,
20
+ agent: { typeOf: factory.organizationType.Project, id: params.project.id },
21
+ object: Object.assign(Object.assign({}, params), { branchCode: params.locationBranchCode, typeOf: factory.placeType.MovieTheater }),
22
+ instrument: {
23
+ theaterCode: params.locationBranchCode,
24
+ typeOf: 'WebAPI',
25
+ identifier: factory.service.webAPI.Identifier.COA
26
+ },
27
+ targetCollection: { typeOf: factory.placeType.MovieTheater }
28
+ };
29
+ const action = yield repos.action.start(actionAttributes);
30
+ let seller;
31
+ let movieTheater;
32
+ let screeningRooms;
33
+ let processTime;
34
+ try {
35
+ // 同ブランチコードの販売者を検索する
36
+ const sellersWithSameBranchCode = yield repos.seller.projectFields({
37
+ limit: 1,
38
+ page: 1,
39
+ project: { id: { $eq: params.project.id } },
40
+ branchCode: { $eq: params.locationBranchCode }
41
+ }, ['id']);
42
+ const sellerWithSameBranchCode = sellersWithSameBranchCode.shift();
43
+ if (typeof (sellerWithSameBranchCode === null || sellerWithSameBranchCode === void 0 ? void 0 : sellerWithSameBranchCode.id) !== 'string') {
44
+ throw new factory.errors.NotFound('Seller', `Seller with branchCode '${params.locationBranchCode}' not found`);
45
+ }
46
+ seller = { id: sellerWithSameBranchCode.id };
47
+ // saveMovieTheater:trueの場合のみ、施設保管(2022-10-10~)
48
+ if (params.saveMovieTheater === true) {
49
+ const processStart = process.hrtime.bigint();
50
+ const savingMovieTheater = createMovieTheaterFromCOA(params.project, { id: seller.id }, yield repos.masterService.theater({ theaterCode: params.locationBranchCode }), yield repos.masterService.screen({ theaterCode: params.locationBranchCode }));
51
+ yield repos.movieTheater.saveMovieTheaterByBranchCode4coa(savingMovieTheater);
52
+ yield repos.screeningRoom.saveScreeningRooms4coa(savingMovieTheater);
53
+ const processEnd = process.hrtime.bigint();
54
+ processTime = processEnd - processStart;
55
+ }
56
+ const movieTheaters = yield repos.movieTheater.projectFields({
57
+ limit: 1,
58
+ page: 1,
59
+ project: { id: { $eq: params.project.id } },
60
+ branchCode: { $eq: params.locationBranchCode }
61
+ }, ['id', 'typeOf', 'branchCode', 'name', 'kanaName']
62
+ // []
63
+ );
64
+ movieTheater = movieTheaters.shift();
65
+ if (movieTheater === undefined) {
66
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
67
+ }
68
+ screeningRooms = yield repos.screeningRoom.searchScreeningRooms({
69
+ project: { id: { $eq: params.project.id } },
70
+ containedInPlace: { branchCode: { $eq: movieTheater.branchCode } }
71
+ });
72
+ }
73
+ catch (error) {
74
+ try {
75
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
76
+ }
77
+ catch (__) {
78
+ // 失敗したら仕方ない
79
+ }
80
+ throw error;
81
+ }
82
+ const actionResult = Object.assign({ screeningRoomsCount: screeningRooms.length }, (processTime !== undefined) ? { processTime } : undefined);
83
+ yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
84
+ return { seller, movieTheater, screeningRooms };
85
+ });
86
+ }
87
+ /**
88
+ * コアマスター抽出結果から作成する
89
+ */
90
+ // tslint:disable-next-line:no-single-line-block-comment
91
+ /* istanbul ignore next */
92
+ function createMovieTheaterFromCOA(project, seller, theaterFromCOA, screensFromCOA) {
93
+ // const id = `MovieTheater-${theaterFromCOA.theaterCode}`;
94
+ return {
95
+ project: { typeOf: project.typeOf, id: project.id },
96
+ // id: id,
97
+ // screenCount: screensFromCOA.length,
98
+ branchCode: theaterFromCOA.theaterCode,
99
+ name: {
100
+ ja: theaterFromCOA.theaterName,
101
+ en: theaterFromCOA.theaterNameEng
102
+ },
103
+ kanaName: theaterFromCOA.theaterNameKana,
104
+ containsPlace: screensFromCOA.map((screenFromCOA) => {
105
+ return createScreeningRoomFromCOA(project, seller, screenFromCOA);
106
+ }),
107
+ typeOf: factory.placeType.MovieTheater,
108
+ telephone: theaterFromCOA.theaterTelNum,
109
+ offers: {
110
+ // project: { typeOf: project.typeOf, id: project.id }, // optimize(2023-11-06~)
111
+ // priceCurrency: factory.priceCurrency.JPY, // optimize(2023-11-06~)
112
+ typeOf: factory.offerType.Offer,
113
+ eligibleQuantity: {
114
+ typeOf: 'QuantitativeValue',
115
+ maxValue: 6,
116
+ unitCode: factory.unitCode.C62
117
+ },
118
+ availabilityStartsGraceTime: {
119
+ typeOf: 'QuantitativeValue',
120
+ value: -2,
121
+ unitCode: factory.unitCode.Day
122
+ },
123
+ availabilityEndsGraceTime: {
124
+ typeOf: 'QuantitativeValue',
125
+ value: 1200,
126
+ unitCode: factory.unitCode.Sec
127
+ },
128
+ availabilityStartsGraceTimeOnPOS: {
129
+ typeOf: 'QuantitativeValue',
130
+ value: -93,
131
+ unitCode: factory.unitCode.Day
132
+ },
133
+ availabilityEndsGraceTimeOnPOS: {
134
+ typeOf: 'QuantitativeValue',
135
+ value: 2678400,
136
+ unitCode: factory.unitCode.Sec
137
+ }
138
+ },
139
+ parentOrganization: { id: seller.id, typeOf: factory.organizationType.Corporation }
140
+ };
141
+ }
142
+ /**
143
+ * コアスクリーン抽出結果からルームを作成する
144
+ */
145
+ // tslint:disable-next-line:no-single-line-block-comment
146
+ /* istanbul ignore next */
147
+ function createScreeningRoomFromCOA(project, seller, screenFromCOA) {
148
+ const sections = [];
149
+ const sectionCodes = [];
150
+ screenFromCOA.listSeat.forEach((seat) => {
151
+ if (sectionCodes.indexOf(seat.seatSection) < 0) {
152
+ sectionCodes.push(seat.seatSection);
153
+ sections.push({
154
+ project: { typeOf: project.typeOf, id: project.id },
155
+ branchCode: seat.seatSection,
156
+ name: {
157
+ ja: `セクション${seat.seatSection}`,
158
+ en: `section${seat.seatSection}`
159
+ },
160
+ containsPlace: [],
161
+ typeOf: factory.placeType.ScreeningRoomSection
162
+ });
163
+ }
164
+ sections[sectionCodes.indexOf(seat.seatSection)].containsPlace.push({
165
+ project: { typeOf: project.typeOf, id: project.id },
166
+ branchCode: seat.seatNum,
167
+ typeOf: factory.placeType.Seat,
168
+ additionalProperty: [
169
+ { name: 'flgFree', value: String(seat.flgFree) },
170
+ { name: 'flgHc', value: String(seat.flgHc) },
171
+ { name: 'flgPair', value: String(seat.flgPair) },
172
+ { name: 'flgSpare', value: String(seat.flgSpare) },
173
+ { name: 'flgSpecial', value: String(seat.flgSpecial) }
174
+ ]
175
+ });
176
+ });
177
+ return {
178
+ project: { typeOf: project.typeOf, id: project.id },
179
+ containsPlace: sections,
180
+ branchCode: screenFromCOA.screenCode,
181
+ name: {
182
+ ja: screenFromCOA.screenName,
183
+ en: screenFromCOA.screenNameEng
184
+ },
185
+ typeOf: factory.placeType.ScreeningRoom,
186
+ maximumAttendeeCapacity: sections[0].containsPlace.length,
187
+ // 必須化(2023-07-14~)
188
+ parentOrganization: { id: seller.id, typeOf: factory.organizationType.Corporation }
189
+ };
190
+ }
@@ -0,0 +1,63 @@
1
+ import type * as COA from '@motionpicture/coa-service';
2
+ import type { CategoryCodeRepo } from '../../repo/categoryCode';
3
+ import type { CreativeWorkRepo } from '../../repo/creativeWork';
4
+ import type { EventSeriesRepo } from '../../repo/eventSeries';
5
+ import * as factory from '../../factory';
6
+ type IMovieTheater = Pick<factory.place.movieTheater.IPlace, 'id' | 'typeOf' | 'branchCode' | 'name' | 'kanaName'>;
7
+ /**
8
+ * - 施設コード
9
+ * - タイトルコード(optional)
10
+ * - タイトル枝番(optional)
11
+ *
12
+ * 指定で、施設コンテンツをインポートする
13
+ *
14
+ * - 作品マスタ抽出
15
+ * - 区分マスタ抽出
16
+ * を使用して、施設コンテンツを作成する
17
+ */
18
+ declare function saveScreeningEventSeries(params: {
19
+ /**
20
+ * 施設コード
21
+ */
22
+ locationBranchCode: string;
23
+ /**
24
+ * 事前に施設から検索すること
25
+ */
26
+ movieTheater: IMovieTheater;
27
+ project: {
28
+ id: string;
29
+ typeOf: factory.organizationType.Project;
30
+ };
31
+ saveScreeningEventSeries: boolean;
32
+ saveScreeningEventSeriesPeriodInMonth: number;
33
+ seller: {
34
+ id: string;
35
+ };
36
+ /**
37
+ * 強制的にインポート対象の施設コンテンツIDを指定する
38
+ * 2024-09-09~
39
+ */
40
+ importingIds?: string[];
41
+ }, options: {
42
+ filterFilmsFromCOA?: {
43
+ titleCode: string;
44
+ titleBranchNum: string;
45
+ };
46
+ }): (repos: {
47
+ categoryCode: CategoryCodeRepo;
48
+ creativeWork: CreativeWorkRepo;
49
+ eventSeries: EventSeriesRepo;
50
+ masterService: COA.service.Master;
51
+ }) => Promise<{
52
+ screeningEventSerieses: factory.eventSeries.IEvent[];
53
+ savedEventsCount: number;
54
+ }>;
55
+ /**
56
+ * COA情報からイベント識別子を作成する
57
+ */
58
+ declare function createScreeningEventSeriesId(params: {
59
+ theaterCode: string;
60
+ titleCode: string;
61
+ titleBranchNum: string;
62
+ }): string;
63
+ export { createScreeningEventSeriesId, saveScreeningEventSeries };
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createScreeningEventSeriesId = createScreeningEventSeriesId;
13
+ exports.saveScreeningEventSeries = saveScreeningEventSeries;
14
+ const createDebug = require("debug");
15
+ const moment = require("moment-timezone");
16
+ // import type { IMovieTheaterIncludingScreeningRooms, MovieTheaterRepo } from '../../repo/place/movieTheater';
17
+ // import type { ScreeningRoomRepo } from '../../repo/place/screeningRoom';
18
+ // import type { SellerRepo } from '../../repo/seller';
19
+ const factory = require("../../factory");
20
+ const debug = createDebug('chevre-domain:service:event');
21
+ /**
22
+ * - 施設コード
23
+ * - タイトルコード(optional)
24
+ * - タイトル枝番(optional)
25
+ *
26
+ * 指定で、施設コンテンツをインポートする
27
+ *
28
+ * - 作品マスタ抽出
29
+ * - 区分マスタ抽出
30
+ * を使用して、施設コンテンツを作成する
31
+ */
32
+ function saveScreeningEventSeries(params, options) {
33
+ // tslint:disable-next-line:max-func-body-length
34
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
35
+ const { importingIds, locationBranchCode, project } = params;
36
+ const { filterFilmsFromCOA } = options;
37
+ let filteredByTitle = false;
38
+ // COAから作品取得
39
+ let filmsFromCOA = yield repos.masterService.title({ theaterCode: locationBranchCode });
40
+ if (typeof (filterFilmsFromCOA === null || filterFilmsFromCOA === void 0 ? void 0 : filterFilmsFromCOA.titleBranchNum) === 'string'
41
+ && typeof (filterFilmsFromCOA === null || filterFilmsFromCOA === void 0 ? void 0 : filterFilmsFromCOA.titleBranchNum) === 'string') {
42
+ filmsFromCOA = filmsFromCOA.filter((film) => {
43
+ return film.titleBranchNum === filterFilmsFromCOA.titleBranchNum
44
+ && film.titleCode === filterFilmsFromCOA.titleCode;
45
+ });
46
+ filteredByTitle = true;
47
+ debug('filmsFromCOA filtered by title.', JSON.stringify(filmsFromCOA));
48
+ }
49
+ debug(filmsFromCOA.length, 'filmsFromCOA processing...');
50
+ // COAから区分マスター抽出
51
+ const eirinKubuns = yield repos.masterService.kubunName({
52
+ theaterCode: locationBranchCode,
53
+ kubunClass: '044'
54
+ });
55
+ const eizouKubuns = yield repos.masterService.kubunName({
56
+ theaterCode: locationBranchCode,
57
+ kubunClass: '042'
58
+ });
59
+ const joueihousikiKubuns = yield repos.masterService.kubunName({
60
+ theaterCode: locationBranchCode,
61
+ kubunClass: '045'
62
+ });
63
+ const jimakufukikaeKubuns = yield repos.masterService.kubunName({
64
+ theaterCode: locationBranchCode,
65
+ kubunClass: '043'
66
+ });
67
+ debug('kubunNames found.');
68
+ const availablePaymentMethodTypes = yield repos.categoryCode.projectCategoryCodeFields({
69
+ project: { id: { $eq: params.project.id } },
70
+ inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.PaymentMethodType } }
71
+ }, ['additionalProperty', 'codeValue']);
72
+ const screeningEventSerieses = filmsFromCOA.map((filmFromCOA) => {
73
+ return createScreeningEventSeriesFromCOA({
74
+ project: project,
75
+ filmFromCOA: filmFromCOA,
76
+ movieTheater: params.movieTheater,
77
+ eirinKubuns: eirinKubuns,
78
+ eizouKubuns: eizouKubuns,
79
+ joueihousikiKubuns: joueihousikiKubuns,
80
+ jimakufukikaeKubuns: jimakufukikaeKubuns,
81
+ availablePaymentMethodTypes,
82
+ seller: params.seller
83
+ });
84
+ });
85
+ const COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH = (typeof params.saveScreeningEventSeriesPeriodInMonth === 'number')
86
+ ? params.saveScreeningEventSeriesPeriodInMonth
87
+ // tslint:disable-next-line:no-magic-numbers
88
+ : 3;
89
+ let savedEventsCount = 0;
90
+ // saveScreeningEventSeries:trueの場合のみ保管(2022-10-10~)
91
+ if (params.saveScreeningEventSeries === true) {
92
+ let saveParams;
93
+ // タイトルでフィルターする場合に対応
94
+ if (filteredByTitle) {
95
+ saveParams = screeningEventSerieses.map((screeningEventSeries) => {
96
+ return {
97
+ id: screeningEventSeries.id,
98
+ attributes: screeningEventSeries,
99
+ upsert: true
100
+ };
101
+ });
102
+ }
103
+ else if (Array.isArray(importingIds) && importingIds.length > 0) {
104
+ saveParams = screeningEventSerieses
105
+ .filter((screeningEventSeries) => importingIds.includes(screeningEventSeries.id))
106
+ .map((screeningEventSeries) => {
107
+ return {
108
+ id: screeningEventSeries.id,
109
+ attributes: screeningEventSeries,
110
+ upsert: true
111
+ };
112
+ });
113
+ }
114
+ else {
115
+ // 更新対象が無限に増えるのを防ぐためにstartDateでフィルター
116
+ const someMonthsAgo = moment()
117
+ .add(-COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH, 'months');
118
+ saveParams = screeningEventSerieses
119
+ .filter((screeningEventSeries) => {
120
+ return moment(screeningEventSeries.startDate)
121
+ .isAfter(someMonthsAgo);
122
+ })
123
+ .map((screeningEventSeries) => {
124
+ return {
125
+ id: screeningEventSeries.id,
126
+ attributes: screeningEventSeries,
127
+ upsert: true
128
+ };
129
+ });
130
+ }
131
+ debug('saving', saveParams.length, 'ScreeningEventSeries...');
132
+ yield repos.eventSeries.upsertManyEventSeriesById4sskts(saveParams);
133
+ debug('saved', saveParams.length, 'ScreeningEventSeries');
134
+ savedEventsCount = saveParams.length;
135
+ // コンテンツ永続化(2023-10-23~)
136
+ try {
137
+ debug('saving', saveParams.length, 'movies...');
138
+ yield repos.creativeWork.upsertMoviesByIdentifier(saveParams.map((saveScreeningEventSeriesParams) => {
139
+ var _a;
140
+ return {
141
+ $set: Object.assign(Object.assign({ typeOf: factory.creativeWorkType.Movie, project: params.project, identifier: saveScreeningEventSeriesParams.attributes.workPerformed.identifier, name: { ja: (_a = saveScreeningEventSeriesParams.attributes.workPerformed.name) === null || _a === void 0 ? void 0 : _a.ja }, offers: { typeOf: factory.offerType.Offer } }, (typeof saveScreeningEventSeriesParams.attributes.workPerformed.contentRating === 'string')
142
+ ? { contentRating: saveScreeningEventSeriesParams.attributes.workPerformed.contentRating }
143
+ : undefined), (typeof saveScreeningEventSeriesParams.attributes.workPerformed.duration === 'string')
144
+ ? { duration: saveScreeningEventSeriesParams.attributes.workPerformed.duration }
145
+ : undefined)
146
+ };
147
+ }));
148
+ debug('saved', saveParams.length, 'movies');
149
+ }
150
+ catch (error) {
151
+ // tslint:disable-next-line:no-console
152
+ console.error('failed in upsertMoviesByIdentifier', error);
153
+ }
154
+ }
155
+ return { screeningEventSerieses, savedEventsCount };
156
+ });
157
+ }
158
+ /**
159
+ * 作品抽出結果から施設コンテンツを作成する
160
+ */
161
+ function createScreeningEventSeriesFromCOA(params) {
162
+ const endDate = (moment(`${params.filmFromCOA.dateEnd} +09:00`, 'YYYYMMDD Z')
163
+ .isValid())
164
+ ? moment(`${params.filmFromCOA.dateEnd} +09:00`, 'YYYYMMDD Z')
165
+ .toDate()
166
+ : moment('2118-01-01T00:00:00+09:00') // 値がない場合、十分に長く
167
+ .toDate();
168
+ const startDate = (moment(`${params.filmFromCOA.dateBegin} +09:00`, 'YYYYMMDD Z')
169
+ .isValid())
170
+ ? moment(`${params.filmFromCOA.dateBegin} +09:00`, 'YYYYMMDD Z')
171
+ .toDate()
172
+ : moment('2018-01-01T00:00:00+09:00') // 値がない場合、十分に長く
173
+ .toDate();
174
+ // title_codeは施設をまたいで共有、title_branch_numは施設毎に管理
175
+ const id = createScreeningEventSeriesId({
176
+ theaterCode: params.movieTheater.branchCode,
177
+ titleCode: params.filmFromCOA.titleCode,
178
+ titleBranchNum: params.filmFromCOA.titleBranchNum
179
+ });
180
+ const { additionalProperty, coaInfo } = createScreeningEventSeriesAdditionalPropertyFromCOA(params);
181
+ const { unacceptedPaymentMethod } = createScreeningEventSeriesUnacceptedPaymentMethodFromCOA(params);
182
+ const workPerformed = Object.assign({
183
+ // id: `${params.movieTheater.branchCode}-${params.filmFromCOA.titleCode}`, // discontinue(2025-01-03~)
184
+ identifier: params.filmFromCOA.titleCode, name: {
185
+ ja: params.filmFromCOA.titleNameOrig
186
+ }, duration: moment.duration(params.filmFromCOA.showTime, 'm')
187
+ .toISOString(), contentRating: params.eirinKubuns.filter((kubun) => kubun.kubunCode === params.filmFromCOA.kbnEirin)[0], typeOf: factory.creativeWorkType.Movie }, (typeof params.filmFromCOA.titleBranchNum === 'string' && params.filmFromCOA.titleBranchNum.length > 0)
188
+ ? { version: params.filmFromCOA.titleBranchNum } // add version(2024-01-31~)
189
+ : undefined);
190
+ // redefine videoFormat(2024-09-18~)
191
+ // const videoFormat: factory.event.screeningEventSeries.ICOAKubun =
192
+ // params.eizouKubuns.filter((kubun) => kubun.kubunCode === params.filmFromCOA.kbnEizou)[0];
193
+ const videoFormat = params.joueihousikiKubuns.filter(({ kubunCode }) => kubunCode === params.filmFromCOA.kbnJoueihousiki)
194
+ .map(({ kubunCode }) => ({ typeOf: kubunCode, name: kubunCode }));
195
+ return {
196
+ project: { typeOf: params.project.typeOf, id: params.project.id },
197
+ typeOf: factory.eventType.ScreeningEventSeries,
198
+ eventStatus: factory.eventStatusType.EventScheduled,
199
+ id: id,
200
+ identifier: id,
201
+ name: {
202
+ ja: params.filmFromCOA.titleName,
203
+ en: params.filmFromCOA.titleNameEng
204
+ },
205
+ kanaName: params.filmFromCOA.titleNameKana,
206
+ alternativeHeadline: params.filmFromCOA.titleNameShort,
207
+ location: {
208
+ id: (params.movieTheater.id !== undefined) ? params.movieTheater.id : '',
209
+ branchCode: params.movieTheater.branchCode,
210
+ name: params.movieTheater.name,
211
+ // 廃止(2024-03-05~)
212
+ // kanaName: params.movieTheater.kanaName,
213
+ typeOf: params.movieTheater.typeOf
214
+ },
215
+ // 必須化(2023-07-12~)
216
+ organizer: { id: params.seller.id },
217
+ videoFormat,
218
+ soundFormat: [],
219
+ workPerformed,
220
+ duration: moment.duration(params.filmFromCOA.showTime, 'm')
221
+ .toISOString(),
222
+ endDate: endDate,
223
+ startDate: startDate,
224
+ coaInfo,
225
+ offers: Object.assign({ typeOf: factory.offerType.Offer }, (Array.isArray(unacceptedPaymentMethod)) ? { unacceptedPaymentMethod: unacceptedPaymentMethod } : undefined),
226
+ additionalProperty
227
+ };
228
+ }
229
+ function createScreeningEventSeriesAdditionalPropertyFromCOA(params) {
230
+ const coaInfo = Object.assign(Object.assign(Object.assign({ titleBranchNum: params.filmFromCOA.titleBranchNum, kbnEirin: params.eirinKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnEirin)[0], kbnEizou: params.eizouKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnEizou)[0], kbnJoueihousiki: params.joueihousikiKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnJoueihousiki)[0], kbnJimakufukikae: params.jimakufukikaeKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnJimakufukikae)[0], flgMvtkUse: params.filmFromCOA.flgMvtkUse, dateMvtkBegin: params.filmFromCOA.dateMvtkBegin }, (typeof params.filmFromCOA.flgMgtkUse === 'string') ? { flgMgtkUse: params.filmFromCOA.flgMgtkUse } : undefined), (typeof params.filmFromCOA.dateMgtkBegin === 'string') ? { dateMgtkBegin: params.filmFromCOA.dateMgtkBegin } : undefined), (typeof params.filmFromCOA.flgNotDiscount === 'string') ? { flgNotDiscount: params.filmFromCOA.flgNotDiscount } : undefined);
231
+ return {
232
+ coaInfo,
233
+ additionalProperty: [
234
+ // { name: 'coaInfo', value: JSON.stringify(coaInfo) } // discontinue(2024-09-13~)
235
+ ]
236
+ };
237
+ }
238
+ function createScreeningEventSeriesUnacceptedPaymentMethodFromCOA(params) {
239
+ let unacceptedPaymentMethod;
240
+ // flgMvtkUseはムビチケ、MGチケットの両方に適用される(<-flgMgtkUseが追加されるまで)(~2024-03-05)
241
+ if (params.filmFromCOA.flgMvtkUse === '1') {
242
+ // no op
243
+ }
244
+ else {
245
+ if (!Array.isArray(unacceptedPaymentMethod)) {
246
+ unacceptedPaymentMethod = [];
247
+ }
248
+ // flgMvtkUseで決済方法区分から動的に
249
+ unacceptedPaymentMethod.push(...params.availablePaymentMethodTypes.filter(({ additionalProperty }) => { var _a; return ((_a = additionalProperty === null || additionalProperty === void 0 ? void 0 : additionalProperty.find(({ name }) => name === 'flgMvtkUse')) === null || _a === void 0 ? void 0 : _a.value) === '1'; })
250
+ .map(({ codeValue }) => codeValue));
251
+ }
252
+ if (params.filmFromCOA.flgMgtkUse === '0') {
253
+ if (!Array.isArray(unacceptedPaymentMethod)) {
254
+ unacceptedPaymentMethod = [];
255
+ }
256
+ // flgMgtkUseで決済方法区分から動的に
257
+ unacceptedPaymentMethod.push(...params.availablePaymentMethodTypes.filter(({ additionalProperty }) => { var _a; return ((_a = additionalProperty === null || additionalProperty === void 0 ? void 0 : additionalProperty.find(({ name }) => name === 'flgMgtkUse')) === null || _a === void 0 ? void 0 : _a.value) === '1'; })
258
+ .map(({ codeValue }) => codeValue));
259
+ }
260
+ if (Array.isArray(unacceptedPaymentMethod)) {
261
+ // 重複排除
262
+ unacceptedPaymentMethod = [...new Set(unacceptedPaymentMethod)];
263
+ }
264
+ return { unacceptedPaymentMethod };
265
+ }
266
+ /**
267
+ * COA情報からイベント識別子を作成する
268
+ */
269
+ // tslint:disable-next-line:no-single-line-block-comment
270
+ /* istanbul ignore next */
271
+ function createScreeningEventSeriesId(params) {
272
+ return [
273
+ params.theaterCode,
274
+ params.titleCode,
275
+ params.titleBranchNum
276
+ ].join('');
277
+ }