@chevre/domain 21.18.0-alpha.7 → 21.18.0-alpha.8

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 (28) hide show
  1. package/example/src/chevre/searchAcceptedOfferIds.ts +18 -0
  2. package/lib/chevre/repo/acceptedOffer.d.ts +1 -1
  3. package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +3 -1
  4. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +1 -1
  5. package/lib/chevre/service/assetTransaction/pay.d.ts +2 -0
  6. package/lib/chevre/service/assetTransaction/pay.js +8 -5
  7. package/lib/chevre/service/order/confirmPayTransaction.d.ts +2 -0
  8. package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
  9. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +1 -2
  10. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -12
  11. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +1 -108
  12. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +11 -0
  13. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +54 -0
  14. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +12 -0
  15. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +39 -0
  16. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +9 -0
  17. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +110 -0
  18. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.d.ts +12 -0
  19. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +164 -0
  20. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +7 -5
  21. package/lib/chevre/service/order/onOrderStatusChanged.js +8 -133
  22. package/lib/chevre/service/order/placeOrder.js +3 -1
  23. package/lib/chevre/service/order/returnOrder.d.ts +2 -2
  24. package/lib/chevre/service/order/returnOrder.js +6 -6
  25. package/lib/chevre/service/order/sendOrder.js +4 -3
  26. package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
  27. package/lib/chevre/service/task/returnOrder.js +10 -17
  28. package/package.json +1 -1
@@ -32,6 +32,24 @@ async function main() {
32
32
  'acceptedOffers.itemOffered.issuedThrough.id'
33
33
  );
34
34
  console.log(productIds);
