@chevre/domain 21.36.0 → 21.37.0-alpha.1

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.
@@ -0,0 +1,53 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const sellerRepo = await chevre.repository.Seller.createInstance(mongoose.connection);
12
+
13
+ const cursor = sellerRepo.getCursor(
14
+ {
15
+ },
16
+ {
17
+ // project: 1,
18
+ // typeOf: 1,
19
+ // startDate: 1,
20
+ // object: 1,
21
+ // result: 1
22
+ }
23
+ );
24
+ console.log('sellers found');
25
+
26
+ let i = 0;
27
+ let hasPolicyCount = 0;
28
+ await cursor.eachAsync(async (doc) => {
29
+ i += 1;
30
+ const seller: chevre.factory.seller.ISeller = doc.toObject();
31
+
32
+ const hasMerchantReturnPolicy = seller.hasMerchantReturnPolicy;
33
+ if (Array.isArray(hasMerchantReturnPolicy) && hasMerchantReturnPolicy.length > 0) {
34
+ hasPolicyCount += 1;
35
+ console.log(
36
+ hasMerchantReturnPolicy.length,
37
+ hasMerchantReturnPolicy.map(({ identifier }) => identifier)
38
+ .join(','),
39
+ seller.branchCode, seller.project.id, i);
40
+ } else {
41
+ // console.log(
42
+ // hasMerchantReturnPolicy.length,
43
+ // seller.branchCode, seller.project.id, i);
44
+ }
45
+ });
46
+
47
+ console.log(i, 'sellers checked');
48
+ console.log(hasPolicyCount, 'sellers have policies');
49
+ }
50
+
51
+ main()
52
+ .then()
53
+ .catch(console.error);
@@ -4,7 +4,7 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
- const DAYS = 500;
7
+ const DAYS = 365;
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
@@ -13,15 +13,18 @@ async function main() {
13
13
 
14
14
  const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
15
15
 
16
+ const startIndex = 8760;
16
17
  // tslint:disable-next-line:no-magic-numbers
17
- const hours = DAYS * 24;
18
+ const hours = (DAYS * 24) + startIndex;
18
19
  // tslint:disable-next-line:no-increment-decrement no-magic-numbers
19
- for (let index = 0; index < hours; index++) {
20
+ for (let index = startIndex; index < hours; index++) {
21
+ // for (let index = 0; index < hours; index++) {
20
22
  updateResult = await actionRepo.unsetUnnecessaryFields({
21
23
  filter: {
22
24
  // _id: { $eq: '667379e7be9a532411c29424' },
23
- typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
24
- 'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
25
+ typeOf: { $eq: chevre.factory.actionType.CheckAction },
26
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.service.paymentService.PaymentServiceType.MovieTicket },
27
+ actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
25
28
  startDate: {
26
29
  $gte: moment(now)
27
30
  .add(-(index + 1), 'hours')
@@ -32,16 +35,8 @@ async function main() {
32
35
  }
33
36
  },
34
37
  $unset: {
35
- 'object.paymentMethod': 1,
36
- 'object.additionalProperty': 1,
37
- 'object.amount': 1,
38
- 'object.issuedThrough': 1,
39
- 'object.description': 1,
40
- 'object.name': 1,
41
- 'object.fromLocation': 1,
42
- 'object.method': 1,
43
- 'object.creditCard': 1,
44
- 'object.movieTickets': 1
38
+ 'result.purchaseNumberAuthIn': 1,
39
+ 'result.purchaseNumberAuthResult': 1
45
40
  }
46
41
  });
47
42
  console.log('unset processed.', updateResult, -(index + 1), 'hours', -index, 'hours');
@@ -79,7 +79,6 @@ function createPotentialActions(params) {
79
79
  typeOf: factory.actionType.CancelAction,
80
80
  object: cancelObject,
81
81
  agent: transaction.project,
82
- potentialActions: {},
83
82
  purpose: {
84
83
  typeOf: transaction.typeOf,
85
84
  id: transaction.id
@@ -86,9 +86,20 @@ export declare function createPotentialActions(params: factory.assetTransaction.
86
86
  order?: Pick<factory.order.IOrder, 'orderNumber' | 'customer' | 'typeOf'>;
87
87
  }): {
88
88
  potentialActions: factory.assetTransaction.reserve.IPotentialActions;
89
- reservationPackage?: factory.action.reserve.IObject;
90
89
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
91
90
  };
91
+ export declare function createMoneyTransferActions(params: {
92
+ acceptedOffer?: factory.assetTransaction.reserve.IAcceptedOffer4object;
93
+ reservation: Pick<factory.assetTransaction.reserve.IObjectSubReservation, 'reservedTicket'>;
94
+ transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
95
+ underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
96
+ }): import("@chevre/factory/lib/action/transfer/moneyTransfer").IAttributes[];
97
+ export interface IPotentialCancelAction extends factory.action.cancel.reservation.IAttributes {
98
+ purpose: {
99
+ id: string;
100
+ typeOf: factory.assetTransactionType.Reserve;
101
+ };
102
+ }
92
103
  export declare function createCancelPendingReservationAction(params: {
93
104
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
94
- }): factory.action.cancel.reservation.IAttributes | undefined;
105
+ }): IPotentialCancelAction | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCancelPendingReservationAction = exports.createPotentialActions = exports.createReservation = exports.createIssuedThrough = exports.createReservationFor = exports.createAdditionalTicketText = exports.createAdditionalProperty = exports.validateAppliesToMovieTicket = exports.createReservedTicket = exports.createPointAward = exports.createStartParams = void 0;
3
+ exports.createCancelPendingReservationAction = exports.createMoneyTransferActions = exports.createPotentialActions = exports.createReservation = exports.createIssuedThrough = exports.createReservationFor = exports.createAdditionalTicketText = exports.createAdditionalProperty = exports.validateAppliesToMovieTicket = exports.createReservedTicket = exports.createPointAward = exports.createStartParams = void 0;
4
4
  /**
5
5
  * 予約取引ファクトリー
6
6
  */
@@ -8,7 +8,6 @@ const moment = require("moment");
8
8
  const util = require("util");
9
9
  const factory = require("../../../factory");
10
10
  const accountTransactionIdentifier_1 = require("../../../factory/accountTransactionIdentifier");
11
- const settings_1 = require("../../../settings");
12
11
  const price_1 = require("./factory/price");
13
12
  function createStartParams(params) {
14
13
  var _a;
@@ -497,63 +496,60 @@ function createPotentialActions(params) {
497
496
  if (reservationFor === undefined) {
498
497
  throw new factory.errors.NotFound('transaction.object.reservationFor');
499
498
  }
500
- const useOptimizeReservation = !settings_1.USE_OPTIMIZE_RESERVATION_EXCEPTIONS.includes(transaction.project.id);
499
+ // discontinue(2024-07-01~)
500
+ // const useOptimizeReservation: boolean = !USE_OPTIMIZE_RESERVATION_EXCEPTIONS.includes(transaction.project.id);
501
501
  // 予約アクション属性作成
502
502
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
503
- let reserveActionAttributes = [];
504
- let reservationPackage;
503
+ // let reserveActionAttributes: factory.action.reserve.IAttributes[] = [];
504
+ // let reservationPackage: factory.action.reserve.IObject | undefined;
505
505
  let underName;
506
506
  if (pendingReservations.length > 0) {
507
507
  // ReservationPackageに対応(2022-12-22~)
508
508
  // purpose:Orderの指定があれば、underName,issuedByを調整(2022-05-23~)
509
509
  if (typeof ((_a = params.order) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
510
- const ordre2reservationUnderNameResult = ordre2reservationUnderName({ order: params.order, useOptimizeReservation });
510
+ const ordre2reservationUnderNameResult = ordre2reservationUnderName({ order: params.order });
511
511
  underName = ordre2reservationUnderNameResult.underName;
512
512
  }
513
- const moneyTransferActions = [];
514
- pendingReservations.forEach((reservation) => {
515
- var _a;
516
- const acceptedOffer4reservation = (_a = transaction.object.acceptedOffer) === null || _a === void 0 ? void 0 : _a.find((o) => { var _a, _b; return ((_b = (_a = o.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id) === reservation.id; });
517
- moneyTransferActions.push(...createMoneyTransferActions({
518
- acceptedOffer: acceptedOffer4reservation,
519
- reservation,
520
- transaction: params.transaction,
521
- underName
522
- }));
523
- });
524
- reservationPackage = {
525
- reservationFor: {
526
- id: String(reservationFor.id),
527
- typeOf: reservationFor.typeOf,
528
- optimized: true
529
- },
530
- reservationNumber: transaction.object.reservationNumber,
531
- reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
532
- ? params.transaction.object.reservationStatus
533
- : factory.reservationStatusType.ReservationPending,
534
- // 不要なので廃止(2023-01-19~)
535
- // subReservation: pendingReservations,
536
- typeOf: factory.reservationType.ReservationPackage
537
- // 廃止(2023-05-31~)→予約取引から取得に変更
538
- // ...(typeof underName?.typeOf === 'string') ? { underName } : undefined
539
- };
540
- reserveActionAttributes = [{
541
- project: transaction.project,
542
- typeOf: factory.actionType.ReserveAction,
543
- // result: {},
544
- object: reservationPackage,
545
- agent: transaction.project,
546
- potentialActions: {
547
- moneyTransfer: moneyTransferActions
548
- },
549
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
550
- }];
513
+ // const moneyTransferActions: factory.action.transfer.moneyTransfer.IAttributes[] = [];
514
+ // pendingReservations.forEach((reservation) => {
515
+ // const acceptedOffer4reservation = transaction.object.acceptedOffer?.find(
516
+ // (o) => o.itemOffered?.serviceOutput?.id === reservation.id
517
+ // );
518
+ // moneyTransferActions.push(...createMoneyTransferActions({
519
+ // acceptedOffer: acceptedOffer4reservation,
520
+ // reservation,
521
+ // transaction: params.transaction,
522
+ // underName
523
+ // }));
524
+ // });
525
+ // reservationPackage = {
526
+ // reservationFor: {
527
+ // id: String(reservationFor.id),
528
+ // typeOf: reservationFor.typeOf,
529
+ // optimized: true
530
+ // }, // optimize(2024-01-24~)
531
+ // reservationNumber: transaction.object.reservationNumber,
532
+ // reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
533
+ // ? params.transaction.object.reservationStatus
534
+ // : factory.reservationStatusType.ReservationPending,
535
+ // typeOf: factory.reservationType.ReservationPackage
536
+ // };
537
+ // reserveActionAttributes = [{
538
+ // project: transaction.project,
539
+ // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction,
540
+ // object: reservationPackage,
541
+ // agent: transaction.project,
542
+ // potentialActions: {
543
+ // moneyTransfer: moneyTransferActions
544
+ // },
545
+ // purpose: { typeOf: transaction.typeOf, id: transaction.id }
546
+ // }];
551
547
  }
552
548
  return {
553
549
  potentialActions: {
554
- reserve: reserveActionAttributes
550
+ // reserve: reserveActionAttributes // discontinue(2024-07-01~)
555
551
  },
556
- reservationPackage,
552
+ // reservationPackage,
557
553
  underName
558
554
  };
559
555
  }
@@ -564,23 +560,24 @@ exports.createPotentialActions = createPotentialActions;
564
560
  function createReservationUnderNameIdentifier(params) {
565
561
  // 必要最低限の識別子のみ継承する(2024-03-16~)
566
562
  let identifiersFromCustomer = (Array.isArray(params.order.customer.identifier)) ? params.order.customer.identifier : [];
567
- if (params.useOptimizeReservation) {
568
- identifiersFromCustomer = identifiersFromCustomer.filter(({ name }) => name === 'clientId');
569
- }
563
+ // if (params.useOptimizeReservation) {
564
+ // identifiersFromCustomer = identifiersFromCustomer.filter(({ name }) => name === 'clientId');
565
+ // }
566
+ identifiersFromCustomer = identifiersFromCustomer.filter(({ name }) => name === 'clientId');
570
567
  return [
571
568
  { name: 'orderNumber', value: params.order.orderNumber },
572
569
  ...identifiersFromCustomer
573
570
  ];
574
571
  }
575
572
  function createReservationUnderName(params) {
576
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ identifier: createReservationUnderNameIdentifier({ order: params.order, useOptimizeReservation: params.useOptimizeReservation }), name: String(params.order.customer.name), typeOf: params.order.customer.typeOf }, (typeof params.order.customer.address === 'string') ? { address: params.order.customer.address } : undefined), (typeof params.order.customer.age === 'string') ? { age: params.order.customer.age } : undefined), (typeof params.order.customer.email === 'string') ? { email: params.order.customer.email } : undefined), (typeof params.order.customer.familyName === 'string') ? { familyName: params.order.customer.familyName } : undefined), (typeof params.order.customer.gender === 'string') ? { gender: params.order.customer.gender } : undefined), (typeof params.order.customer.givenName === 'string') ? { givenName: params.order.customer.givenName } : undefined), (typeof params.order.customer.id === 'string') ? { id: params.order.customer.id } : undefined), (typeof params.order.customer.telephone === 'string') ? { telephone: params.order.customer.telephone } : undefined), (typeof params.order.customer.url === 'string') ? { url: params.order.customer.url } : undefined);
573
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ identifier: createReservationUnderNameIdentifier({ order: params.order }), name: String(params.order.customer.name), typeOf: params.order.customer.typeOf }, (typeof params.order.customer.address === 'string') ? { address: params.order.customer.address } : undefined), (typeof params.order.customer.age === 'string') ? { age: params.order.customer.age } : undefined), (typeof params.order.customer.email === 'string') ? { email: params.order.customer.email } : undefined), (typeof params.order.customer.familyName === 'string') ? { familyName: params.order.customer.familyName } : undefined), (typeof params.order.customer.gender === 'string') ? { gender: params.order.customer.gender } : undefined), (typeof params.order.customer.givenName === 'string') ? { givenName: params.order.customer.givenName } : undefined), (typeof params.order.customer.id === 'string') ? { id: params.order.customer.id } : undefined), (typeof params.order.customer.telephone === 'string') ? { telephone: params.order.customer.telephone } : undefined), (typeof params.order.customer.url === 'string') ? { url: params.order.customer.url } : undefined);
577
574
  }
