@chevre/domain 20.1.0-alpha.39 → 20.1.0-alpha.40

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.
@@ -48,6 +48,14 @@ export declare class MongoRepository {
48
48
  previousReservationStatus?: factory.reservationStatusType;
49
49
  now: Date;
50
50
  }): Promise<factory.reservation.IReservation<T>>;
51
+ /**
52
+ * 予約取消
53
+ */
54
+ cancelByReservationNumber(params: {
55
+ reservationNumber: string;
56
+ previousReservationStatus?: factory.reservationStatusType;
57
+ now: Date;
58
+ }): Promise<void>;
51
59
  /**
52
60
  * 発券する
53
61
  */
@@ -952,6 +952,21 @@ class MongoRepository {
952
952
  return doc.toObject();
953
953
  });
954
954
  }
955
+ /**
956
+ * 予約取消
957
+ */
958
+ cancelByReservationNumber(params) {
959
+ return __awaiter(this, void 0, void 0, function* () {
960
+ const conditions = Object.assign({ reservationNumber: { $eq: String(params.reservationNumber) } }, (typeof params.previousReservationStatus === 'string')
961
+ ? { reservationStatus: params.previousReservationStatus }
962
+ : undefined);
963
+ const update = Object.assign(Object.assign({}, (typeof params.previousReservationStatus === 'string')
964
+ ? { previousReservationStatus: params.previousReservationStatus }
965
+ : undefined), { reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.now });
966
+ yield this.reservationModel.updateMany(conditions, update)
967
+ .exec();
968
+ });
969
+ }
955
970
  /**
956
971
  * 発券する
957
972
  */
@@ -61,21 +61,6 @@ function createPointAward(params) {
61
61
  return pointAward;
62
62
  }
63
63
  exports.createPointAward = createPointAward;
64
- // function createPointAwardPurposeIdentifier(params: {
65
- // assetTransaction: { typeOf: factory.assetTransactionType };
66
- // project: { id: string };
67
- // reservation: { id: string };
68
- // toLocation: { identifier: string };
69
- // }): string {
70
- // return util.format(
71
- // '%s:%s:%s:%s:%s',
72
- // params.project.id,
73
- // 'givePointAward',
74
- // params.assetTransaction.typeOf,
75
- // params.reservation.id,
76
- // params.toLocation.identifier
77
- // );
78
- // }
79
64
  function createReservedTicket(params) {
80
65
  var _a, _b, _c;
81
66
  let acceptedTicketedSeat;
@@ -351,9 +336,7 @@ function createReservationFor(params) {
351
336
  id: params.id, location: params.location, name: params.name,
352
337
  // 不要なので廃止(2022-12-19~)
353
338
  // project: params.project,
354
- startDate: params.startDate,
355
- // 最適化(2022-05-31~)
356
- superEvent: optimizeReservationSuperEvent(params), typeOf: params.typeOf }, (params.doorTime instanceof Date)
339
+ startDate: params.startDate, superEvent: optimizeReservationSuperEvent(params), typeOf: params.typeOf }, (params.doorTime instanceof Date)
357
340
  ? { doorTime: params.doorTime }
358
341
  : undefined);
359
342
  }
@@ -446,14 +429,18 @@ function createPotentialActions(params) {
446
429
  const ordre2reservationUnderNameResult = ordre2reservationUnderName({ order: params.order });
447
430
  underName = ordre2reservationUnderNameResult.underName;
448
431
  }
