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

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.
@@ -1,9 +1,10 @@
1
- import { Connection } from 'mongoose';
1
+ import { Connection, UpdateWriteOpResult } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  export interface IUpdatePartiallyParams {
4
4
  additionalTicketText?: string;
5
5
  'reservedTicket.dateUsed'?: Date;
6
6
  }
7
+ export declare type ICancelResult = UpdateWriteOpResult;
7
8
  /**
8
9
  * 予約リポジトリ
9
10
  */
@@ -46,7 +47,7 @@ export declare class MongoRepository {
46
47
  cancel<T extends factory.reservationType>(params: {
47
48
  id: string;
48
49
  previousReservationStatus?: factory.reservationStatusType;
49
- now: Date;
50
+ modifiedTime: Date;
50
51
  }): Promise<factory.reservation.IReservation<T>>;
51
52
  /**
52
53
  * 予約取消
@@ -54,8 +55,8 @@ export declare class MongoRepository {
54
55
  cancelByReservationNumber(params: {
55
56
  reservationNumber: string;
56
57
  previousReservationStatus?: factory.reservationStatusType;
57
- now: Date;
58
- }): Promise<void>;
58
+ modifiedTime: Date;
59
+ }): Promise<ICancelResult>;
59
60
  /**
60
61
  * 発券する
61
62
  */
@@ -934,7 +934,7 @@ class MongoRepository {
934
934
  : undefined);
935
935
  const update = Object.assign(Object.assign({}, (typeof params.previousReservationStatus === 'string')
936
936
  ? { previousReservationStatus: params.previousReservationStatus }
937
- : undefined), { reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.now });
937
+ : undefined), { reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime });
938
938
  const doc = yield this.reservationModel.findOneAndUpdate(conditions, update, { new: true })
939
939
  .select({ __v: 0, createdAt: 0, updatedAt: 0 })
940
940
  .exec();
@@ -962,8 +962,8 @@ class MongoRepository {
962
962
  : undefined);
963
963
  const update = Object.assign(Object.assign({}, (typeof params.previousReservationStatus === 'string')
964
964
  ? { previousReservationStatus: params.previousReservationStatus }
965
- : undefined), { reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.now });
966
- yield this.reservationModel.updateMany(conditions, update)
965
+ : undefined), { reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime });
966
+ return this.reservationModel.updateMany(conditions, update)
967
967
  .exec();
968
968
  });
969
969
  }
@@ -33,6 +33,7 @@ function cancelPendingReservation(actionAttributesList) {
33
33
  const reserveTransactionId = actionAttributes.purpose.id;
34
34
  // アクション開始
35
35
  const action = yield repos.action.start(actionAttributes);
36
+ let cancelResult;
36
37
  try {
37
38
  // 予約取引を検索
38
39
  const reserveTransactions = yield repos.assetTransaction.search({
@@ -44,12 +45,12 @@ function cancelPendingReservation(actionAttributesList) {
44
45
  const reserveTransaction = reserveTransactions.shift();
45
46
  const actionObject = actionAttributes.object;
46
47
  if (reserveTransaction !== undefined) {
48
+ const reservationFor = reserveTransaction.object.reservationFor;
49
+ if (reservationFor === undefined) {
50
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
51
+ }
47
52
  // ReservationPackageに対応(2022-12-23~)
48
53
  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
54
  const subReservation = reserveTransaction.object.subReservation;
54
55
  if (Array.isArray(subReservation) && subReservation.length > 0) {
55
56
  yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
@@ -62,10 +63,10 @@ function cancelPendingReservation(actionAttributesList) {
62
63
  })));
63
64
  }
64
65
  // 予約番号単位でキャンセル状態に変更する
65
- yield repos.reservation.cancelByReservationNumber({
66
+ cancelResult = yield repos.reservation.cancelByReservationNumber({
66
67
  reservationNumber: actionObject.reservationNumber,
67
68
  previousReservationStatus: actionObject.reservationStatus,
68
- now
69
+ modifiedTime: now
69
70
  });
70
71
  }
71
72
  else {
@@ -74,10 +75,6 @@ function cancelPendingReservation(actionAttributesList) {
74
75
  });
75
76
  // 取消対象予約が取引に存在すれば、適宜unlock
76
77
  if (cancelingSubReservation !== undefined) {
77
- const reservationFor = reserveTransaction.object.reservationFor;
78
- if (reservationFor === undefined) {
79
- throw new factory.errors.NotFound('transaction.object.reservationFor');
80
- }
81
78
  const cancelingReservation = Object.assign(Object.assign({}, cancelingSubReservation), { reservationFor });
82
79
  yield processUnlockSeat({
83
80
  reservation: cancelingReservation,
@@ -93,7 +90,7 @@ function cancelPendingReservation(actionAttributesList) {
93
90
  yield repos.reservation.cancel({
94
91
  id: cancelingSubReservation.id,
95
92
  previousReservationStatus: actionObject.reservationStatus,
96
- now
93
+ modifiedTime: now
97
94
  });
98
95
  // canceledReservations.push(canceledReservation);
99
96
  }
@@ -113,9 +110,15 @@ function cancelPendingReservation(actionAttributesList) {
113
110
  throw error;
114
111
  }
115
112
  // アクション完了
116
- const actionResult = {
113
+ const actionResult = Object.assign({}, (cancelResult !== undefined) ? {
114
+ cancelResult: {
115
+ n: cancelResult.n,
116
+ nModified: cancelResult.nModified,
117
+ ok: cancelResult.ok
118
+ }
119
+ } : undefined
117
120
  // canceledReservationId: canceledReservation?.id
118
- };
121
+ );
119
122
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
120
123
  yield (0, onReservationCanceled_1.onReservationCanceledByAction)(actionAttributes)({ task: repos.task });
121
124
  })));
@@ -178,7 +181,7 @@ function cancelReservation(actionAttributesList) {
178
181
  canceledReservation = yield repos.reservation.cancel({
179
182
  id: reservation.id,
180
183
  previousReservationStatus: actionAttributes.object.reservationStatus,
181
- now
184
+ modifiedTime: now
182
185
  });
183
186
  canceledReservations.push(canceledReservation);
184
187
  }
package/package.json CHANGED
@@ -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.40"
123
+ "version": "20.1.0-alpha.41"
124
124
  }