@chevre/domain 21.20.0-alpha.44 → 21.20.0-alpha.46

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.
@@ -503,7 +503,11 @@ function createPotentialActions(params) {
503
503
  }));
504
504
  });
505
505
  reservationPackage = {
506
- reservationFor,
506
+ reservationFor: {
507
+ id: String(reservationFor.id),
508
+ typeOf: reservationFor.typeOf,
509
+ optimized: true
510
+ },
507
511
  reservationNumber: transaction.object.reservationNumber,
508
512
  reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
509
513
  ? params.transaction.object.reservationStatus
@@ -1,9 +1,9 @@
1
+ /**
2
+ * COA予約取引サービス
3
+ */
4
+ import * as COA from '@motionpicture/coa-service';
1
5
  import * as factory from '../../factory';
2
- import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
3
- import type { MongoRepository as OrderRepo } from '../../repo/order';
4
6
  interface IConfirmRepo {
5
- acceptedOffer: AcceptedOfferRepo;
6
- order: OrderRepo;
7
7
  }
8
8
  type IConfirmOperation<T> = (repos: IConfirmRepo) => Promise<T>;
9
9
  /**
@@ -15,5 +15,5 @@ declare function confirm(params: {
15
15
  };
16
16
  object: factory.action.interact.confirm.reservation.IObject4COA;
17
17
  purpose: factory.action.interact.confirm.reservation.IPurpose;
18
- }): IConfirmOperation<void>;
18
+ }): IConfirmOperation<COA.factory.reserve.IUpdReserveResult | undefined>;
19
19
  export { confirm };
@@ -14,90 +14,16 @@ exports.confirm = void 0;
14
14
  * COA予約取引サービス
15
15
  */
16
16
  const COA = require("@motionpicture/coa-service");
17
- const createDebug = require("debug");
18
- const google_libphonenumber_1 = require("google-libphonenumber");
19
- const util_1 = require("util");
20
17
  const credentials_1 = require("../../credentials");
21
- const factory = require("../../factory");
22
- const debug = createDebug('chevre-domain:service:assetTransaction');
23
18
  const coaAuthClient = new COA.auth.RefreshToken({
24
19
  endpoint: credentials_1.credentials.coa.endpoint,
25
20
  refreshToken: credentials_1.credentials.coa.refreshToken
26
21
  });
27
- function createConfirmObject4COAByOrder(params) {
28
- // COA予約のみ
29
- const coaReservationOffers = params.order.acceptedOffers.filter((o) => {
30
- var _a;
31
- return o.itemOffered.typeOf === factory.reservationType.EventReservation
32
- && ((_a = o.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) === factory.service.webAPI.Identifier.COA;
33
- });
34
- const customer = params.order.customer;
35
- // 電話番号のフォーマットを日本人にリーダブルに調整(COAではこのフォーマットで扱うので)
36
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
37
- const phoneNumber = phoneUtil.parse(customer.telephone, 'JP');
38
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
39
- // COAでは数字のみ受け付けるので数字以外を除去
40
- telNum = telNum.replace(/[^\d]/g, '');
41
- const mailAddr = customer.email;
42
- if (mailAddr === undefined) {
43
- throw new factory.errors.Argument('order', 'order.customer.email undefined');
44
- }
45
- const coaReservations = coaReservationOffers
46
- .filter((o) => o.itemOffered.reservationNumber === params.reservationNumber)
47
- .map((o) => {
48
- return o.itemOffered;
49
- });
50
- const coaReservation = coaReservations[0];
51
- const reservationForCOAInfo = coaReservation.reservationFor.coaInfo;
52
- if (reservationForCOAInfo === undefined) {
53
- throw new factory.errors.NotFound('reservationFor.coaInfo');
54
- }
55
- const totalPrice = coaReservation.reservedTicket.coaReserveAmount;
56
- if (totalPrice === undefined) {
57
- throw new factory.errors.NotFound('reservedTicket.coaReserveAmount');
58
- }
59
- const listTicket = coaReservations.map((r) => {
60
- var _a;
61
- if (typeof ((_a = r.reservedTicket.coaTicketInfo) === null || _a === void 0 ? void 0 : _a.ticketCode) !== 'string') {
62
- throw new factory.errors.NotFound('reservedTicket.coaTicketInfo');
63
- }
64
- // 冗長な属性を排除(2023-03-20~)
65
- const { ticketCode, stdPrice, addPrice, spseatAdd1, spseatAdd2, disPrice, salePrice, mvtkAppPrice, ticketCount, spseatKbn, seatNum, addGlasses, kbnEisyahousiki, mvtkNum, mvtkKbnDenshiken, mvtkKbnMaeuriken, mvtkKbnKensyu, mvtkSalesPrice, kbnMgtk } = r.reservedTicket.coaTicketInfo;
66
- return {
67
- ticketCode, stdPrice, addPrice, spseatAdd1, spseatAdd2,
68
- disPrice, salePrice, mvtkAppPrice, ticketCount, spseatKbn,
69
- seatNum, addGlasses, kbnEisyahousiki, mvtkNum, mvtkKbnDenshiken,
70
- mvtkKbnMaeuriken, mvtkKbnKensyu, mvtkSalesPrice, kbnMgtk
71
- };
72
- });
73
- return {
74
- theaterCode: reservationForCOAInfo.theaterCode,
75
- dateJouei: reservationForCOAInfo.dateJouei,
76
- titleCode: reservationForCOAInfo.titleCode,
77
- titleBranchNum: reservationForCOAInfo.titleBranchNum,
78
- timeBegin: reservationForCOAInfo.timeBegin,
79
- tmpReserveNum: params.reservationNumber,
80
- // tslint:disable-next-line:no-irregular-whitespace
81
- reserveName: (0, util_1.format)('%s %s', customer.familyName, customer.givenName),
82
- // tslint:disable-next-line:no-irregular-whitespace
83
- reserveNameJkana: (0, util_1.format)('%s %s', customer.familyName, customer.givenName),
84
- telNum: telNum,
85
- mailAddr: mailAddr,
86
- reserveAmount: totalPrice,
87
- listTicket
88
- // transactionNumber: reservationNumber,
89
- // typeOf: 'COAReserveTransaction'
90
- };
91
- }
92
22
  /**
93
23
  * 取引確定
94
24
  */
95
25
  function confirm(params) {
96
- return (repos) => __awaiter(this, void 0, void 0, function* () {
97
- // ここでIObject4COAを注文から生成する(2024-01-24~)
98
- const order = yield fixOrderAsPurpose(params)(repos);
99
- const updReserveArgs = createConfirmObject4COAByOrder({ order, reservationNumber: params.object.transactionNumber });
100
- debug('confirming coa reserve transaction...', order, updReserveArgs);
26
+ return (__) => __awaiter(this, void 0, void 0, function* () {
101
27
  // 未本予約であれば実行(COA本予約は一度成功すると成功できない)
102
28
  // リトライ可能な前提でつくる必要があるので、要注意
103
29
  // すでに本予約済みかどうか確認
@@ -111,30 +37,9 @@ function confirm(params) {
111
37
  telNum: params.object.telNum
112
38
  });
113
39
  if (stateReserveResult === null) {
114
- yield reserveService.updReserve(params.object);
40
+ return reserveService.updReserve(params.object);
115
41
  }
42
+ return;
116
43
  });
117
44
  }
118
45
  exports.confirm = confirm;
119
- function fixOrderAsPurpose(params) {
120
- return (repos) => __awaiter(this, void 0, void 0, function* () {
121
- let order;
122
- const purposeOrderNumber = params.purpose.orderNumber;
123
- const orders = yield repos.order.search({
124
- limit: 1,
125
- page: 1,
126
- project: { id: { $eq: params.project.id } },
127
- // confirmationNumbers: [payPurposeConfirmationNumber],
128
- orderNumbers: [purposeOrderNumber]
129
- }, { customer: 1, orderNumber: 1, typeOf: 1 });
130
- order = orders.shift();
131
- if (order === undefined) {
132
- throw new factory.errors.NotFound('Order as purpose');
133
- }
134
- const acceptedOffers = yield repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
135
- orderNumber: { $eq: order.orderNumber },
136
- project: { id: { $eq: params.project.id } }
137
- }, ['itemOffered', 'offeredThrough']);
138
- return Object.assign(Object.assign({}, order), { acceptedOffers });
139
- });
140
- }
@@ -14,7 +14,7 @@ declare function createConfirmReservationActionObject4COAByOrder(params: {
14
14
  order: factory.order.IOrder & {
15
15
  acceptedOffers: IAcceptedOffer[];
16
16
  };
17
- }): factory.action.interact.confirm.reservation.IObject<factory.service.webAPI.Identifier.COA>[];
17
+ }): factory.task.confirmReserveTransaction.IObject4COAOptimized[];
18
18
  declare function createConfirmRegisterServiceActionObjectByOrder(params: {
19
19
  order: factory.order.IOrder & {
20
20
  acceptedOffers: factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
@@ -100,7 +100,11 @@ function reserveIfNotYet(params) {
100
100
  reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
101
101
  ? reserveTransaction.object.reservationStatus
102
102
  : factory.reservationStatusType.ReservationPending,
103
- reservationFor: reserveTransaction.object.reservationFor
103
+ reservationFor: {
104
+ id: String(reserveTransaction.object.reservationFor.id),
105
+ typeOf: reserveTransaction.object.reservationFor.typeOf,
106
+ optimized: true
107
+ } // optimize(2024-01-24~)
104
108
  },
105
109
  agent: reserveTransaction.project,
106
110
  purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
@@ -120,7 +120,11 @@ function reserveIfNotYet(params) {
120
120
  reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
121
121
  ? reserveTransaction.object.reservationStatus
122
122
  : factory.reservationStatusType.ReservationPending,
123
- reservationFor: reserveTransaction.object.reservationFor
123
+ reservationFor: {
124
+ id: String(reserveTransaction.object.reservationFor.id),
125
+ typeOf: reserveTransaction.object.reservationFor.typeOf,
126
+ optimized: true
127
+ } // optimize(2024-01-24~)
124
128
  },
125
129
  agent: reserveTransaction.project,
126
130
  purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
@@ -13,7 +13,7 @@ export declare function call(data: factory.task.IData<factory.taskName.ConfirmRe
13
13
  /**
14
14
  * 予約を確定する
15
15
  */
16
- export declare function confirmReserveTransaction(params: factory.action.interact.confirm.reservation.IAttributes<factory.service.webAPI.Identifier>, options: {
16
+ export declare function confirmReserveTransaction(params: factory.task.IData<factory.taskName.ConfirmReserveTransaction>, options: {
17
17
  sendOrder: boolean;
18
18
  useOnOrderStatusChanged: boolean;
19
19
  }): (repos: {
@@ -10,6 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.confirmReserveTransaction = exports.call = void 0;
13
+ const createDebug = require("debug");
14
+ const google_libphonenumber_1 = require("google-libphonenumber");
15
+ const util_1 = require("util");
13
16
  const factory = require("../../factory");
14
17
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
15
18
  const action_1 = require("../../repo/action");
@@ -19,6 +22,7 @@ const reservation_1 = require("../../repo/reservation");
19
22
  const task_1 = require("../../repo/task");
20
23
  const ReserveTransactionService = require("../assetTransaction/reserve");
21
24
  const COAReserveService = require("../assetTransaction/reserveCOA");
25
+ const debug = createDebug('chevre-domain:service:task');
22
26
  /**
23
27
  * タスク実行関数
24
28
  */
@@ -38,29 +42,132 @@ function call(data) {
38
42
  });
39
43
  }
40
44
  exports.call = call;
45
+ function createConfirmObject4COAByOrder(params) {
46
+ // COA予約のみ
47
+ const coaReservationOffers = params.order.acceptedOffers.filter((o) => {
48
+ var _a;
49
+ return o.itemOffered.typeOf === factory.reservationType.EventReservation
50
+ && ((_a = o.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) === factory.service.webAPI.Identifier.COA;
51
+ });
52
+ const customer = params.order.customer;
53
+ // 電話番号のフォーマットを日本人にリーダブルに調整(COAではこのフォーマットで扱うので)
54
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
55
+ const phoneNumber = phoneUtil.parse(customer.telephone, 'JP');
56
+ let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
57
+ // COAでは数字のみ受け付けるので数字以外を除去
58
+ telNum = telNum.replace(/[^\d]/g, '');
59
+ const mailAddr = customer.email;
60
+ if (mailAddr === undefined) {
61
+ throw new factory.errors.Argument('order', 'order.customer.email undefined');
62
+ }
63
+ const coaReservations = coaReservationOffers
64
+ .filter((o) => o.itemOffered.reservationNumber === params.reservationNumber)
65
+ .map((o) => {
66
+ return o.itemOffered;
67
+ });
68
+ const coaReservation = coaReservations[0];
69
+ const reservationForCOAInfo = coaReservation.reservationFor.coaInfo;
70
+ if (reservationForCOAInfo === undefined) {
71
+ throw new factory.errors.NotFound('reservationFor.coaInfo');
72
+ }
73
+ const totalPrice = coaReservation.reservedTicket.coaReserveAmount;
74
+ if (totalPrice === undefined) {
75
+ throw new factory.errors.NotFound('reservedTicket.coaReserveAmount');
76
+ }
77
+ const listTicket = coaReservations.map((r) => {
78
+ var _a;
79
+ if (typeof ((_a = r.reservedTicket.coaTicketInfo) === null || _a === void 0 ? void 0 : _a.ticketCode) !== 'string') {
80
+ throw new factory.errors.NotFound('reservedTicket.coaTicketInfo');
81
+ }
82
+ // 冗長な属性を排除(2023-03-20~)
83
+ const { ticketCode, stdPrice, addPrice, spseatAdd1, spseatAdd2, disPrice, salePrice, mvtkAppPrice, ticketCount, spseatKbn, seatNum, addGlasses, kbnEisyahousiki, mvtkNum, mvtkKbnDenshiken, mvtkKbnMaeuriken, mvtkKbnKensyu, mvtkSalesPrice, kbnMgtk } = r.reservedTicket.coaTicketInfo;
84
+ return {
85
+ ticketCode, stdPrice, addPrice, spseatAdd1, spseatAdd2,
86
+ disPrice, salePrice, mvtkAppPrice, ticketCount, spseatKbn,
87
+ seatNum, addGlasses, kbnEisyahousiki, mvtkNum, mvtkKbnDenshiken,
88
+ mvtkKbnMaeuriken, mvtkKbnKensyu, mvtkSalesPrice, kbnMgtk
89
+ };
90
+ });
91
+ return {
92
+ theaterCode: reservationForCOAInfo.theaterCode,
93
+ dateJouei: reservationForCOAInfo.dateJouei,
94
+ titleCode: reservationForCOAInfo.titleCode,
95
+ titleBranchNum: reservationForCOAInfo.titleBranchNum,
96
+ timeBegin: reservationForCOAInfo.timeBegin,
97
+ tmpReserveNum: params.reservationNumber,
98
+ // tslint:disable-next-line:no-irregular-whitespace
99
+ reserveName: (0, util_1.format)('%s %s', customer.familyName, customer.givenName),
100
+ // tslint:disable-next-line:no-irregular-whitespace
101
+ reserveNameJkana: (0, util_1.format)('%s %s', customer.familyName, customer.givenName),
102
+ telNum: telNum,
103
+ mailAddr: mailAddr,
104
+ reserveAmount: totalPrice,
105
+ listTicket
106
+ // transactionNumber: reservationNumber,
107
+ // typeOf: 'COAReserveTransaction'
108
+ };
109
+ }
110
+ function fixOrderAsPurpose(params) {
111
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
112
+ let order;
113
+ const purposeOrderNumber = params.purpose.orderNumber;
114
+ const orders = yield repos.order.search({
115
+ limit: 1,
116
+ page: 1,
117
+ project: { id: { $eq: params.project.id } },
118
+ // confirmationNumbers: [payPurposeConfirmationNumber],
119
+ orderNumbers: [purposeOrderNumber]
120
+ }, { customer: 1, orderNumber: 1, typeOf: 1 });
121
+ order = orders.shift();
122
+ if (order === undefined) {
123
+ throw new factory.errors.NotFound('Order as purpose');
124
+ }
125
+ const acceptedOffers = yield repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
126
+ orderNumber: { $eq: order.orderNumber },
127
+ project: { id: { $eq: params.project.id } }
128
+ }, ['itemOffered', 'offeredThrough']);
129
+ return Object.assign(Object.assign({}, order), { acceptedOffers });
130
+ });
131
+ }
41
132
  /**
42
133
  * 予約を確定する
43
134
  */
44
135
  function confirmReserveTransaction(params, options) {
45
136
  return (repos) => __awaiter(this, void 0, void 0, function* () {
137
+ let confirmActionObject;
138
+ switch (params.instrument.identifier) {
139
+ case factory.service.webAPI.Identifier.COA:
140
+ // 最適化されたタスクに対応するため、ここでIObject4COAを注文から生成する(2024-01-24~)
141
+ const order = yield fixOrderAsPurpose({
142
+ project: { id: params.project.id },
143
+ purpose: params.purpose
144
+ })(repos);
145
+ const updReserveArgs = createConfirmObject4COAByOrder({ order, reservationNumber: params.object.transactionNumber });
146
+ debug('confirming coa reserve transaction...', order, updReserveArgs);
147
+ // updReserveArgsで上書き
148
+ confirmActionObject = Object.assign(Object.assign({}, updReserveArgs), { transactionNumber: params.object.transactionNumber, typeOf: params.object.typeOf });
149
+ debug('confirmActionObject === params.object?', JSON.stringify(confirmActionObject) === JSON.stringify(params.object));
150
+ break;
151
+ default:
152
+ confirmActionObject = params.object;
153
+ }
46
154
  // アクション開始
47
- const confirmActionAttributes = params;
155
+ const confirmActionAttributes = Object.assign(Object.assign({}, params), { object: confirmActionObject });
48
156
  const action = yield repos.action.start(confirmActionAttributes);
157
+ let updReserveResult;
49
158
  try {
50
- let object = confirmActionAttributes.object;
159
+ const object = confirmActionAttributes.object;
51
160
  switch (params.instrument.identifier) {
52
161
  case factory.service.webAPI.Identifier.COA:
53
162
  // COA本予約
54
- object = object;
55
- yield COAReserveService.confirm({
163
+ updReserveResult = yield COAReserveService.confirm({
56
164
  project: { id: confirmActionAttributes.project.id },
57
- object,
165
+ object: object,
58
166
  purpose: confirmActionAttributes.purpose
59
- })(repos);
167
+ })({});
60
168
  break;
61
169
  default:
62
170
  // 予約取引確定
63
- object = object;
64
171
  yield ReserveTransactionService.confirm({
65
172
  transactionNumber: object.transactionNumber,
66
173
  potentialActions: object.potentialActions
@@ -77,10 +184,10 @@ function confirmReserveTransaction(params, options) {
77
184
  throw error;
78
185
  }
79
186
  // アクション完了
80
- const result = {};
187
+ const result = { updReserveResult };
81
188
  yield repos.action.completeWithVoid({ typeOf: confirmActionAttributes.typeOf, id: action.id, result: result });
82
189
  // sendOrder連携(2024-01-11~)
83
- yield onConfirmed(params, options)({
190
+ yield onConfirmed(confirmActionAttributes, options)({
84
191
  task: repos.task
85
192
  });
86
193
  });
package/package.json CHANGED
@@ -10,9 +10,9 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.352.0-alpha.4",
13
+ "@chevre/factory": "4.352.0-alpha.6",
14
14
  "@cinerino/sdk": "5.9.0-alpha.1",
15
- "@motionpicture/coa-service": "9.3.0-alpha.0",
15
+ "@motionpicture/coa-service": "9.3.0-alpha.1",
16
16
  "@motionpicture/gmo-service": "5.3.0-alpha.0",
17
17
  "@sendgrid/mail": "6.4.0",
18
18
  "@surfrock/sdk": "1.2.0",
@@ -112,5 +112,5 @@
112
112
  "postversion": "git push origin --tags",
113
113
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
114
  },
115
- "version": "21.20.0-alpha.44"
115
+ "version": "21.20.0-alpha.46"
116
116
  }