578
575
  /**
579
576
  * 注文者情報を予約者情報へ変換する
580
577
  */
581
578
  function ordre2reservationUnderName(params) {
582
579
  return {
583
- underName: createReservationUnderName({ order: params.order, useOptimizeReservation: params.useOptimizeReservation })
580
+ underName: createReservationUnderName({ order: params.order })
584
581
  };
585
582
  }
586
583
  function createMoneyTransferActions(params) {
@@ -625,6 +622,7 @@ function createMoneyTransferActions(params) {
625
622
  }
626
623
  return moneyTransfer;
627
624
  }
625
+ exports.createMoneyTransferActions = createMoneyTransferActions;
628
626
  function createCancelPendingReservationAction(params) {
629
627
  const transaction = params.transaction;
630
628
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
@@ -648,8 +646,7 @@ function createCancelPendingReservationAction(params) {
648
646
  typeOf: factory.actionType.CancelAction,
649
647
  purpose: { typeOf: transaction.typeOf, id: transaction.id },
650
648
  agent: transaction.project,
651
- object: reservationPackage,
652
- potentialActions: {}
649
+ object: reservationPackage
653
650
  };
654
651
  }
655
652
  return cancelActionAttributes;
@@ -142,8 +142,7 @@ function addReservations(params) {
142
142
  validateAppliesToMovieTicket: params.validateAppliesToMovieTicket
143
143
  })(repos);