449
- const reservationPackage = {
450
- reservationFor,
451
- reservationNumber: pendingReservations[0].reservationNumber,
452
- reservationStatus: pendingReservations[0].reservationStatus,
453
- subReservation: pendingReservations,
454
- underName,
455
- typeOf: factory.reservationType.ReservationPackage
456
- };
432
+ const moneyTransferActions = [];
433
+ pendingReservations.forEach((reservation) => {
434
+ var _a;
435
+ 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; });
436
+ moneyTransferActions.push(...createMoneyTransferActions({
437
+ acceptedOffer: acceptedOffer4reservation,
438
+ reservation,
439
+ transaction: params.transaction,
440
+ underName
441
+ }));
442
+ });
443
+ const reservationPackage = Object.assign({ reservationFor, reservationNumber: pendingReservations[0].reservationNumber, reservationStatus: pendingReservations[0].reservationStatus, subReservation: pendingReservations, typeOf: factory.reservationType.ReservationPackage }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string') ? { underName } : undefined);
457
444
  reserveActionAttributes = [{
458
445
  project: transaction.project,
459
446
  typeOf: factory.actionType.ReserveAction,
@@ -461,9 +448,7 @@ function createPotentialActions(params) {
461
448
  object: reservationPackage,
462
449
  agent: transaction.project,
463
450
  potentialActions: {
464
- // tslint:disable-next-line:no-suspicious-comment
465
- // TODO implement
466
- moneyTransfer: []
451
+ moneyTransfer: moneyTransferActions
467
452
  },
468
453
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
469
454
  }];
@@ -478,13 +463,15 @@ function createPotentialActions(params) {
478
463
  eventReservation.underName = ordre2reservationUnderNameResult.underName;
479
464
  // 不要なので廃止(2022-12-19~)
480
465
  // eventReservation.reservedTicket.underName = ordre2reservationUnderNameResult.underName;
481
- eventReservation.reservedTicket.issuedBy = ordre2reservationUnderNameResult.issuedBy;
466
+ // 不要なので廃止(2022-12-23~)
467
+ // eventReservation.reservedTicket.issuedBy = ordre2reservationUnderNameResult.issuedBy;
482
468
  }
483
469
  const acceptedOffer4reservation = (_b = transaction.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.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; });
484
470
  const moneyTransfer = createMoneyTransferActions({
485
471
  acceptedOffer: acceptedOffer4reservation,
486
472
  reservation: eventReservation,
487
- transaction: params.transaction
473
+ transaction: params.transaction,
474
+ underName: eventReservation.underName
488
475
  });
489
476
  return {
490
477
  project: transaction.project,
@@ -506,38 +493,29 @@ function createPotentialActions(params) {
506
493
  }
507
494
  exports.createPotentialActions = createPotentialActions;
508
495
  function createReservationUnderNameIdentifier(params) {
509
- const order = params.order;
510
- const customer = order.customer;
511
496
  // 予約のunderName.identifierを決定する
512
497
  return [
513
- { name: 'orderNumber', value: order.orderNumber },
514
- // 不要なので廃止(2022-05-24~)
515
- // { name: 'transaction', value: params.transaction.id },
516
- // ↓legacy-reservationの印刷アウトプットで使用(2022-02-09廃止)
517
- // { name: 'paymentMethod', value: paymentMethodNames },
518
- ...(Array.isArray(customer.identifier)) ? customer.identifier : []
498
+ { name: 'orderNumber', value: params.order.orderNumber },
499
+ ...(Array.isArray(params.order.customer.identifier)) ? params.order.customer.identifier : []
519
500
  ];
520
501
  }
521
502
  function createReservationUnderName(params) {
522
- // 予約のunderName.identifierを決定する
523
- const defaultUnderNameIdentifiers = createReservationUnderNameIdentifier({ order: params.order });
524
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ identifier: defaultUnderNameIdentifiers, 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);
503
+ 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);
525
504
  }
526
505
  /**
527
506
  * 注文者情報を予約者情報へ変換する
528
507
  */
529
508
  function ordre2reservationUnderName(params) {
530
509
  return {
531
- issuedBy: {
532
- typeOf: params.order.seller.typeOf,
533
- name: params.order.seller.name
534
- },
510
+ // issuedBy: {
511
+ // typeOf: params.order.seller.typeOf,
512
+ // name: params.order.seller.name
513
+ // },
535
514
  underName: createReservationUnderName({ order: params.order })
536
515
  };
537
516
  }