35
+
36
+ const locationBranchCodes = await acceptedOfferRepo.distinctValues(
37
+ { orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
38
+ 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode'
39
+ );
40
+ console.log(locationBranchCodes);
41
+
42
+ const offeredThroughIdentifiers = await acceptedOfferRepo.distinctValues(
43
+ { orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
44
+ 'acceptedOffers.offeredThrough.identifier'
45
+ );
46
+ console.log(offeredThroughIdentifiers);
47
+
48
+ const invalidValues = await acceptedOfferRepo.distinctValues(
49
+ { orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
50
+ <any>'invalidValues'
51
+ );
52
+ console.log(invalidValues);
35
53
  }
36
54
 
37
55
  main()
@@ -5,7 +5,7 @@ type IProjection4searchWithUnwoundAcceptedOffers = {
5
5
  } & {
6
6
  _id?: 0 | 1;
7
7
  };
8
- type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id';
8
+ type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id' | 'acceptedOffers.offeredThrough.identifier' | 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode';
9
9
  /**
10
10
  * 注文オファーリポジトリ
11
11
  */
@@ -6,5 +6,7 @@ export type IUnitPriceSpecification = factory.unitPriceOffer.IUnitPriceOfferPric
6
6
  export declare function createPotentialActions(params: {
7
7
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Pay>;
8
8
  potentialActions?: factory.assetTransaction.pay.IPotentialActionsParams;
9
- order: factory.order.IOrder;
9
+ order: factory.order.IOrder & {
10
+ acceptedOffers: factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
11
+ };
10
12
  }): factory.assetTransaction.IPotentialActions<factory.assetTransactionType.Pay>;
@@ -219,7 +219,7 @@ function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType)
219
219
  let reservationNumber = '';
220
220
  let priceComponents4invoice = [];
221
221
  // Orderから対象予約を取得
222
- const reservationOffer = (_a = order === null || order === void 0 ? void 0 : order.acceptedOffers) === null || _a === void 0 ? void 0 : _a.find((o) => {
222
+ const reservationOffer = (_a = order.acceptedOffers) === null || _a === void 0 ? void 0 : _a.find((o) => {
223
223
  var _a, _b, _c, _d;
224
224
  let mvtkUnitPriceSpec;
225
225
  // MovieTicket適用単価オファーからidentifierを取り出す
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import * as GMO from '@motionpicture/gmo-service';
5
5
  import * as factory from '../../factory';
6
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
6
7
  import type { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
7
8
  import type { MongoRepository as ActionRepo } from '../../repo/action';
8
9
  import type { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
@@ -38,6 +39,7 @@ export interface ICancelRepos {
38
39
  }
39
40
  export type ICancelOperation<T> = (repos: ICancelRepos) => Promise<T>;
40
41
  export interface IConfirmRepos {
42
+ acceptedOffer: AcceptedOfferRepo;
41
43
  action: ActionRepo;
42
44
  accountingReport: AccountingReportRepo;
43
45
  assetTransaction: AssetTransactionRepo;
@@ -365,25 +365,28 @@ exports.confirm = confirm;
365
365
  function fixOrderAsPurpose(params, transaction) {
366
366
  return (repos) => __awaiter(this, void 0, void 0, function* () {
367
367
  var _a, _b, _c, _d, _e, _f;
368
- let order;
369
368
  const payPurposeConfirmationNumber = (_c = (_b = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.pay) === null || _b === void 0 ? void 0 : _b.purpose) === null || _c === void 0 ? void 0 : _c.confirmationNumber;
370
369
  const payPurposeOrderNumber = (_f = (_e = (_d = params.potentialActions) === null || _d === void 0 ? void 0 : _d.pay) === null || _e === void 0 ? void 0 : _e.purpose) === null || _f === void 0 ? void 0 : _f.orderNumber;
371
370
  if (typeof payPurposeConfirmationNumber !== 'string' || payPurposeConfirmationNumber.length === 0
372
371
  || typeof payPurposeOrderNumber !== 'string' || payPurposeOrderNumber.length === 0) {
373
372
  throw new factory.errors.ArgumentNull('potentialActions.pay.purpose');
374
373
  }
375
- const orders = yield repos.order.search({
374
+ const ordersWithoutAcceptedOffers = yield repos.order.search({
376
375
  limit: 1,
377
376
  page: 1,
378
377
  project: { id: { $eq: transaction.project.id } },
379
378
  confirmationNumbers: [payPurposeConfirmationNumber],
380
379
  orderNumbers: [payPurposeOrderNumber]
381
380
  });
382
- order = orders.shift();
383
- if (order === undefined) {
381
+ const orderWithoutAcceptedOffers = ordersWithoutAcceptedOffers.shift();
382
+ if (orderWithoutAcceptedOffers === undefined) {
384
383
  throw new factory.errors.NotFound('Order as purpose');
385
384
  }
386
- return order;
385
+ // 全acceptedOffersを検索(2023-12-06~)
386
+ const acceptedOffers = yield repos.acceptedOffer.searchAcceptedOffers({
387
+ orderNumbers: [orderWithoutAcceptedOffers.orderNumber]
388
+ });
389
+ return Object.assign(Object.assign({}, orderWithoutAcceptedOffers), { acceptedOffers });
387
390
  });
388
391
  }
389
392
  /**
@@ -1,4 +1,5 @@
1
1
  import * as factory from '../../factory';
2
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
2
3
  import type { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
3
4
  import type { MongoRepository as ActionRepo } from '../../repo/action';
4
5
  import type { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
@@ -9,6 +10,7 @@ import type { MongoRepository as ProjectRepo } from '../../repo/project';
9
10
  import type { MongoRepository as TaskRepo } from '../../repo/task';
10
11
  import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
11
12
  declare function confirmPayTransaction(data: factory.task.IData<factory.taskName.ConfirmPayTransaction>): (repos: {
13
+ acceptedOffer: AcceptedOfferRepo;
12
14
  action: ActionRepo;
13
15
  assetTransaction: AssetTransactionRepo;
14
16
  order: OrderRepo;
@@ -30,6 +30,7 @@ function confirmPayTransaction(data) {
30
30
  } }, (typeof ((_b = (_a = confirmingTransaction.object) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
31
31
  ? { object: { paymentMethod: { identifier: confirmingTransaction.object.paymentMethod.identifier } } }
32
32
  : undefined))({
33
+ acceptedOffer: repos.acceptedOffer,
33
34
  action: repos.action,
34
35
  accountingReport: repos.accountingReport,
35
36
  assetTransaction: repos.assetTransaction,
@@ -212,12 +212,11 @@ function cancelOrderIfExist(params) {
212
212
  throw error;
213
213
  }
214
214
  if (params.useOnOrderStatusChanged) {
215
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
215
+ yield (0, onOrderStatusChanged_1.onOrderCancelled)({
216
216
  order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderCancelled // 強制的にOrderCancelledとして処理する
217
217
  }),
218
218
  placeOrderTransaction
219
219
  })({
220
- registerActionInProgress: repos.registerActionInProgress,
221
220
  task: repos.task
222
221
  });
223
222
  }
@@ -27,16 +27,4 @@ export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | '
27
27
  export declare function createOnOrderSentTasksByTransaction(params: {
28
28
  potentialActions?: factory.action.transfer.send.order.IPotentialActions;
29
29
  }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
30
- /**
31
- * 注文返品後のアクション
32
- */
33
- export declare function createOnOrderReturnedTasksByTransaction(params: {
34
- potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
35
- }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
36
- /**
37
- * 注文中止時のアクション
38
- */
39
- export declare function createOnOrderCancelledTasksByTransaction(params: {
40
- transaction?: factory.transaction.placeOrder.ITransaction;
41
- }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
42
30
  export {};
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  var _a;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderSentTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
14
14
  const google_libphonenumber_1 = require("google-libphonenumber");
15
15
  const jwt = require("jsonwebtoken");
16
16
  const util_1 = require("util");
@@ -358,110 +358,3 @@ function createOnOrderSentTasksByTransaction(params) {
358
358
  return taskAttributes;
359
359
  }
360
360
  exports.createOnOrderSentTasksByTransaction = createOnOrderSentTasksByTransaction;
361
- /**
362
- * 注文返品後のアクション
363
- */
364
- function createOnOrderReturnedTasksByTransaction(params) {
365
- const now = new Date();
366
- const taskAttributes = [];
367
- const potentialActions = params.potentialActions;
368
- // 入金返却タスク
369
- const returnMoneyTransferAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnMoneyTransfer;
370
- if (Array.isArray(returnMoneyTransferAttributes)) {
371
- taskAttributes.push(...returnMoneyTransferAttributes.map((a) => {
372
- return {
373
- project: a.project,
374
- name: factory.taskName.ReturnMoneyTransfer,
375
- status: factory.taskStatus.Ready,
376
- runsAt: now,
377
- remainingNumberOfTries: 10,
378
- numberOfTried: 0,
379
- executionResults: [],
380
- data: a
381
- };
382
- }));
383
- }
384
- // ポイント特典返却タスク
385
- const returnPointAwardAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnPointAward;
386
- if (Array.isArray(returnPointAwardAttributes)) {
387
- taskAttributes.push(...returnPointAwardAttributes.map((a) => {
388
- return {
389
- project: a.project,
390
- name: factory.taskName.ReturnPointAward,
391
- status: factory.taskStatus.Ready,
392
- runsAt: now,
393
- remainingNumberOfTries: 10,
394
- numberOfTried: 0,
395
- executionResults: [],
396
- data: a
397
- };
398
- }));
399
- }
400
- const sendEmailMessageAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.sendEmailMessage;
401
- if (Array.isArray(sendEmailMessageAttributes)) {
402
- sendEmailMessageAttributes.forEach((s) => {
403
- const sendEmailMessageTask = {
404
- project: s.project,
405
- name: factory.taskName.SendEmailMessage,
406
- status: factory.taskStatus.Ready,
407
- runsAt: now,
408
- remainingNumberOfTries: 3,
409
- numberOfTried: 0,
410
- executionResults: [],
411
- data: {
412
- actionAttributes: s
413
- }
414
- };
415
- taskAttributes.push(sendEmailMessageTask);
416
- });
417
- }
418
- return taskAttributes;
419
- }
420
- exports.createOnOrderReturnedTasksByTransaction = createOnOrderReturnedTasksByTransaction;
421
- /**
422
- * 注文中止時のアクション
423
- */
424
- function createOnOrderCancelledTasksByTransaction(params) {
425
- var _a;
426
- const now = new Date();
427
- const taskAttributes = [];
428
- if (typeof ((_a = params.transaction) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
429
- const voidPaymentTaskAttributes = {
430
- project: params.transaction.project,
431
- name: factory.taskName.VoidPayTransaction,
432
- status: factory.taskStatus.Ready,
433
- runsAt: now,
434
- remainingNumberOfTries: 10,
435
- numberOfTried: 0,
436
- executionResults: [],
437
- data: {
438
- project: params.transaction.project,
439
- purpose: {
440
- typeOf: params.transaction.typeOf,
441
- id: params.transaction.id,
442
- result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
443
- }
444
- }
445
- };
446
- const voidReserveTaskAttributes = {
447
- project: params.transaction.project,
448
- name: factory.taskName.VoidReserveTransaction,
449
- status: factory.taskStatus.Ready,
450
- runsAt: now,
451
- remainingNumberOfTries: 10,
452
- numberOfTried: 0,
453
- executionResults: [],
454
- data: {
455
- project: params.transaction.project,
456
- purpose: {
457
- typeOf: params.transaction.typeOf,
458
- id: params.transaction.id,
459
- result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
460
- }
461
- }
462
- };
463
- taskAttributes.push(voidPaymentTaskAttributes, voidReserveTaskAttributes);
464
- }
465
- return taskAttributes;
466
- }
467
- exports.createOnOrderCancelledTasksByTransaction = createOnOrderCancelledTasksByTransaction;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 注文ステータス変更時処理
3
+ */
4
+ import * as factory from '../../../../factory';
5
+ /**
6
+ * 注文中止時のアクション
7
+ */
8
+ declare function createOnOrderCancelledTasksByTransaction(params: {
9
+ transaction?: factory.transaction.placeOrder.ITransaction;
10
+ }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
11
+ export { createOnOrderCancelledTasksByTransaction };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOnOrderCancelledTasksByTransaction = void 0;
4
+ /**
5
+ * 注文ステータス変更時処理
6
+ */
7
+ const factory = require("../../../../factory");
8
+ /**
9
+ * 注文中止時のアクション
10
+ */
11
+ function createOnOrderCancelledTasksByTransaction(params) {
12
+ var _a;
13
+ const now = new Date();
14
+ const taskAttributes = [];
15
+ if (typeof ((_a = params.transaction) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
16
+ const voidPaymentTaskAttributes = {
17
+ project: params.transaction.project,
18
+ name: factory.taskName.VoidPayTransaction,
19
+ status: factory.taskStatus.Ready,
20
+ runsAt: now,
21
+ remainingNumberOfTries: 10,
22
+ numberOfTried: 0,
23
+ executionResults: [],
24
+ data: {
25
+ project: params.transaction.project,
26
+ purpose: {
27
+ typeOf: params.transaction.typeOf,
28
+ id: params.transaction.id,
29
+ result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
30
+ }
31
+ }
32
+ };
33
+ const voidReserveTaskAttributes = {
34
+ project: params.transaction.project,
35
+ name: factory.taskName.VoidReserveTransaction,
36
+ status: factory.taskStatus.Ready,
37
+ runsAt: now,
38
+ remainingNumberOfTries: 10,
39
+ numberOfTried: 0,
40
+ executionResults: [],
41
+ data: {
42
+ project: params.transaction.project,
43
+ purpose: {
44
+ typeOf: params.transaction.typeOf,
45
+ id: params.transaction.id,
46
+ result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
47
+ }
48
+ }
49
+ };
50
+ taskAttributes.push(voidPaymentTaskAttributes, voidReserveTaskAttributes);
51
+ }
52
+ return taskAttributes;
53
+ }
54
+ exports.createOnOrderCancelledTasksByTransaction = createOnOrderCancelledTasksByTransaction;
@@ -0,0 +1,12 @@
1
+ import type { MongoRepository as TaskRepo } from '../../../repo/task';
2
+ import * as factory from '../../../factory';
3
+ type IPlaceOrderTransaction = factory.transaction.ITransaction<factory.transactionType.PlaceOrder>;
4
+ type IReturnOrderTransaction = factory.transaction.ITransaction<factory.transactionType.ReturnOrder>;
5
+ declare function onOrderCancelled(params: {
6
+ order: factory.order.IOrder;
7
+ placeOrderTransaction?: IPlaceOrderTransaction;
8
+ returnOrderTransaction?: IReturnOrderTransaction;
9
+ }): (repos: {
10
+ task: TaskRepo;
11
+ }) => Promise<void>;
12
+ export { onOrderCancelled };
@@ -0,0 +1,39 @@
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.onOrderCancelled = void 0;
13
+ /**
14
+ * 注文中止時処理
15
+ */
16
+ const createDebug = require("debug");
17
+ const factory = require("../../../factory");
18
+ const factory_1 = require("./onOrderCancelled/factory");
19
+ const debug = createDebug('chevre-domain:service:order');
20
+ function onOrderCancelled(params) {
21
+ // tslint:disable-next-line:max-func-body-length
22
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
23
+ debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
24
+ let tasks = [];
25
+ switch (params.order.orderStatus) {
26
+ // OrderCancelled追加(2023-08-30~)
27
+ case factory.orderStatus.OrderCancelled:
28
+ // 注文取引中止時と同様の処理か
29
+ tasks = [
30
+ ...(0, factory_1.createOnOrderCancelledTasksByTransaction)({ transaction: params.placeOrderTransaction })
31
+ ];
32
+ break;
33
+ default:
34
+ throw new factory.errors.NotImplemented(`${params.order.orderStatus} not implemented`);
35
+ }
36
+ yield repos.task.saveMany(tasks, { emitImmediately: true });
37
+ });
38
+ }
39
+ exports.onOrderCancelled = onOrderCancelled;
@@ -0,0 +1,9 @@
1
+ import * as factory from '../../../../factory';
2
+ declare function createInformTasks(order: Pick<factory.order.IOrder, 'project' | 'typeOf' | 'orderNumber' | 'dateReturned' | 'id' | 'customer' | 'returner'>): factory.task.IAttributes<factory.taskName.TriggerWebhook>[];
3
+ /**
4
+ * 注文返品後のアクション
5
+ */
6
+ declare function createOnOrderReturnedTasksByTransaction(params: {
7
+ potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
8
+ }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
9
+ export { createInformTasks, createOnOrderReturnedTasksByTransaction };
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createOnOrderReturnedTasksByTransaction = exports.createInformTasks = void 0;
5
+ const factory = require("../../../../factory");
6
+ const settings_1 = require("../../../../settings");
7
+ const informOrder = (_a = settings_1.settings.onOrderStatusChanged) === null || _a === void 0 ? void 0 : _a.informOrder;
8
+ function createInformTasks(order) {
9
+ var _a;
10
+ const taskRunsAt = new Date();
11
+ let informTasks = [];
12
+ if (Array.isArray(informOrder) && informOrder.length > 0) {
13
+ const order4inform = creteOrder4inform(order);
14
+ let recipientId = '';
15
+ recipientId = order.customer.id;
16
+ if (typeof ((_a = order.returner) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
17
+ recipientId = order.returner.id;
18
+ }
19
+ informTasks = informOrder.map((informOrderParams) => {
20
+ var _a, _b;
21
+ const informActionAttributes = {
22
+ agent: order.project,
23
+ object: order4inform,
24
+ project: order.project,
25
+ recipient: {
26
+ url: (_a = informOrderParams.recipient) === null || _a === void 0 ? void 0 : _a.url,
27
+ id: recipientId,
28
+ name: (_b = informOrderParams.recipient) === null || _b === void 0 ? void 0 : _b.name,
29
+ typeOf: factory.creativeWorkType.WebApplication
30
+ },
31
+ typeOf: factory.actionType.InformAction
32
+ };
33
+ return {
34
+ project: order.project,
35
+ name: factory.taskName.TriggerWebhook,
36
+ status: factory.taskStatus.Ready,
37
+ runsAt: taskRunsAt,
38
+ remainingNumberOfTries: 10,
39
+ numberOfTried: 0,
40
+ executionResults: [],
41
+ data: informActionAttributes
42
+ };
43
+ });
44
+ }
45
+ return informTasks;
46
+ }
47
+ exports.createInformTasks = createInformTasks;
48
+ function creteOrder4inform(order) {
49
+ return Object.assign(Object.assign({ project: order.project, typeOf: order.typeOf, orderNumber: order.orderNumber, orderStatus: factory.orderStatus.OrderReturned }, (order.dateReturned !== undefined) ? { dateReturned: order.dateReturned } : undefined), (typeof order.id === 'string') ? { id: order.id } : undefined);
50
+ }
51
+ /**
52
+ * 注文返品後のアクション
53
+ */
54
+ function createOnOrderReturnedTasksByTransaction(params) {
55
+ const now = new Date();
56
+ const taskAttributes = [];
57
+ const potentialActions = params.potentialActions;
58
+ // 入金返却タスク
59
+ const returnMoneyTransferAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnMoneyTransfer;
60
+ if (Array.isArray(returnMoneyTransferAttributes)) {
61
+ taskAttributes.push(...returnMoneyTransferAttributes.map((a) => {
62
+ return {
63
+ project: a.project,
64
+ name: factory.taskName.ReturnMoneyTransfer,
65
+ status: factory.taskStatus.Ready,
66
+ runsAt: now,
67
+ remainingNumberOfTries: 10,
68
+ numberOfTried: 0,
69
+ executionResults: [],
70
+ data: a
71
+ };
72
+ }));
73
+ }
74
+ // ポイント特典返却タスク
75
+ const returnPointAwardAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.returnPointAward;
76
+ if (Array.isArray(returnPointAwardAttributes)) {
77
+ taskAttributes.push(...returnPointAwardAttributes.map((a) => {
78
+ return {
79
+ project: a.project,
80
+ name: factory.taskName.ReturnPointAward,
81
+ status: factory.taskStatus.Ready,
82
+ runsAt: now,
83
+ remainingNumberOfTries: 10,
84
+ numberOfTried: 0,
85
+ executionResults: [],
86
+ data: a
87
+ };
88
+ }));
89
+ }
90
+ const sendEmailMessageAttributes = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.sendEmailMessage;
91
+ if (Array.isArray(sendEmailMessageAttributes)) {
92
+ sendEmailMessageAttributes.forEach((s) => {
93
+ const sendEmailMessageTask = {
94
+ project: s.project,
95
+ name: factory.taskName.SendEmailMessage,
96
+ status: factory.taskStatus.Ready,
97
+ runsAt: now,
98
+ remainingNumberOfTries: 3,
99
+ numberOfTried: 0,
100
+ executionResults: [],
101
+ data: {
102
+ actionAttributes: s
103
+ }
104
+ };
105
+ taskAttributes.push(sendEmailMessageTask);
106
+ });
107
+ }
108
+ return taskAttributes;
109
+ }
110
+ exports.createOnOrderReturnedTasksByTransaction = createOnOrderReturnedTasksByTransaction;
@@ -0,0 +1,12 @@
1
+ import type { MongoRepository as AcceptedOfferRepo } from '../../../repo/acceptedOffer';
2
+ import type { MongoRepository as TaskRepo } from '../../../repo/task';
3
+ import * as factory from '../../../factory';
4
+ type IReturnOrderTransaction = factory.transaction.ITransaction<factory.transactionType.ReturnOrder>;
5
+ declare function onOrderReturned(params: {
6
+ order: Pick<factory.order.IOrder, 'project' | 'typeOf' | 'orderNumber' | 'dateReturned' | 'id' | 'customer' | 'returner' | 'seller' | 'price' | 'priceCurrency' | 'orderDate' | 'orderStatus'>;
7
+ returnOrderTransaction?: IReturnOrderTransaction;
8
+ }): (repos: {
9
+ acceptedOffer: AcceptedOfferRepo;
10
+ task: TaskRepo;
11
+ }) => Promise<void>;
12
+ export { onOrderReturned };
@@ -0,0 +1,164 @@
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.onOrderReturned = void 0;
13
+ /**
14
+ * 注文返品時処理
15
+ */
16
+ const createDebug = require("debug");
17
+ const google_libphonenumber_1 = require("google-libphonenumber");
18
+ const factory = require("../../../factory");
19
+ const order_1 = require("../../../factory/order");
20
+ const factory_1 = require("./onOrderReturned/factory");
21
+ const debug = createDebug('chevre-domain:service:order');
22
+ function onOrderReturned(params) {
23
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
24
+ var _a, _b, _c, _d;
25
+ debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
26
+ let tasks = [];
27
+ const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
28
+ const simpleOrder = {
29
+ typeOf: params.order.typeOf,
30
+ seller: {
31
+ id: params.order.seller.id,
32
+ typeOf: params.order.seller.typeOf,
33
+ name: params.order.seller.name
34
+ },
35
+ customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id },
36
+ orderNumber: params.order.orderNumber,
37
+ price: params.order.price,
38
+ priceCurrency: params.order.priceCurrency,
39
+ orderDate: params.order.orderDate
40
+ };
41
+ switch (params.order.orderStatus) {
42
+ case factory.orderStatus.OrderReturned:
43
+ const potentialActionsByTransaction = (_d = (_c = (_b = (_a = params.returnOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.returnOrder) === null || _c === void 0 ? void 0 : _c.find((returnOrderActionByTransaction) => {
44
+ return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
45
+ })) === null || _d === void 0 ? void 0 : _d.potentialActions;
46
+ const reservationNumbers = yield repos.acceptedOffer.distinctValues({ orderNumber: { $in: [params.order.orderNumber] } }, 'acceptedOffers.itemOffered.reservationNumber');
47
+ const offeredThroughIdentifier = (yield repos.acceptedOffer.distinctValues({ orderNumber: { $in: [params.order.orderNumber] } }, 'acceptedOffers.itemOffered.reservationNumber'))[0];
48
+ const reservationForSuperEventLocationBranchCodes = yield repos.acceptedOffer.distinctValues({ orderNumber: { $in: [params.order.orderNumber] } }, 'acceptedOffers.itemOffered.reservationNumber');
49
+ tasks = [
50
+ ...(0, factory_1.createInformTasks)(params.order),
51
+ ...createReturnReserveTransactionTasks(Object.assign(Object.assign({}, params.order), { reservationNumbers,
52
+ offeredThroughIdentifier,
53
+ reservationForSuperEventLocationBranchCodes }), simpleOrder),
54
+ // 決済取引返却タスクを作成(2022-06-09~)
55
+ ...createReturnPayTransactionTasks({ orderNumber: params.order.orderNumber }, params.returnOrderTransaction),
56
+ // 取引のpotentialActionsを適用(2023-08-19~)
57
+ ...(0, factory_1.createOnOrderReturnedTasksByTransaction)({ potentialActions: potentialActionsByTransaction })
58
+ ];
59
+ break;
60
+ default:
61
+ throw new factory.errors.NotImplemented(`${params.order.orderStatus} not implemented`);
62
+ }
63
+ yield repos.task.saveMany(tasks, { emitImmediately: true });
64
+ });
65
+ }
66
+ exports.onOrderReturned = onOrderReturned;
67
+ function createReturnReserveTransactionTasks(order, simpleOrder) {
68
+ const taskRunsAt = new Date();
69
+ const taskRunsAt4coa = new Date();
70
+ const tasks = [];
71
+ const returnActionRecipient = {
72
+ typeOf: order.seller.typeOf,
73
+ id: order.seller.id,
74
+ name: order.seller.name
75
+ };
76
+ // 注文アイテムから返却アクションを作成する
77
+ // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
78
+ for (const reservationNumber of order.reservationNumbers) {
79
+ // const reservation = acceptedOffer.itemOffered;
80
+ // 予約番号ごとに返却アクションを作成する
81
+ let returnReserveTransactionAction;
82
+ switch (order.offeredThroughIdentifier) {
83
+ case factory.service.webAPI.Identifier.COA:
84
+ // const superEventLocationBranchCode =
85
+ // (<factory.order.IEventReservation>reservation).reservationFor?.superEvent.location.branchCode;
86
+ // ↓1注文に複数施設はない想定なので、これで問題ない
87
+ const superEventLocationBranchCode = order.reservationForSuperEventLocationBranchCodes[0];
88
+ if (typeof superEventLocationBranchCode !== 'string') {
89
+ throw new factory.errors.ArgumentNull('order.reservationForSuperEventLocationBranchCodes');
90
+ }
91
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
92
+ const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
93
+ let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
94
+ // COAでは数字のみ受け付けるので数字以外を除去
95
+ telNum = telNum.replace(/[^\d]/g, '');
96
+ returnReserveTransactionAction = {
97
+ project: order.project,
98
+ typeOf: factory.actionType.ReturnAction,
99
+ object: {
100
+ theaterCode: superEventLocationBranchCode,
101
+ reserveNum: reservationNumber,
102
+ telNum: telNum,
103
+ typeOf: 'COAReserveTransaction'
104
+ },
105
+ agent: order.project,
106
+ purpose: simpleOrder,
107
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
108
+ recipient: returnActionRecipient
109
+ };
110
+ break;
111
+ default:
112
+ returnReserveTransactionAction = {
113
+ project: order.project,
114
+ typeOf: factory.actionType.ReturnAction,
115
+ object: {
116
+ typeOf: factory.assetTransactionType.Reserve,
117
+ transactionNumber: reservationNumber
118
+ },
119
+ agent: order.project,
120
+ purpose: simpleOrder,
121
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
122
+ recipient: returnActionRecipient
123
+ };
124
+ }
125
+ tasks.push({
126
+ project: order.project,
127
+ name: factory.taskName.ReturnReserveTransaction,
128
+ status: factory.taskStatus.Ready,
129
+ runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
130
+ ? taskRunsAt4coa
131
+ : taskRunsAt,
132
+ remainingNumberOfTries: 10,
133
+ numberOfTried: 0,
134
+ executionResults: [],
135
+ data: returnReserveTransactionAction
136
+ });
137
+ }
138
+ return tasks;
139
+ }
140
+ function createReturnPayTransactionTasks(order, returnOrderTransaction) {
141
+ var _a, _b;
142
+ const taskRunsAt = new Date();
143
+ // const taskRunsAt = moment(order.dateReturned)
144
+ // .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
145
+ // .toDate();
146
+ const tasks = [];
147
+ const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
148
+ const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
149
+ if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
150
+ tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
151
+ return {
152
+ project: a.project,
153
+ name: factory.taskName.ReturnPayTransaction,
154
+ status: factory.taskStatus.Ready,
155
+ runsAt: taskRunsAt,
156
+ remainingNumberOfTries: 10,
157
+ numberOfTried: 0,
158
+ executionResults: [],
159
+ data: a
160
+ };
161
+ }));
162
+ }
163
+ return tasks;
164
+ }
@@ -2,14 +2,16 @@ import type { RedisRepository as RegisterServiceInProgressRepo } from '../../rep
2
2
  import type { MongoRepository as TaskRepo } from '../../repo/task';
3
3
  import * as factory from '../../factory';
4
4
  import { IExternalOrder } from './onOrderStatusChanged/factory';
5
+ import { onOrderCancelled } from './onOrderStatusChanged/onOrderCancelled';
6
+ import { onOrderReturned } from './onOrderStatusChanged/onOrderReturned';
5
7
  type IPlaceOrderTransaction = factory.transaction.ITransaction<factory.transactionType.PlaceOrder>;
6
- type IReturnOrderTransaction = factory.transaction.ITransaction<factory.transactionType.ReturnOrder>;
7
- export declare function onOrderStatusChanged(params: {
8
- order: factory.order.IOrder;
8
+ declare function onOrderStatusChanged(params: {
9
+ order: Omit<factory.order.IOrder, 'orderStatus'> & {
10
+ orderStatus: factory.orderStatus.OrderDelivered | factory.orderStatus.OrderPaymentDue | factory.orderStatus.OrderPaymentDue | factory.orderStatus.OrderProcessing;
11
+ };
9
12
  placeOrderTransaction?: IPlaceOrderTransaction;
10
- returnOrderTransaction?: IReturnOrderTransaction;
11
13
  }): (repos: {
12
14
  registerActionInProgress: RegisterServiceInProgressRepo;
13
15
  task: TaskRepo;
14
16
  }) => Promise<void>;
15
- export { IExternalOrder };
17
+ export { IExternalOrder, onOrderCancelled, onOrderReturned, onOrderStatusChanged };
@@ -9,23 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.onOrderStatusChanged = void 0;
12
+ exports.onOrderStatusChanged = exports.onOrderReturned = exports.onOrderCancelled = void 0;
13
13
  /**
14
14
  * 注文ステータス変更時処理
15
15
  */
16
16
  const createDebug = require("debug");
17
- const google_libphonenumber_1 = require("google-libphonenumber");
18
17
  const factory = require("../../factory");
19
18
  const order_1 = require("../../factory/order");
20
19
  const product_1 = require("../offer/product");
21
20
  const factory_1 = require("./onOrderStatusChanged/factory");
21
+ const onOrderCancelled_1 = require("./onOrderStatusChanged/onOrderCancelled");
22
+ Object.defineProperty(exports, "onOrderCancelled", { enumerable: true, get: function () { return onOrderCancelled_1.onOrderCancelled; } });
23
+ const onOrderReturned_1 = require("./onOrderStatusChanged/onOrderReturned");
24
+ Object.defineProperty(exports, "onOrderReturned", { enumerable: true, get: function () { return onOrderReturned_1.onOrderReturned; } });
22
25
  const debug = createDebug('chevre-domain:service:order');
23
26
  const USE_CONFIRM_REGISTER_SERVICE_TRANSACTION = process.env.USE_CONFIRM_REGISTER_SERVICE_TRANSACTION === '1';
24
27
  const TOKEN_EXPIRES_IN = 604800;
25
28
  function onOrderStatusChanged(params) {
26
29
  // tslint:disable-next-line:max-func-body-length
27
30
  return (repos) => __awaiter(this, void 0, void 0, function* () {
28
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
31
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
29
32
  debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
30
33
  let tasks = [];
31
34
  const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
@@ -103,26 +106,6 @@ function onOrderStatusChanged(params) {
103
106
  // })
104
107
  ];
105
108
  break;
106
- case factory.orderStatus.OrderReturned:
107
- const potentialActionsByTransaction = (_j = (_h = (_g = (_f = params.returnOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.returnOrder) === null || _h === void 0 ? void 0 : _h.find((returnOrderActionByTransaction) => {
108
- return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
109
- })) === null || _j === void 0 ? void 0 : _j.potentialActions;
110
- tasks = [
111
- ...(0, factory_1.createInformTasks)(params.order),
112
- ...createReturnReserveTransactionTasks(params.order, simpleOrder),
113
- // 決済取引返却タスクを作成(2022-06-09~)
114
- ...createReturnPayTransactionTasks(params.order, simpleOrder, params.returnOrderTransaction),
115
- // 取引のpotentialActionsを適用(2023-08-19~)
116
- ...(0, factory_1.createOnOrderReturnedTasksByTransaction)({ potentialActions: potentialActionsByTransaction })
117
- ];
118
- break;
119
- // OrderCancelled追加(2023-08-30~)
120
- case factory.orderStatus.OrderCancelled:
121
- // 注文取引中止時と同様の処理か
122
- tasks = [
123
- ...(0, factory_1.createOnOrderCancelledTasksByTransaction)({ transaction: params.placeOrderTransaction })
124
- ];
125
- break;
126
109
  default:
127
110
  }
128
111
  yield repos.task.saveMany(tasks, { emitImmediately: true });
@@ -133,10 +116,10 @@ function onOrderStatusChanged(params) {
133
116
  // 冗長なsendOrderタスク作成を回避(2023-08-25~)
134
117
  yield createSendOrderTransactionTaskIfNotExist({
135
118
  object: params.order,
136
- potentialActions: (_m = (_l = (_k = params.placeOrderTransaction) === null || _k === void 0 ? void 0 : _k.potentialActions) === null || _l === void 0 ? void 0 : _l.order) === null || _m === void 0 ? void 0 : _m.potentialActions
119
+ potentialActions: (_h = (_g = (_f = params.placeOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.order) === null || _h === void 0 ? void 0 : _h.potentialActions
137
120
  })(repos);
138
121
  yield createGivePointAwardTaskIfNotExist({
139
- potentialActions: (_q = (_p = (_o = params.placeOrderTransaction) === null || _o === void 0 ? void 0 : _o.potentialActions) === null || _p === void 0 ? void 0 : _p.order) === null || _q === void 0 ? void 0 : _q.potentialActions
122
+ potentialActions: (_l = (_k = (_j = params.placeOrderTransaction) === null || _j === void 0 ? void 0 : _j.potentialActions) === null || _k === void 0 ? void 0 : _k.order) === null || _l === void 0 ? void 0 : _l.potentialActions
140
123
  })(repos);
141
124
  break;
142
125
  default:
@@ -341,111 +324,3 @@ function createGivePointAwardTaskIfNotExist(params) {
341
324
  }
342
325
  });
343
326
  }
344
- // const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
345
- function createReturnReserveTransactionTasks(order, simpleOrder) {
346
- var _a, _b;
347
- const taskRunsAt = new Date();
348
- const taskRunsAt4coa = new Date();
349
- // const taskRunsAt4coa = moment(order.dateReturned)
350
- // .add(RETURN_COA_TASK_DELAY_IN_SECONDS, 'seconds')
351
- // .toDate();
352
- const tasks = [];
353
- const returnActionRecipient = {
354
- typeOf: order.seller.typeOf,
355
- id: order.seller.id,
356
- name: order.seller.name
357
- };
358
- const reservationNumbers = [];
359
- // 注文アイテムから返却アクションを作成する
360
- const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
361
- for (const acceptedOffer of acceptedOffers) {
362
- if (acceptedOffer.itemOffered.typeOf === factory.reservationType.EventReservation
363
- || acceptedOffer.itemOffered.typeOf === factory.reservationType.BusReservation) {
364
- const reservation = acceptedOffer.itemOffered;
365
- const reservationNumber = reservation.reservationNumber;
366
- // 予約番号ごとに返却アクションを作成する
367
- if (!reservationNumbers.includes(reservationNumber)) {
368
- let returnReserveTransactionAction;
369
- switch ((_a = acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) {
370
- case factory.service.webAPI.Identifier.COA:
371
- const superEventLocationBranchCode = (_b = reservation.reservationFor) === null || _b === void 0 ? void 0 : _b.superEvent.location.branchCode;
372
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
373
- const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
374
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
375
- // COAでは数字のみ受け付けるので数字以外を除去
376
- telNum = telNum.replace(/[^\d]/g, '');
377
- returnReserveTransactionAction = {
378
- project: order.project,
379
- typeOf: factory.actionType.ReturnAction,
380
- object: {
381
- theaterCode: superEventLocationBranchCode,
382
- reserveNum: reservationNumber,
383
- telNum: telNum,
384
- typeOf: 'COAReserveTransaction'
385
- },
386
- agent: order.project,
387
- // potentialActions: {},
388
- purpose: simpleOrder,
389
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
390
- recipient: returnActionRecipient
391
- };
392
- break;
393
- default:
394
- returnReserveTransactionAction = {
395
- project: order.project,
396
- typeOf: factory.actionType.ReturnAction,
397
- object: {
398
- typeOf: factory.assetTransactionType.Reserve,
399
- transactionNumber: reservationNumber
400
- },
401
- agent: order.project,
402
- // potentialActions: {},
403
- purpose: simpleOrder,
404
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
405
- recipient: returnActionRecipient
406
- };
407
- }
408
- tasks.push({
409
- project: order.project,
410
- name: factory.taskName.ReturnReserveTransaction,
411
- status: factory.taskStatus.Ready,
412
- runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
413
- ? taskRunsAt4coa
414
- : taskRunsAt,
415
- remainingNumberOfTries: 10,
416
- numberOfTried: 0,
417
- executionResults: [],
418
- data: returnReserveTransactionAction
419
- });
420
- reservationNumbers.push(reservationNumber);
421
- }
422
- }
423
- }
424
- return tasks;
425
- }
426
- // const RETURN_PAY_TASK_DELAY_IN_SECONDS = 0;
427
- function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
428
- var _a, _b;
429
- const taskRunsAt = new Date();
430
- // const taskRunsAt = moment(order.dateReturned)
431
- // .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
432
- // .toDate();
433
- const tasks = [];
434
- const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
435
- const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
436
- if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
437
- tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
438
- return {
439
- project: a.project,
440
- name: factory.taskName.ReturnPayTransaction,
441
- status: factory.taskStatus.Ready,
442
- runsAt: taskRunsAt,
443
- remainingNumberOfTries: 10,
444
- numberOfTried: 0,
445
- executionResults: [],
446
- data: a
447
- };
448
- }));
449
- }
450
- return tasks;
451
- }
@@ -226,7 +226,9 @@ function placeOrder(params) {
226
226
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
227
227
  // PaymentDueであればonOrderStatusChangedを実行(2023-08-23~)
228
228
  if (order.orderStatus === factory.orderStatus.OrderPaymentDue) {
229
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
229
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
230
+ order: Object.assign(Object.assign({}, order), { orderStatus: order.orderStatus }), placeOrderTransaction
231
+ })({
230
232
  registerActionInProgress: repos.registerActionInProgress,
231
233
  task: repos.task
232
234
  });
@@ -1,5 +1,5 @@
1
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
1
2
  import type { MongoRepository as ActionRepo } from '../../repo/action';
2
- import type { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
3
3
  import type { MongoRepository as OrderRepo } from '../../repo/order';
4
4
  import type { MongoRepository as OwnershipInfoRepo } from '../../repo/ownershipInfo';
5
5
  import type { MongoRepository as TaskRepo } from '../../repo/task';
@@ -16,11 +16,11 @@ declare function returnOrder(params: {
16
16
  };
17
17
  useOnOrderStatusChanged: boolean;
18
18
  }): (repos: {
19
+ acceptedOffer: AcceptedOfferRepo;
19
20
  action: ActionRepo;
20
21
  order: OrderRepo;
21
22
  ownershipInfo: OwnershipInfoRepo;
22
23
  task: TaskRepo;
23
24
  transaction: TransactionRepo;
24
- registerServiceInProgress: RegisterServiceInProgressRepo;
25
25
  }) => Promise<void>;
26
26
  export { returnOrder };
@@ -28,7 +28,10 @@ function returnOrder(params) {
28
28
  let order = yield repos.order.findByOrderNumber({
29
29
  orderNumber,
30
30
  project: { id: params.project.id },
31
- inclusion: [],
31
+ inclusion: [
32
+ // 'project', 'typeOf', 'orderNumber', 'dateReturned', 'id', 'customer',
33
+ // 'returner', 'seller', 'price', 'priceCurrency', 'orderDate', 'orderStatus'
34
+ ],
32
35
  exclusion: []
33
36
  });
34
37
  // 返品取引検索
@@ -95,14 +98,11 @@ function returnOrder(params) {
95
98
  const result = returnedOwnershipInfos;
96
99
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: result });
97
100
  if (params.useOnOrderStatusChanged) {
98
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, returnOrderTransaction })({
99
- registerActionInProgress: repos.registerServiceInProgress,
101
+ yield (0, onOrderStatusChanged_1.onOrderReturned)({ order, returnOrderTransaction })({
102
+ acceptedOffer: repos.acceptedOffer,
100
103
  task: repos.task
101
104
  });
102
105
  }
103
- // 潜在アクション
104
- // onOrderStatusChangedへ移行(2023-08-19~)
105
- // await onReturn(returnOrderActionAttributes)({ task: repos.task });
106
106
  });
107
107
  }
108
108
  exports.returnOrder = returnOrder;
@@ -100,7 +100,10 @@ function sendOrder(params) {
100
100
  const result = ownershipInfos;
101
101
  yield repos.action.complete({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
102
102
  if (params.useOnOrderStatusChanged) {
103
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
103
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
104
+ order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderDelivered }),
105
+ placeOrderTransaction
106
+ })({
104
107
  registerActionInProgress: repos.registerActionInProgress,
105
108
  task: repos.task
106
109
  });
@@ -122,8 +125,6 @@ function sendOrder(params) {
122
125
  throw error;
123
126
  }
124
127
  }
125
- // onOrderStatusChangedへ移行(2023-08-17~)
126
- // await onSend(params)({ task: repos.task });
127
128
  });
128
129
  }
129
130
  exports.sendOrder = sendOrder;
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const factory = require("../../factory");
14
+ const acceptedOffer_1 = require("../../repo/acceptedOffer");
14
15
  const accountingReport_1 = require("../../repo/accountingReport");
15
16
  const action_1 = require("../../repo/action");
16
17
  const assetTransaction_1 = require("../../repo/assetTransaction");
@@ -30,6 +31,7 @@ function call(data) {
30
31
  throw new factory.errors.Argument('settings', 'redisClient required');
31
32
  }
32
33
  yield (0, confirmPayTransaction_1.confirmPayTransaction)(data)({
34
+ acceptedOffer: new acceptedOffer_1.MongoRepository(settings.connection),
33
35
  action: new action_1.MongoRepository(settings.connection),
34
36
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
35
37
  order: new order_1.MongoRepository(settings.connection),
@@ -37,7 +39,6 @@ function call(data) {
37
39
  event: new event_1.MongoRepository(settings.connection),
38
40
  product: new product_1.MongoRepository(settings.connection),
39
41
  project: new project_1.MongoRepository(settings.connection),
40
- // seller: new SellerRepo(settings.connection),
41
42
  task: new task_1.MongoRepository(settings.connection),
42
43
  transaction: new transaction_1.MongoRepository(settings.connection)
43
44
  });
@@ -10,9 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
- const factory = require("../../factory");
13
+ const acceptedOffer_1 = require("../../repo/acceptedOffer");
14
14
  const action_1 = require("../../repo/action");
15
- const registerServiceInProgress_1 = require("../../repo/action/registerServiceInProgress");
16
15
  const order_1 = require("../../repo/order");
17
16
  const ownershipInfo_1 = require("../../repo/ownershipInfo");
18
17
  const task_1 = require("../../repo/task");
@@ -23,22 +22,16 @@ const returnOrder_1 = require("../order/returnOrder");
23
22
  */
24
23
  function call(data) {
25
24
  return (settings) => __awaiter(this, void 0, void 0, function* () {
26
- if (settings.redisClient === undefined) {
27
- throw new factory.errors.Argument('settings', 'redisClient required');
28
- }
29
- const actionRepo = new action_1.MongoRepository(settings.connection);
30
- const orderRepo = new order_1.MongoRepository(settings.connection);
31
- const ownershipInfoRepo = new ownershipInfo_1.MongoRepository(settings.connection);
32
- const taskRepo = new task_1.MongoRepository(settings.connection);
33
- const transactionRepo = new transaction_1.MongoRepository(settings.connection);
34
- const registerServiceInProgressRepo = new registerServiceInProgress_1.RedisRepository(settings.redisClient);
25
+ // if (settings.redisClient === undefined) {
26
+ // throw new factory.errors.Argument('settings', 'redisClient required');
27
+ // }
35
28
  yield (0, returnOrder_1.returnOrder)(Object.assign(Object.assign({}, data), { useOnOrderStatusChanged: true }))({
36
- action: actionRepo,
37
- order: orderRepo,
38
- ownershipInfo: ownershipInfoRepo,
39
- registerServiceInProgress: registerServiceInProgressRepo,
40
- task: taskRepo,
41
- transaction: transactionRepo
29
+ acceptedOffer: new acceptedOffer_1.MongoRepository(settings.connection),
30
+ action: new action_1.MongoRepository(settings.connection),
31
+ order: new order_1.MongoRepository(settings.connection),
32
+ ownershipInfo: new ownershipInfo_1.MongoRepository(settings.connection),
33
+ task: new task_1.MongoRepository(settings.connection),
34
+ transaction: new transaction_1.MongoRepository(settings.connection)
42
35
  });
43
36
  });
44
37
  }
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.18.0-alpha.7"
118
+ "version": "21.18.0-alpha.8"
119
119
  }