144
144
  // 予約イベント最適化
145
- const useOptimizeReservation = !settings_1.USE_OPTIMIZE_RESERVATION_EXCEPTIONS.includes(transaction.project.id);
146
- const reservationFor = (0, factory_1.createReservationFor)(event, useOptimizeReservation);
145
+ const reservationFor = (0, factory_1.createReservationFor)(event, true);
147
146
  const { issuedThrough } = (0, factory_1.createIssuedThrough)({ reservationFor: event });
148
147
  // 取引に予約追加
149
148
  let lockedOfferRateLimitKeys = [];
@@ -885,15 +884,19 @@ function confirm(params) {
885
884
  order }));
886
885
  // 取引確定
887
886
  const result = {};
888
- yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Reserve, id: transaction.id, result: result, potentialActions: (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING)
889
- ? { reserve: [] }
890
- : potentialActions }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string')
887
+ yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Reserve, id: transaction.id, result: result,
888
+ // potentialActions: (USE_ASSET_TRANSACTION_SYNC_PROCESSING)
889
+ // ? { reserve: [] }
890
+ // : potentialActions, // discontinue(2024-07-01~)
891
+ potentialActions }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string')
891
892
  ? { object: { underName } }
892
893
  : undefined));
893
894
  if (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
894
895
  // sync対応(2023-01-13~)
895
896
  yield (0, confirmReservation_1.confirmReservation)({
896
- actionAttributesList: potentialActions.reserve,
897
+ // optimize(2024-07-01~)
898
+ // actionAttributesList: potentialActions.reserve,
899
+ potentialReserveAction: { object: { reservationNumber: transaction.transactionNumber } },
897
900
  useOnReservationConfirmed: true,
898
901
  byTask: true
899
902
  })(repos);
@@ -939,10 +942,17 @@ function cancel(params) {
939
942
  });
940
943
  // 本来非同期でタスクが実行されるが、同期的に仮予約取消が実行されていないと、サービス利用側が困る可能性があるので、
941
944
  // 同期的にもcancelPendingReservationを実行しておく
942
- const cancelActionAttributes = (0, factory_1.createCancelPendingReservationAction)({ transaction });
943
- if (cancelActionAttributes !== undefined) {
944
- yield (0, cancelReservation_1.cancelPendingReservation)(cancelActionAttributes)(repos);
945
- }
945
+ // optimize(2024-07-01~)
946
+ // const cancelActionAttributes = createCancelPendingReservationAction({ transaction });
947
+ // if (cancelActionAttributes !== undefined) {
948
+ // await cancelPendingReservation(cancelActionAttributes)(repos);
949
+ // }
950
+ yield (0, cancelReservation_1.cancelPendingReservation)({
951
+ purpose: {
952
+ id: transaction.id,
953
+ typeOf: factory.assetTransactionType.Reserve
954
+ }
955
+ })(repos);
946
956
  });
947
957
  }
948
958
  exports.cancel = cancel;
@@ -956,30 +966,27 @@ function exportTasksById(params) {
956
966
  typeOf: factory.assetTransactionType.Reserve,
957
967
  id: params.id
958
968
  });
959
- const potentialActions = transaction.potentialActions;
969
+ // const potentialActions = transaction.potentialActions;
960
970
  const taskAttributes = [];