538
517
  function createMoneyTransferActions(params) {
539
518
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
540
- // return [];
541
519
  const pointAward = (_b = (_a = params.acceptedOffer) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.pointAward;
542
520
  const moneyTransfer = [];
543
521
  // ポイント特典があれば適用
@@ -560,13 +538,13 @@ function createMoneyTransferActions(params) {
560
538
  issuedThrough: { id: String((_k = (_j = pointAward.toLocation) === null || _j === void 0 ? void 0 : _j.issuedThrough) === null || _k === void 0 ? void 0 : _k.id) }
561
539
  };
562
540
  const recipient = {
563
- typeOf: (typeof ((_l = params.reservation.underName) === null || _l === void 0 ? void 0 : _l.typeOf) === 'string')
564
- ? (_m = params.reservation.underName) === null || _m === void 0 ? void 0 : _m.typeOf
541
+ typeOf: (typeof ((_l = params.underName) === null || _l === void 0 ? void 0 : _l.typeOf) === 'string')
542
+ ? (_m = params.underName) === null || _m === void 0 ? void 0 : _m.typeOf
565
543
  : factory.personType.Person,
566
- id: (typeof ((_o = params.reservation.underName) === null || _o === void 0 ? void 0 : _o.id) === 'string')
567
- ? (_p = params.reservation.underName) === null || _p === void 0 ? void 0 : _p.id
544
+ id: (typeof ((_o = params.underName) === null || _o === void 0 ? void 0 : _o.id) === 'string')
545
+ ? (_p = params.underName) === null || _p === void 0 ? void 0 : _p.id
568
546
  : '',
569
- name: String((_q = params.reservation.underName) === null || _q === void 0 ? void 0 : _q.name)
547
+ name: String((_q = params.underName) === null || _q === void 0 ? void 0 : _q.name)
570
548
  };
571
549
  moneyTransfer.push(Object.assign(Object.assign({ project: params.transaction.project, typeOf: factory.actionType.MoneyTransfer, agent: params.transaction.project, recipient, object: {
572
550
  typeOf: factory.account.transactionType.Deposit
@@ -20,6 +20,7 @@ const OfferService = require("../offer");
20
20
  const cancelReservation_1 = require("../reserve/cancelReservation");
21
21
  const settings_1 = require("../../settings");
22
22
  const factory_1 = require("./reserve/factory");
23
+ const USE_RESERVATION_PACKAGE_AS_OBJECT = process.env.USE_RESERVATION_PACKAGE_AS_OBJECT === '1';
23
24
  /**
24
25
  * 取引開始
25
26
  */
@@ -148,9 +149,6 @@ function addReservations(params) {
148
149
  // 予約作成(insertManyで実装)
149
150
  yield repos.reservation.createMany({ reservationFor, reservations: objectSubReservations });
150
151
  // 予約作成後処理
151
- // await Promise.all(objectSubReservations.map(async (r) => {
152
- // await onReservationCreated(transaction, r)(repos);
153
- // }));
154
152
  yield onReservationsCreated({ event })(repos);
155
153
  return transaction;
156
154
  });
@@ -528,22 +526,6 @@ function processLockSeats(params) {
528
526
  }
529
527
  });
530
528
  }
531
- /**
532
- * 予約作成時イベント
533
- */
534
- // function onReservationCreated(
535
- // __1: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>,
536
- // __2: IObjectSubReservation
537
- // ) {
538
- // return async (repos: {
539
- // task: TaskRepo;
540
- // }) => {
541
- // // const now = new Date();
542
- // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
543
- // // タスク保管
544
- // await repos.task.saveMany(taskAttributes);
545
- // };
546
- // }
547
529
  /**
548
530
  * 予約作成時イベント
549
531
  */
@@ -628,47 +610,55 @@ function cancel(params) {
628
610
  transactionNumber: params.transactionNumber
629
611
  });
630
612
  // 本来非同期でタスクが実行されるが、同期的に仮予約取消が実行されていないと、サービス利用側が困る可能性があるので、
631
- // 一応同期的にもcancelPendingReservationを実行しておく
613
+ // 同期的にもcancelPendingReservationを実行しておく
632
614
  try {
633
615
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
616
+ let cancelActionAttributes = [];
634
617
  if (pendingReservations.length > 0) {
635
618
  const reservationFor = transaction.object.reservationFor;
636
619
  if (reservationFor === undefined) {
637
620
  throw new factory.errors.NotFound('transaction.object.reservationFor');
638
621
  }
639
- const actionAttributes = pendingReservations.map((reservation) => {
640
- var _a;
641
- const eventReservation = Object.assign(Object.assign({}, reservation), { reservationFor });
642
- // const informReservationActions: factory.action.reserve.IInformReservation[] = [];
643
- return {
644
- project: transaction.project,
645
- typeOf: factory.actionType.CancelAction,
646
- purpose: {
647
- typeOf: transaction.typeOf,
648
- id: transaction.id
649
- },
650
- // プロジェクトに変更(2022-05-26~)
651
- agent: transaction.project,
652
- // 最適化(2022-06-06~)
653
- object: {
654
- typeOf: eventReservation.typeOf,
655
- id: eventReservation.id,
656
- issuedThrough: {
657
- typeOf: (_a = eventReservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
658
- },
659
- reservationFor: {
660
- typeOf: eventReservation.reservationFor.typeOf,
661
- id: eventReservation.reservationFor.id
662
- },
663
- reservationNumber: eventReservation.reservationNumber,
664
- reservationStatus: eventReservation.reservationStatus
665
- },
666
- potentialActions: {
667
- // informReservation: informReservationActions
668
- }
622
+ // ReservationPackageに対応(2022-12-23~)
623
+ if (USE_RESERVATION_PACKAGE_AS_OBJECT) {
624
+ const reservationPackage = {
625
+ typeOf: factory.reservationType.ReservationPackage,
626
+ reservationNumber: transaction.transactionNumber,
627
+ reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
628
+ reservationStatus: pendingReservations[0].reservationStatus
669
629
  };
670
- });
671
- yield (0, cancelReservation_1.cancelPendingReservation)(actionAttributes)(repos);
630
+ cancelActionAttributes = [{
631
+ project: transaction.project,
632
+ typeOf: factory.actionType.CancelAction,
633
+ purpose: { typeOf: transaction.typeOf, id: transaction.id },
634
+ agent: transaction.project,
635
+ object: reservationPackage,
636
+ potentialActions: {}
637
+ }];
638
+ }
639
+ else {
640
+ cancelActionAttributes = pendingReservations.map((reservation) => {
641
+ var _a;
642
+ return {
643
+ project: transaction.project,
644
+ typeOf: factory.actionType.CancelAction,
645
+ purpose: { typeOf: transaction.typeOf, id: transaction.id },
646
+ agent: transaction.project,
647
+ object: {
648
+ typeOf: reservation.typeOf,
649
+ id: reservation.id,
650
+ issuedThrough: {
651
+ typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
652
+ },
653
+ reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
654
+ reservationNumber: reservation.reservationNumber,
655
+ reservationStatus: reservation.reservationStatus
656
+ },
657
+ potentialActions: {}
658
+ };
659
+ });
660
+ }
661
+ yield (0, cancelReservation_1.cancelPendingReservation)(cancelActionAttributes)(repos);
672
662
  }
673
663
  }
674
664
  catch (error) {
@@ -737,45 +727,29 @@ function exportTasksById(params) {
737
727
  case factory.transactionStatusType.Canceled:
738
728
  case factory.transactionStatusType.Expired:
739
729
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
730
+ let cancelActionAttributes = [];
740
731
  if (pendingReservations.length > 0) {
741
732
  const reservationFor = transaction.object.reservationFor;
742
733
  if (reservationFor === undefined) {
743
734
  throw new factory.errors.NotFound('transaction.object.reservationFor');
744
735
  }
745
- const actionAttributes = pendingReservations.map((reservation) => {
746
- var _a;
747
- const eventReservation = Object.assign(Object.assign({}, reservation), { reservationFor });
748
- // const informReservationActions: factory.action.reserve.IInformReservation[] = [];
749
- return {
750
- project: transaction.project,
751
- typeOf: factory.actionType.CancelAction,
752
- purpose: {
753
- typeOf: transaction.typeOf,
754
- id: transaction.id
755
- },
756
- // プロジェクトに変更(2022-05-26~)
757
- agent: transaction.project,
758
- // 最適化(2022-06-06~)
759
- object: {
760
- typeOf: eventReservation.typeOf,
761
- id: eventReservation.id,
762
- issuedThrough: {
763
- typeOf: (_a = eventReservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
764
- },
765
- reservationFor: {
766
- typeOf: eventReservation.reservationFor.typeOf,
767
- id: eventReservation.reservationFor.id
768
- },
769
- reservationNumber: eventReservation.reservationNumber,
770
- reservationStatus: eventReservation.reservationStatus
771
- },
772
- potentialActions: {
773
- // informReservation: informReservationActions
774
- }
736
+ // ReservationPackageに対応(2022-12-23~)
737
+ if (USE_RESERVATION_PACKAGE_AS_OBJECT) {
738
+ const reservationPackage = {
739
+ typeOf: factory.reservationType.ReservationPackage,
740
+ reservationNumber: transaction.transactionNumber,
741
+ reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
742
+ reservationStatus: pendingReservations[0].reservationStatus
775
743
  };
776
- });
777
- const cancelPendingReservationTasks = actionAttributes.map((a) => {
778
- return {
744
+ cancelActionAttributes = [{
745
+ project: transaction.project,
746
+ typeOf: factory.actionType.CancelAction,
747
+ purpose: { typeOf: transaction.typeOf, id: transaction.id },
748
+ agent: transaction.project,
749
+ object: reservationPackage,
750
+ potentialActions: {}
751
+ }];
752
+ const cancelPendingReservationTask = {
779
753
  project: transaction.project,
780
754
  name: factory.taskName.CancelPendingReservation,
781
755
  status: factory.taskStatus.Ready,
@@ -784,18 +758,54 @@ function exportTasksById(params) {
784
758
  numberOfTried: 0,
785
759
  executionResults: [],
786
760
  data: {
787
- actionAttributes: [a]
761
+ actionAttributes: cancelActionAttributes
788
762
  }
789
763
  };
790
- });
791
- taskAttributes.push(...cancelPendingReservationTasks);
764
+ taskAttributes.push(cancelPendingReservationTask);
765
+ }
766
+ else {
767
+ cancelActionAttributes = pendingReservations.map((reservation) => {
768
+ var _a;
769
+ return {
770
+ project: transaction.project,
771
+ typeOf: factory.actionType.CancelAction,
772
+ purpose: { typeOf: transaction.typeOf, id: transaction.id },
773
+ agent: transaction.project,
774
+ object: {
775
+ typeOf: reservation.typeOf,
776
+ id: reservation.id,
777
+ issuedThrough: {
778
+ typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
779
+ },
780
+ reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
781
+ reservationNumber: reservation.reservationNumber,
782
+ reservationStatus: reservation.reservationStatus
783
+ },
784
+ potentialActions: {}
785
+ };
786
+ });
787
+ const cancelPendingReservationTasks = cancelActionAttributes.map((a) => {
788
+ return {
789
+ project: transaction.project,
790
+ name: factory.taskName.CancelPendingReservation,
791
+ status: factory.taskStatus.Ready,
792
+ runsAt: new Date(),
793
+ remainingNumberOfTries: 10,
794
+ numberOfTried: 0,
795
+ executionResults: [],
796
+ data: {
797
+ actionAttributes: [a]
798
+ }
799
+ };
800
+ });
801
+ taskAttributes.push(...cancelPendingReservationTasks);
802
+ }
792
803
  }
793
804
  break;
794
805
  default:
795
806
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
796
807
  }
797
808
  return repos.task.saveMany(taskAttributes);
798
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
799
809
  });
800
810
  }
801
811
  exports.exportTasksById = exportTasksById;
@@ -19,78 +19,121 @@ const onReservationCanceled_1 = require("./potentialActions/onReservationCancele
19
19
  /**
20
20
  * 進行中の予約をキャンセルする
21
21
  */
22
+ // tslint:disable-next-line:max-func-body-length
22
23
  function cancelPendingReservation(actionAttributesList) {
24
+ // tslint:disable-next-line:max-func-body-length
23
25
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
26
  const now = new Date();
25
- const canceledReservations = [];
26
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
27
- var _a;
28
- let canceledReservation;
29
- const reserveTransactionId = actionAttributes.purpose.id;
30
- // アクション開始
31
- const action = yield repos.action.start(actionAttributes);
32
- try {
33
- // 予約取引を検索
34
- const reserveTransactions = yield repos.assetTransaction.search({
35
- limit: 1,
36
- page: 1,
37
- typeOf: factory.assetTransactionType.Reserve,
38
- ids: [reserveTransactionId]
39
- });
40
- const reserveTransaction = reserveTransactions.shift();
41
- if (reserveTransaction !== undefined) {
42
- const cancelingSubReservation = (_a = reserveTransaction.object.subReservation) === null || _a === void 0 ? void 0 : _a.find((r) => {
43
- return r.id === actionAttributes.object.id;
27
+ let canceledReservations = [];
28
+ if (actionAttributesList.length > 0) {
29
+ // tslint:disable-next-line:max-func-body-length
30
+ yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
31
+ var _a;
32
+ // let canceledReservation: factory.reservation.eventReservation.IReservation | undefined;
33
+ const reserveTransactionId = actionAttributes.purpose.id;
34
+ // アクション開始
35
+ const action = yield repos.action.start(actionAttributes);
36
+ try {
37
+ // 予約取引を検索
38
+ const reserveTransactions = yield repos.assetTransaction.search({
39
+ limit: 1,
40
+ page: 1,
41
+ typeOf: factory.assetTransactionType.Reserve,
42
+ ids: [reserveTransactionId]
44
43
  });
45
- // 取消対象予約が取引に存在すれば、適宜unlock
46
- if (cancelingSubReservation !== undefined) {
47
- const reservationFor = reserveTransaction.object.reservationFor;
48
- if (reservationFor === undefined) {
49
- throw new factory.errors.NotFound('transaction.object.reservationFor');
50
- }
51
- const cancelingReservation = Object.assign(Object.assign({}, cancelingSubReservation), { reservationFor });
52
- yield processUnlockSeat({
53
- reservation: cancelingReservation,
54
- expectedHolder: reserveTransactionId
55
- })(repos);
56
- yield processUnlockOfferRateLimit({ reservation: cancelingReservation, reservationFor })(repos);
57
- // 予約が存在すればキャンセル状態に変更する
58
- const reservationCount = yield repos.reservation.count({
59
- typeOf: cancelingSubReservation.typeOf,
60
- ids: [cancelingSubReservation.id]
61
- });
62
- if (reservationCount > 0) {
63
- canceledReservation = yield repos.reservation.cancel({
64
- id: cancelingSubReservation.id,
65
- previousReservationStatus: actionAttributes.object.reservationStatus,
44
+ const reserveTransaction = reserveTransactions.shift();
45
+ const actionObject = actionAttributes.object;
46
+ if (reserveTransaction !== undefined) {
47
+ // ReservationPackageに対応(2022-12-23~)
48
+ if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
49
+ const reservationFor = reserveTransaction.object.reservationFor;
50
+ if (reservationFor === undefined) {
51
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
52
+ }
53
+ const subReservation = reserveTransaction.object.subReservation;
54
+ if (Array.isArray(subReservation) && subReservation.length > 0) {
55
+ yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
56
+ const cancelingReservation = Object.assign(Object.assign({}, cancelingSubReservation), { reservationFor });
57
+ yield processUnlockSeat({
58
+ reservation: cancelingReservation,
59
+ expectedHolder: reserveTransactionId
60
+ })(repos);
61
+ yield processUnlockOfferRateLimit({ reservation: cancelingReservation, reservationFor })(repos);
62
+ })));
63
+ }
64
+ // 予約番号単位でキャンセル状態に変更する
65
+ yield repos.reservation.cancelByReservationNumber({
66
+ reservationNumber: actionObject.reservationNumber,
67
+ previousReservationStatus: actionObject.reservationStatus,
66
68
  now
67
69
  });
68
- canceledReservations.push(canceledReservation);
70
+ }
71
+ else {
72
+ const cancelingSubReservation = (_a = reserveTransaction.object.subReservation) === null || _a === void 0 ? void 0 : _a.find((r) => {
73
+ return r.id === actionObject.id;
74
+ });
75
+ // 取消対象予約が取引に存在すれば、適宜unlock
76
+ if (cancelingSubReservation !== undefined) {
77
+ const reservationFor = reserveTransaction.object.reservationFor;
78
+ if (reservationFor === undefined) {
79
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
80
+ }
81
+ const cancelingReservation = Object.assign(Object.assign({}, cancelingSubReservation), { reservationFor });
82
+ yield processUnlockSeat({
83
+ reservation: cancelingReservation,
84
+ expectedHolder: reserveTransactionId
85
+ })(repos);
86
+ yield processUnlockOfferRateLimit({ reservation: cancelingReservation, reservationFor })(repos);
87
+ // 予約が存在すればキャンセル状態に変更する
88
+ const reservationCount = yield repos.reservation.count({
89
+ typeOf: cancelingSubReservation.typeOf,
90
+ ids: [cancelingSubReservation.id]
91
+ });
92
+ if (reservationCount > 0) {
93
+ yield repos.reservation.cancel({
94
+ id: cancelingSubReservation.id,
95
+ previousReservationStatus: actionObject.reservationStatus,
96
+ now
97
+ });
98
+ // canceledReservations.push(canceledReservation);
99
+ }
100
+ }
69
101
  }
70
102
  }
71
103
  }
72
- }
73
- catch (error) {
74
- // actionにエラー結果を追加
75
- try {
76
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
77
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
78
- }
79
- catch (__) {
80
- // 失敗したら仕方ない
104
+ catch (error) {
105
+ // actionにエラー結果を追加
106
+ try {
107
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
108
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
109
+ }
110
+ catch (__) {
111
+ // 失敗したら仕方ない
112
+ }
113
+ throw error;
81
114
  }
82
- throw error;
83
- }
84
- // アクション完了
85
- const actionResult = {
86
- canceledReservationId: canceledReservation === null || canceledReservation === void 0 ? void 0 : canceledReservation.id
87
- };
88
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
89
- if (canceledReservation !== undefined) {
115
+ // アクション完了
116
+ const actionResult = {
117
+ // canceledReservationId: canceledReservation?.id
118
+ };
119
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
90
120
  yield (0, onReservationCanceled_1.onReservationCanceledByAction)(actionAttributes)({ task: repos.task });
121
+ })));
122
+ const reservationNumber = actionAttributesList[0].object.reservationNumber;
123
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
124
+ // 最新のconfirmedReservationsを検索
125
+ canceledReservations = yield repos.reservation.search({
126
+ reservationNumber: { $eq: reservationNumber },
127
+ typeOf: factory.reservationType.EventReservation
128
+ });
129
+ canceledReservations = canceledReservations.map((r) => {
130
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
131
+ delete r._id;
132
+ return r;
133
+ });
91
134
  }
92
- })));
93
- yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, false)({ task: repos.task });
135
+ yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, false)({ task: repos.task });
136
+ }
94
137
  });
95
138
  }
96
139
  exports.cancelPendingReservation = cancelPendingReservation;
@@ -105,35 +148,40 @@ function cancelReservation(actionAttributesList) {
105
148
  let canceledReservation;
106
149
  const action = yield repos.action.start(actionAttributes);
107
150
  try {
108
- const reservation = yield repos.reservation.findById({
109
- id: actionAttributes.object.id
110
- });
111
- // 予約取引を検索
112
- const reserveTransactions = yield repos.assetTransaction.search({
113
- limit: 1,
114
- page: 1,
115
- typeOf: factory.assetTransactionType.Reserve,
116
- object: { reservations: { id: { $in: [reservation.id] } } }
117
- });
118
- const reserveTransaction = reserveTransactions.shift();
119
- let exectedHolder;
120
- if (reserveTransaction !== undefined) {
121
- exectedHolder = reserveTransaction.id;
151
+ if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
152
+ throw new factory.errors.NotImplemented('ReservationPackage not implemented');
122
153
  }
123
- if (typeof exectedHolder === 'string') {
124
- yield processUnlockSeat({
125
- reservation: reservation,
126
- expectedHolder: exectedHolder
127
- })(repos);
154
+ else {
155
+ const reservation = yield repos.reservation.findById({
156
+ id: actionAttributes.object.id
157
+ });
158
+ // 予約取引を検索
159
+ const reserveTransactions = yield repos.assetTransaction.search({
160
+ limit: 1,
161
+ page: 1,
162
+ typeOf: factory.assetTransactionType.Reserve,
163
+ object: { reservations: { id: { $in: [reservation.id] } } }
164
+ });
165
+ const reserveTransaction = reserveTransactions.shift();
166
+ let exectedHolder;
167
+ if (reserveTransaction !== undefined) {
168
+ exectedHolder = reserveTransaction.id;
169
+ }
170
+ if (typeof exectedHolder === 'string') {
171
+ yield processUnlockSeat({
172
+ reservation: reservation,
173
+ expectedHolder: exectedHolder
174
+ })(repos);
175
+ }
176
+ yield processUnlockOfferRateLimit({ reservation, reservationFor: reservation.reservationFor })(repos);
177
+ // 予約をキャンセル状態に変更する
178
+ canceledReservation = yield repos.reservation.cancel({
179
+ id: reservation.id,
180
+ previousReservationStatus: actionAttributes.object.reservationStatus,
181
+ now
182
+ });
183
+ canceledReservations.push(canceledReservation);
128
184
  }
129
- yield processUnlockOfferRateLimit({ reservation, reservationFor: reservation.reservationFor })(repos);
130
- // 予約をキャンセル状態に変更する
131
- canceledReservation = yield repos.reservation.cancel({
132
- id: reservation.id,
133
- previousReservationStatus: actionAttributes.object.reservationStatus,
134
- now
135
- });
136
- canceledReservations.push(canceledReservation);
137
185
  }
138
186
  catch (error) {
139
187
  // actionにエラー結果を追加
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.280.0-alpha.9",
12
+ "@chevre/factory": "4.280.0-alpha.10",
13
13
  "@cinerino/sdk": "3.135.0-alpha.4",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.1.0-alpha.39"
123
+ "version": "20.1.0-alpha.40"
124
124
  }