961
971
  switch (transaction.status) {
962
972
  case factory.transactionStatusType.Confirmed:
963
- // tslint:disable-next-line:no-single-line-block-comment
964
- /* istanbul ignore else */
965
- if (potentialActions !== undefined) {
966
- // tslint:disable-next-line:no-single-line-block-comment
967
- /* istanbul ignore else */
968
- if (Array.isArray(potentialActions.reserve) && potentialActions.reserve.length > 0) {
969
- const reserveTask = {
970
- project: transaction.project,
971
- name: factory.taskName.Reserve,
972
- status: factory.taskStatus.Ready,
973
- runsAt: new Date(),
974
- remainingNumberOfTries: 10,
975
- numberOfTried: 0,
976
- executionResults: [],
977
- data: {
978
- actionAttributes: potentialActions.reserve
979
- }
980
- };
981
- taskAttributes.push(reserveTask);
982
- }
973
+ // potentialActions依存を完全廃止(2024-07-01~)
974
+ // if (potentialActions !== undefined) {
975
+ // if (Array.isArray(potentialActions.reserve) && potentialActions.reserve.length > 0) {
976
+ // }
977
+ // }
978
+ if (!settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
979
+ const reserveTask = {
980
+ project: transaction.project,
981
+ name: factory.taskName.Reserve,
982
+ status: factory.taskStatus.Ready,
983
+ runsAt: new Date(),
984
+ remainingNumberOfTries: 10,
985
+ numberOfTried: 0,
986
+ executionResults: [],
987
+ data: { object: { reservationNumber: transaction.transactionNumber } } // optimize(2024-07-01~)
988
+ };
989
+ taskAttributes.push(reserveTask);
983
990
  }
984
991
  break;
985
992
  case factory.transactionStatusType.Canceled:
@@ -996,7 +1003,9 @@ function exportTasksById(params) {
996
1003
  numberOfTried: 0,
997
1004
  executionResults: [],
998
1005
  data: {
999
- actionAttributes: [cancelActionAttributes4canceled]
1006
+ // optimize(2024-07-01~)
1007
+ // actionAttributes: [cancelActionAttributes4canceled],
1008
+ purpose: { id: transaction.id, typeOf: transaction.typeOf }
1000
1009
  }
1001
1010
  };
1002
1011
  taskAttributes.push(cancelPendingReservationTask);
@@ -1015,7 +1024,9 @@ function exportTasksById(params) {
1015
1024
  numberOfTried: 0,
1016
1025
  executionResults: [],
1017
1026
  data: {
1018
- actionAttributes: [cancelActionAttributes]
1027
+ // optimize(2024-07-01~)
1028
+ // actionAttributes: [cancelActionAttributes]
1029
+ purpose: { id: transaction.id, typeOf: transaction.typeOf }
1019
1030
  }
1020
1031
  };
1021
1032
  taskAttributes.push(cancelPendingReservationTask);
@@ -8,7 +8,7 @@ import type { MongoRepository as TaskRepo } from '../../repo/task';
8
8
  /**
9
9
  * 進行中の予約をキャンセルする
10
10
  */
11
- declare function cancelPendingReservation(actionAttributes: factory.action.cancel.reservation.IAttributes): (repos: {
11
+ declare function cancelPendingReservation(actionAttributes: factory.task.cancelPendingReservation.IData): (repos: {
12
12
  action: ActionRepo;
13
13
  assetTransaction: AssetTransactionRepo;
14
14
  stockHolder: StockHolderRepo;
@@ -15,6 +15,7 @@ exports.processUnlockOfferRateLimit = exports.cancelReservation = exports.cancel
15
15
  */
16
16
  const moment = require("moment");
17
17
  const factory = require("../../factory");
18
+ const factory_1 = require("../assetTransaction/reserve/factory");
18
19
  const onReservationCanceled_1 = require("./potentialActions/onReservationCanceled");
19
20
  /**
20
21
  * 進行中の予約をキャンセルする
@@ -22,30 +23,19 @@ const onReservationCanceled_1 = require("./potentialActions/onReservationCancele
22
23
  function cancelPendingReservation(actionAttributes) {
23
24
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
25
  var _a;
25
- const now = new Date();
26
- const canceledReservations = [];
27
- const { reserveTransaction } = yield cancelPengindIfNotYet(actionAttributes, now)(repos);
28
- if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
29
- if (reserveTransaction.object.disablePendingReservations === true) {
30
- // Pendingが存在しない場合は検索しても無駄(2023-06-05~)
31
- }
32
- else {
33
- // 完全廃止(2023-07-19~)
34
- throw new factory.errors.NotImplemented('disablePendingReservations must be true');
35
- }
36
- }
37
- yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, false, {
26
+ const { reserveTransaction } = yield cancelPengindIfNotYet(actionAttributes)(repos);
27
+ yield (0, onReservationCanceled_1.onReservationCanceled)([], // PendingReservationはドキュメントとして存在しないので空でok
28
+ false, {
38
29
  project: { id: reserveTransaction.project.id },
39
30
  id: String((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id)
40
31
  })({ task: repos.task });
41
32
  });
42
33
  }
43
34
  exports.cancelPendingReservation = cancelPendingReservation;
44
- function cancelPengindIfNotYet(params, __) {
35
+ function cancelPengindIfNotYet(params) {
45
36
  // tslint:disable-next-line:max-func-body-length
46
37
  return (repos) => __awaiter(this, void 0, void 0, function* () {
47
- const actionAttributes = params;
48
- const reserveTransactionId = actionAttributes.purpose.id;
38
+ const reserveTransactionId = params.purpose.id;
49
39
  // 予約取引を検索
50
40
  const reserveTransactions = yield repos.assetTransaction.search({
51
41
  limit: 1,
@@ -62,10 +52,10 @@ function cancelPengindIfNotYet(params, __) {
62
52
  limit: 1,
63
53
  page: 1,
64
54
  actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
65
- typeOf: { $eq: params.typeOf },
55
+ typeOf: { $eq: factory.actionType.CancelAction },
66
56
  object: {
67
- typeOf: { $eq: params.object.typeOf },
68
- reservationNumber: { $eq: params.object.reservationNumber }
57
+ typeOf: { $eq: factory.reservationType.ReservationPackage },
58
+ reservationNumber: { $eq: reserveTransaction.transactionNumber }
69
59
  },
70
60
  purpose: {
71
61
  id: { $in: [params.purpose.id] },
@@ -73,82 +63,85 @@ function cancelPengindIfNotYet(params, __) {
73
63
  }
74
64
  }, ['_id'], []);
75
65
  if (completedActions.length === 0) {
76
- // アクション開始
77
- const action = yield repos.action.start(actionAttributes);
78
- const actionObject = actionAttributes.object;
79
- // let cancelResult: ICancelResult | undefined;
80
- try {
81
- if (reserveTransaction !== undefined) {
82
- const reservationFor = reserveTransaction.object.reservationFor;
83
- if (reservationFor === undefined) {
84
- throw new factory.errors.NotFound('transaction.object.reservationFor');
85
- }
86
- // ReservationPackageに対応(2022-12-23~)
87
- if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
88
- const subReservation = reserveTransaction.object.subReservation;
89
- if (Array.isArray(subReservation) && subReservation.length > 0) {
90
- yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
91
- yield processUnlockSeat({
92
- reservation: {
93
- id: cancelingSubReservation.id,
94
- project: { id: reserveTransaction.project.id },
95
- reservedTicket: cancelingSubReservation.reservedTicket,
96
- subReservation: cancelingSubReservation.subReservation,
97
- reservationFor: {
98
- id: String(reservationFor.id),
99
- startDate: (reservationFor.typeOf === factory.eventType.ScreeningEvent)
100
- ? reservationFor.startDate
101
- : reservationFor.departureTime
102
- }
103
- },
104
- // holder:取引番号に対応(2023-06-05~)
105
- expectedHolder: (reserveTransaction.object.useHoldStockByTransactionNumber === true)
106
- ? reserveTransaction.transactionNumber
107
- : reserveTransactionId
108
- })(repos);
109
- yield processUnlockOfferRateLimit({
110
- reservation: {
111
- reservationNumber: reserveTransaction.object.reservationNumber,
112
- reservedTicket: cancelingSubReservation.reservedTicket
113
- },
114
- reservationFor
115
- })(repos);
116
- })));
66
+ const actionAttributes = (0, factory_1.createCancelPendingReservationAction)({ transaction: reserveTransaction });
67
+ if (actionAttributes !== undefined) {
68
+ // アクション開始
69
+ const action = yield repos.action.start(actionAttributes);
70
+ const actionObject = actionAttributes.object;
71
+ // let cancelResult: ICancelResult | undefined;
72
+ try {
73
+ if (reserveTransaction !== undefined) {
74
+ const reservationFor = reserveTransaction.object.reservationFor;
75
+ if (reservationFor === undefined) {
76
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
117
77
  }
118
- if (reserveTransaction.object.disablePendingReservations === true) {
119
- // disablePendingReservationsの場合は処理不要(2023-06-05~)
78
+ // ReservationPackageに対応(2022-12-23~)
79
+ if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
80
+ const subReservation = reserveTransaction.object.subReservation;
81
+ if (Array.isArray(subReservation) && subReservation.length > 0) {
82
+ yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
83
+ yield processUnlockSeat({
84
+ reservation: {
85
+ id: cancelingSubReservation.id,
86
+ project: { id: reserveTransaction.project.id },
87
+ reservedTicket: cancelingSubReservation.reservedTicket,
88
+ subReservation: cancelingSubReservation.subReservation,
89
+ reservationFor: {
90
+ id: String(reservationFor.id),
91
+ startDate: (reservationFor.typeOf === factory.eventType.ScreeningEvent)
92
+ ? reservationFor.startDate
93
+ : reservationFor.departureTime
94
+ }
95
+ },
96
+ // holder:取引番号に対応(2023-06-05~)
97
+ expectedHolder: (reserveTransaction.object.useHoldStockByTransactionNumber === true)
98
+ ? reserveTransaction.transactionNumber
99
+ : reserveTransactionId
100
+ })(repos);
101
+ yield processUnlockOfferRateLimit({
102
+ reservation: {
103
+ reservationNumber: reserveTransaction.object.reservationNumber,
104
+ reservedTicket: cancelingSubReservation.reservedTicket
105
+ },
106
+ reservationFor
107
+ })(repos);
108
+ })));
109
+ }
110
+ if (reserveTransaction.object.disablePendingReservations === true) {
111
+ // disablePendingReservationsの場合は処理不要(2023-06-05~)
112
+ }
113
+ else {
114
+ // 完全廃止(2023-07-19~)
115
+ throw new factory.errors.NotImplemented('disablePendingReservations must be true');
116
+ }
120
117
  }
121
118
  else {
122
- // 完全廃止(2023-07-19~)
123
- throw new factory.errors.NotImplemented('disablePendingReservations must be true');
119
+ // 廃止(2022-12-27~)
120
+ throw new factory.errors.NotImplemented(`object.typeOf '${actionObject.typeOf}' not implemented`);
124
121
  }
125
122
  }
126
- else {
127
- // 廃止(2022-12-27~)
128
- throw new factory.errors.NotImplemented(`object.typeOf '${actionObject.typeOf}' not implemented`);
129
- }
130
123
  }
131
- }
132
- catch (error) {
133
- try {
134
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
135
- }
136
- catch (__) {
137
- // 失敗したら仕方ない
124
+ catch (error) {
125
+ try {
126
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
127
+ }
128
+ catch (__) {
129
+ // 失敗したら仕方ない
130
+ }
131
+ throw error;
138
132
  }
139
- throw error;
133
+ // アクション完了
134
+ const actionResult = {
135
+ // ...(cancelResult !== undefined) ? {
136
+ // cancelResult: {
137
+ // matchedCount: cancelResult.matchedCount,
138
+ // modifiedCount: cancelResult.modifiedCount
139
+ // }
140
+ // } : undefined
141
+ // canceledReservationId: canceledReservation?.id
142
+ };
143
+ yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
140
144
  }
141
- // アクション完了
142
- const actionResult = {
143
- // ...(cancelResult !== undefined) ? {
144
- // cancelResult: {
145
- // matchedCount: cancelResult.matchedCount,
146
- // modifiedCount: cancelResult.modifiedCount
147
- // }
148
- // } : undefined
149
- // canceledReservationId: canceledReservation?.id
150
- };
151
- yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
152
145
  }
153
146
  return { reserveTransaction };
154
147
  });
@@ -71,8 +71,8 @@ function reserveIfNotYet(params) {
71
71
  reservations: { id: { $in: params.object.ids } }
72
72
  },
73
73
  statuses: [factory.transactionStatusType.Confirmed]
74
- }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
75
- debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. ids:', params.object.ids);
74
+ }, ['transactionNumber']);
75
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. ids:', params.object.ids, 'reserveTransactions:', JSON.stringify(reserveTransactions));
76
76
  }
77
77
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
78
78
  reserveTransactions = yield repos.assetTransaction.search({
@@ -81,36 +81,35 @@ function reserveIfNotYet(params) {
81
81
  reservationNumber: { $in: params.object.reservationNumbers }
82
82
  },
83
83
  statuses: [factory.transactionStatusType.Confirmed]
84
- }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
85
- debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. reservationNumbers:', params.object.reservationNumbers);
84
+ }, ['transactionNumber']);
85
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. reservationNumbers:', params.object.reservationNumbers, 'reserveTransactions:', JSON.stringify(reserveTransactions));
86
86
  }
87
87
  yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
88
- var _a;
89
- if (typeof ((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
90
- yield (0, confirmReservation_1.confirmReservation)({
91
- actionAttributesList: [{
92
- project: reserveTransaction.project,
93
- typeOf: factory.actionType.ReserveAction,
94
- object: {
95
- typeOf: reserveTransaction.object.typeOf,
96
- reservationNumber: reserveTransaction.object.reservationNumber,
97
- reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
98
- ? reserveTransaction.object.reservationStatus
99
- : factory.reservationStatusType.ReservationPending,
100
- reservationFor: {
101
- id: String(reserveTransaction.object.reservationFor.id),
102
- typeOf: reserveTransaction.object.reservationFor.typeOf,
103
- optimized: true
104
- } // optimize(2024-01-24~)
105
- },
106
- agent: reserveTransaction.project,
107
- purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
108
- }],
109
- useOnReservationConfirmed: false,
110
- byTask: false
111
- })(repos);
112
- debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.object.reservationNumber);
113
- }
88
+ yield (0, confirmReservation_1.confirmReservation)({
89
+ // optimize(2024-07-01~)
90
+ potentialReserveAction: { object: { reservationNumber: reserveTransaction.transactionNumber } },
91
+ // actionAttributesList: [{
92
+ // project: reserveTransaction.project,
93
+ // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction,
94
+ // object: {
95
+ // typeOf: reserveTransaction.object.typeOf,
96
+ // reservationNumber: reserveTransaction.object.reservationNumber,
97
+ // reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
98
+ // ? reserveTransaction.object.reservationStatus
99
+ // : factory.reservationStatusType.ReservationPending,
100
+ // reservationFor: {
101
+ // id: String(reserveTransaction.object.reservationFor.id),
102
+ // typeOf: reserveTransaction.object.reservationFor.typeOf,
103
+ // optimized: true
104
+ // } // optimize(2024-01-24~)
105
+ // },
106
+ // agent: reserveTransaction.project,
107
+ // purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
108
+ // }],
109
+ useOnReservationConfirmed: false,
110
+ byTask: false
111
+ })(repos);
112
+ debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.transactionNumber);
114
113
  })));
115
114
  });
116
115
  }
@@ -7,7 +7,7 @@ import type { MongoRepository as TaskRepo } from '../../repo/task';
7
7
  * 予約を確定する
8
8
  */
9
9
  export declare function confirmReservation(params: {
10
- actionAttributesList: factory.action.reserve.IAttributes[];
10
+ potentialReserveAction: factory.task.reserve.IPotentialReserveAction;
11
11
  useOnReservationConfirmed: boolean;
12
12
  byTask: boolean;
13
13
  }): (repos: {
@@ -16,3 +16,8 @@ export declare function confirmReservation(params: {
16
16
  reservation: ReservationRepo;
17
17
  task: TaskRepo;
18
18
  }) => Promise<void>;
19
+ type IReserveActionAttributes = Pick<factory.action.reserve.IAttributes, 'agent' | 'object' | 'potentialActions' | 'project' | 'purpose' | 'typeOf'>;
20
+ export declare function reserveTransaction2action(params: {
21
+ transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
22
+ }): IReserveActionAttributes;
23
+ export {};
@@ -9,9 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.confirmReservation = void 0;
12
+ exports.reserveTransaction2action = exports.confirmReservation = void 0;
13
13
  const createDebug = require("debug");
14
14
  const factory = require("../../factory");
15
+ const factory_1 = require("../assetTransaction/reserve/factory");
15
16
  const onReservationConfirmed_1 = require("./potentialActions/onReservationConfirmed");
16
17
  const debug = createDebug('chevre-domain:service:reserve:confirmReservation');
17
18
  /**
@@ -19,70 +20,121 @@ const debug = createDebug('chevre-domain:service:reserve:confirmReservation');
19
20
  */
20
21
  function confirmReservation(params) {
21
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
22
- if (params.actionAttributesList.length > 0) {
23
- yield Promise.all(params.actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
24
- yield reserveIfNotYet(actionAttributes, { byTask: params.byTask })(repos);
25
- if (params.useOnReservationConfirmed) {
26
- yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
27
- }
28
- })));
29
- if (params.useOnReservationConfirmed) {
30
- let confirmedReservations = [];
31
- // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
32
- const reservationNumber = params.actionAttributesList[0].object.reservationNumber;
33
- if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
34
- // 最新のconfirmedReservationsを検索
35
- confirmedReservations = yield repos.reservation.search({
36
- reservationNumber: { $eq: reservationNumber },
37
- typeOf: factory.reservationType.EventReservation
38
- });
39
- confirmedReservations = confirmedReservations.map((r) => {
40
- // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
41
- delete r._id;
42
- return r;
43
- });
44
- }
45
- yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
23
+ // await Promise.all(params.actionAttributesList.map(async (potentialReserveAction) => {
24
+ // const actionAttributes = await reserveIfNotYet(potentialReserveAction, { byTask: params.byTask })(repos);
25
+ // if (params.useOnReservationConfirmed) {
26
+ // await onReservationConfirmedByAction(actionAttributes)({ task: repos.task });
27
+ // }
28
+ // }));
29
+ const actionAttributes = yield reserveIfNotYet(params.potentialReserveAction, { byTask: params.byTask })(repos);
30
+ if (params.useOnReservationConfirmed) {
31
+ yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
32
+ }
33
+ if (params.useOnReservationConfirmed) {
34
+ let confirmedReservations = [];
35
+ // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
36
+ const reservationNumber = params.potentialReserveAction.object.reservationNumber;
37
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
38
+ // 最新のconfirmedReservationsを検索
39
+ confirmedReservations = yield repos.reservation.search({
40
+ reservationNumber: { $eq: reservationNumber },
41
+ typeOf: factory.reservationType.EventReservation
42
+ });
43
+ confirmedReservations = confirmedReservations.map((r) => {
44
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
45
+ delete r._id;
46
+ return r;
47
+ });
46
48
  }
49
+ yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
47
50
  }
48
51
  });
49
52
  }
50
53
  exports.confirmReservation = confirmReservation;
51
- function reserveIfNotYet(params, options) {
54
+ function reserveTransaction2action(params) {
55
+ var _a;
56
+ const transaction = params.transaction;
57
+ const reservationFor = transaction.object.reservationFor;
58
+ if (reservationFor === undefined) {
59
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
60
+ }
61
+ let underName;
62
+ if (typeof ((_a = transaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
63
+ underName = transaction.object.underName;
64
+ }
65
+ const moneyTransferActions = [];
66
+ const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
67
+ pendingReservations.forEach((reservation) => {
68
+ var _a;
69
+ const acceptedOffer4reservation = (_a = transaction.object.acceptedOffer) === null || _a === void 0 ? void 0 : _a.find((o) => { var _a, _b; return ((_b = (_a = o.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id) === reservation.id; });
70
+ moneyTransferActions.push(...(0, factory_1.createMoneyTransferActions)({
71
+ acceptedOffer: acceptedOffer4reservation,
72
+ reservation,
73
+ transaction: params.transaction,
74
+ underName
75
+ }));
76
+ });
77
+ const reservationPackage = {
78
+ reservationFor: {
79
+ id: String(reservationFor.id),
80
+ typeOf: reservationFor.typeOf,
81
+ optimized: true
82
+ },
83
+ reservationNumber: transaction.object.reservationNumber,
84
+ reservationStatus: (typeof params.transaction.object.reservationStatus === 'string')
85
+ ? params.transaction.object.reservationStatus
86
+ : factory.reservationStatusType.ReservationPending,
87
+ typeOf: factory.reservationType.ReservationPackage
88
+ };
89
+ return {
90
+ project: transaction.project,
91
+ typeOf: factory.actionType.ReserveAction,
92
+ object: reservationPackage,
93
+ agent: transaction.project,
94
+ potentialActions: {
95
+ moneyTransfer: moneyTransferActions
96
+ },
97
+ purpose: { typeOf: transaction.typeOf, id: transaction.id }
98
+ };
99
+ }
100
+ exports.reserveTransaction2action = reserveTransaction2action;
101
+ function reserveIfNotYet(
102
+ // params: factory.action.reserve.IAttributes,
103
+ params, options) {
52
104
  // tslint:disable-next-line:max-func-body-length
53
105
  return (repos) => __awaiter(this, void 0, void 0, function* () {
54
106
  var _a, _b;
55
107
  const reservationPackage = params.object;
108
+ const reserveTransaction = (yield repos.assetTransaction.search({
109
+ limit: 1,
110
+ page: 1,
111
+ typeOf: factory.assetTransactionType.Reserve,
112
+ transactionNumber: { $eq: reservationPackage.reservationNumber }
113
+ })).shift();
114
+ if (reserveTransaction === undefined) {
115
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
116
+ }
117
+ const actionAttributes = reserveTransaction2action({ transaction: reserveTransaction });
56
118
  // 冪等性を担保(2023-05-31~)
57
119
  debug('searching completed reserveAction... byTask:', options === null || options === void 0 ? void 0 : options.byTask, 'reservationNumber:', reservationPackage.reservationNumber);
58
120
  const completedActions = yield repos.action.search({
59
121
  limit: 1,
60
122
  page: 1,
61
123
  actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
62
- typeOf: { $eq: params.typeOf },
124
+ typeOf: { $eq: actionAttributes.typeOf },
63
125
  object: {
64
- typeOf: { $eq: params.object.typeOf }
126
+ typeOf: { $eq: actionAttributes.object.typeOf }
65
127
  // reservationNumber: { $eq: params.object.reservationNumber }
66
128
  },
67
129
  purpose: {
68
- id: { $in: [params.purpose.id] },
69
- typeOf: { $in: [params.purpose.typeOf] }
130
+ id: { $in: [actionAttributes.purpose.id] },
131
+ typeOf: { $in: [actionAttributes.purpose.typeOf] }
70
132
  }
71
133
  }, ['_id'], []);
72
134
  debug(completedActions.length, 'completed reserveAction found. byTask:', options === null || options === void 0 ? void 0 : options.byTask, 'reservationNumber:', reservationPackage.reservationNumber);
73
135
  if (completedActions.length === 0) {
74
- const action = yield repos.action.start(params);
136
+ const action = yield repos.action.start(actionAttributes);
75
137
  try {
76
- const reserveTransactions = yield repos.assetTransaction.search({
77
- limit: 1,
78
- page: 1,
79
- typeOf: factory.assetTransactionType.Reserve,
80
- transactionNumber: { $eq: reservationPackage.reservationNumber }
81
- });
82
- const reserveTransaction = reserveTransactions.shift();
83
- if (reserveTransaction === undefined) {
84
- throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
85
- }
86
138
  let underName;
87
139
  // 予約取引に保管されたunderNameを使用する(2023-05-30~)
88
140
  if (typeof ((_a = reserveTransaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
@@ -92,7 +144,7 @@ function reserveIfNotYet(params, options) {
92
144
  // underName = reservationPackage.underName;
93
145
  }
94
146
  // ReservationPackageに対応(2022-12-22~)
95
- if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
147
+ if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
96
148
  // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
97
149
  if (reserveTransaction.object.disablePendingReservations === true) {
98
150
  const reservationFor = reserveTransaction.object.reservationFor;
@@ -127,7 +179,7 @@ function reserveIfNotYet(params, options) {
127
179
  }
128
180
  else {
129
181
  // 廃止(2023-01-18)
130
- throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
182
+ throw new factory.errors.Forbidden(`${actionAttributes.object.typeOf} not acceptable`);
131
183
  }
132
184
  }
133
185
  catch (error) {
@@ -139,9 +191,9 @@ function reserveIfNotYet(params, options) {
139
191
  }
140
192
  throw error;
141
193
  }
142
- // アクション完了
143
194
  const actionResult = {};
144
195
  yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
145
196
  }
197
+ return actionAttributes;
146
198
  });
147
199
  }
@@ -7,7 +7,7 @@ type IEventReservation = factory.reservation.IReservation<factory.reservationTyp
7
7
  /**
8
8
  * 予約確定後のアクション
9
9
  */
10
- export declare function onReservationConfirmedByAction(actionAttributes: factory.action.reserve.IAttributes): (repos: {
10
+ export declare function onReservationConfirmedByAction(actionAttributes: Pick<factory.action.reserve.IAttributes, 'potentialActions'>): (repos: {
11
11
  task: TaskRepo;
12
12
  }) => Promise<void>;
13
13
  export declare function onReservationConfirmed(confirmedReservations: IEventReservation[]): (repos: {
@@ -86,36 +86,35 @@ function reserveIfNotYet(params) {
86
86
  reservations: { id: { $in: [params.object.id] } }
87
87
  },
88
88
  statuses: [factory.transactionStatusType.Confirmed]
89
- }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
90
- debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. id:', params.object.id);
89
+ }, ['transactionNumber']);
90
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. id:', params.object.id, 'reserveTransactions:', JSON.stringify(reserveTransactions));
91
91
  }
92
92
  yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
93
- var _a;
94
- if (typeof ((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
95
- yield (0, confirmReservation_1.confirmReservation)({
96
- actionAttributesList: [{
97
- project: reserveTransaction.project,
98
- typeOf: factory.actionType.ReserveAction,
99
- object: {
100
- typeOf: reserveTransaction.object.typeOf,
101
- reservationNumber: reserveTransaction.object.reservationNumber,
102
- reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
103
- ? reserveTransaction.object.reservationStatus
104
- : factory.reservationStatusType.ReservationPending,
105
- reservationFor: {
106
- id: String(reserveTransaction.object.reservationFor.id),
107
- typeOf: reserveTransaction.object.reservationFor.typeOf,
108
- optimized: true
109
- } // optimize(2024-01-24~)
110
- },
111
- agent: reserveTransaction.project,
112
- purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
113
- }],
114
- useOnReservationConfirmed: false,
115
- byTask: false
116
- })(repos);
117
- debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.object.reservationNumber);
118
- }
93
+ yield (0, confirmReservation_1.confirmReservation)({
94
+ // optimize(2024-07-01~)
95
+ potentialReserveAction: { object: { reservationNumber: reserveTransaction.transactionNumber } },
96
+ // actionAttributesList: [{
97
+ // project: reserveTransaction.project,
98
+ // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction,
99
+ // object: {
100
+ // typeOf: reserveTransaction.object.typeOf,
101
+ // reservationNumber: reserveTransaction.object.reservationNumber,
102
+ // reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
103
+ // ? reserveTransaction.object.reservationStatus
104
+ // : factory.reservationStatusType.ReservationPending,
105
+ // reservationFor: {
106
+ // id: String(reserveTransaction.object.reservationFor.id),
107
+ // typeOf: reserveTransaction.object.reservationFor.typeOf,
108
+ // optimized: true
109
+ // } // optimize(2024-01-24~)
110
+ // },
111
+ // agent: reserveTransaction.project,
112
+ // purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
113
+ // }],
114
+ useOnReservationConfirmed: false,
115
+ byTask: false
116
+ })(repos);
117
+ debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.transactionNumber);
119
118
  })));
120
119
  });
121
120
  }
@@ -33,10 +33,10 @@ function call(data) {
33
33
  const stockHolderRepo = new stockHolder_1.StockHolderRepository(settings.redisClient, settings.connection);
34
34
  const offerRateLimitRepo = new offer_1.RedisRepository(settings.redisClient);
35
35
  // アクション数は予約番号単位で1しかありえないはず(2023-06-05~)
36
- if (data.actionAttributes.length !== 1) {
37
- throw new factory.errors.Argument('data.actionAttributes', 'data.actionAttributes.length must be 1');
38
- }
39
- yield ReserveService.cancelPendingReservation(data.actionAttributes[0])({
36
+ // if (data.actionAttributes.length !== 1) {
37
+ // throw new factory.errors.Argument('data.actionAttributes', 'data.actionAttributes.length must be 1');
38
+ // }
39
+ yield ReserveService.cancelPendingReservation(data)({
40
40
  action: actionRepo,
41
41
  assetTransaction: assetTransactionRepo,
42
42
  stockHolder: stockHolderRepo,
@@ -21,7 +21,8 @@ const ReserveService = require("../reserve");
21
21
  function call(data) {
22
22
  return (settings) => __awaiter(this, void 0, void 0, function* () {
23
23
  yield ReserveService.confirmReservation({
24
- actionAttributesList: data.actionAttributes,
24
+ // actionAttributesList: data.actionAttributes,
25
+ potentialReserveAction: data,
25
26
  useOnReservationConfirmed: true,
26
27
  byTask: true
27
28
  })({
@@ -36,7 +36,6 @@ export declare const USE_OPTIMIZE_TICKET_OFFER: boolean;
36
36
  export declare const USE_FETCH_API: boolean;
37
37
  export declare const USE_OWNERSHIP_INFO_BY_WEB_APPLICATION: boolean;
38
38
  export declare const USE_CHECK_RESOURCE_TASK: boolean;
39
- export declare const USE_OPTIMIZE_RESERVATION_EXCEPTIONS: string[];
40
39
  export declare const USE_OPTIMIZE_INFORM_EVENT: boolean;
41
40
  export declare const USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER: boolean;
42
41
  export declare const USE_EXPERIMENTAL_FEATURE: boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = exports.DELIVER_ORDER_LIMIT = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_EXPERIMENTAL_FEATURE = exports.USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER = exports.USE_OPTIMIZE_INFORM_EVENT = exports.USE_OPTIMIZE_RESERVATION_EXCEPTIONS = exports.USE_CHECK_RESOURCE_TASK = exports.USE_OWNERSHIP_INFO_BY_WEB_APPLICATION = exports.USE_FETCH_API = exports.USE_OPTIMIZE_TICKET_OFFER = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.MAX_NUM_CREDIT_CARD_PAYMENT_METHOD = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
3
+ exports.settings = exports.DELIVER_ORDER_LIMIT = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_EXPERIMENTAL_FEATURE = exports.USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER = exports.USE_OPTIMIZE_INFORM_EVENT = exports.USE_CHECK_RESOURCE_TASK = exports.USE_OWNERSHIP_INFO_BY_WEB_APPLICATION = exports.USE_FETCH_API = exports.USE_OPTIMIZE_TICKET_OFFER = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.MAX_NUM_CREDIT_CARD_PAYMENT_METHOD = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
4
4
  const factory = require("./factory");
5
5
  const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
6
6
  ? process.env.INFORM_TRANSACTION_URL.split(' ')
@@ -57,9 +57,6 @@ exports.USE_OPTIMIZE_TICKET_OFFER = process.env.USE_OPTIMIZE_TICKET_OFFER === '1
57
57
  exports.USE_FETCH_API = process.env.USE_FETCH_API === '1';
58
58
  exports.USE_OWNERSHIP_INFO_BY_WEB_APPLICATION = process.env.USE_OWNERSHIP_INFO_BY_WEB_APPLICATION === '1';
59
59
  exports.USE_CHECK_RESOURCE_TASK = process.env.USE_CHECK_RESOURCE_TASK === '1';
60
- exports.USE_OPTIMIZE_RESERVATION_EXCEPTIONS = (typeof process.env.USE_OPTIMIZE_RESERVATION_EXCEPTIONS === 'string')
61
- ? process.env.USE_OPTIMIZE_RESERVATION_EXCEPTIONS.split(' ')
62
- : [];
63
60
  exports.USE_OPTIMIZE_INFORM_EVENT = process.env.USE_OPTIMIZE_INFORM_EVENT === '1';
64
61
  exports.USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER = process.env.USE_VALIDATE_MOVIE_TICKET_BY_TICKET_IDENTIFIER === '1';
65
62
  exports.USE_EXPERIMENTAL_FEATURE = process.env.USE_EXPERIMENTAL_FEATURE === '1';
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.376.0",
13
+ "@chevre/factory": "4.377.0-alpha.2",
14
14
  "@cinerino/sdk": "8.0.0",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.36.0"
113
+ "version": "21.37.0-alpha.1"
114
114
  }