@chevre/domain 20.1.0-alpha.45 → 20.1.0-alpha.47

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.
@@ -24,49 +24,66 @@ exports.createStartParams = createStartParams;
24
24
  function createPotentialActions(params) {
25
25
  var _a, _b;
26
26
  const transaction = params.transaction;
27
- let targetReservations = [];
27
+ let cancelReservationActionAttributes = [];
28
+ // 予約番号指定であれば予約番号単位でアクション生成(2022-12-27~)
28
29
  // 予約番号指定の取消取引であれば、予約取引から取消対象予約リストを作成する
29
- const reservationForByReserveTransaction = (_a = transaction.object.transaction) === null || _a === void 0 ? void 0 : _a.object.reservationFor;
30
- const subReservationByReserveTransaction = (_b = transaction.object.transaction) === null || _b === void 0 ? void 0 : _b.object.subReservation;
31
- if (reservationForByReserveTransaction !== undefined && Array.isArray(subReservationByReserveTransaction)) {
32
- targetReservations = subReservationByReserveTransaction.map((r) => {
33
- return Object.assign(Object.assign({}, r), { reservationFor: reservationForByReserveTransaction });
34
- });
35
- }
36
- else if (Array.isArray(transaction.object.reservations)) {
37
- targetReservations = transaction.object.reservations;
38
- }
39
- // 予約取消アクション属性作成
40
- const cancelReservationActionAttributes = targetReservations.map((reservation) => {
41
- var _a;
42
- // 最適化(2022-06-06~)
30
+ const reservationNumber = (_a = transaction.object.transaction) === null || _a === void 0 ? void 0 : _a.transactionNumber;
31
+ const reservationForByReserveTransaction = (_b = transaction.object.transaction) === null || _b === void 0 ? void 0 : _b.object.reservationFor;
32
+ if (reservationForByReserveTransaction !== undefined && typeof reservationNumber === 'string') {
43
33
  const cancelObject = {
44
- typeOf: reservation.typeOf,
45
- id: reservation.id,
46
- issuedThrough: {
47
- typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
48
- },
49
34
  reservationFor: {
50
- typeOf: reservation.reservationFor.typeOf,
51
- id: reservation.reservationFor.id
35
+ typeOf: reservationForByReserveTransaction.typeOf,
36
+ id: reservationForByReserveTransaction.id
52
37
  },
53
- reservationNumber: reservation.reservationNumber,
38
+ reservationNumber,
54
39
  // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
55
- reservationStatus: factory.reservationStatusType.ReservationConfirmed
40
+ reservationStatus: factory.reservationStatusType.ReservationConfirmed,
41
+ typeOf: factory.reservationType.ReservationPackage
56
42
  };
57
- return {
58
- project: transaction.project,
59
- typeOf: factory.actionType.CancelAction,
60
- // result: {},
61
- object: cancelObject,
62
- agent: transaction.project,
63
- potentialActions: {},
64
- purpose: {
65
- typeOf: transaction.typeOf,
66
- id: transaction.id
67
- }
68
- };
69
- });
43
+ cancelReservationActionAttributes = [{
44
+ project: transaction.project,
45
+ typeOf: factory.actionType.CancelAction,
46
+ object: cancelObject,
47
+ agent: transaction.project,
48
+ potentialActions: {},
49
+ purpose: {
50
+ typeOf: transaction.typeOf,
51
+ id: transaction.id
52
+ }
53
+ }];
54
+ }
55
+ else if (Array.isArray(transaction.object.reservations)) {
56
+ // 予約取消アクション属性作成
57
+ cancelReservationActionAttributes = transaction.object.reservations.map((reservation) => {
58
+ var _a;
59
+ // 最適化(2022-06-06~)
60
+ const cancelObject = {
61
+ typeOf: reservation.typeOf,
62
+ id: reservation.id,
63
+ issuedThrough: {
64
+ typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
65
+ },
66
+ reservationFor: {
67
+ typeOf: reservation.reservationFor.typeOf,
68
+ id: reservation.reservationFor.id
69
+ },
70
+ reservationNumber: reservation.reservationNumber,
71
+ // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
72
+ reservationStatus: factory.reservationStatusType.ReservationConfirmed
73
+ };
74
+ return {
75
+ project: transaction.project,
76
+ typeOf: factory.actionType.CancelAction,
77
+ object: cancelObject,
78
+ agent: transaction.project,
79
+ potentialActions: {},
80
+ purpose: {
81
+ typeOf: transaction.typeOf,
82
+ id: transaction.id
83
+ }
84
+ };
85
+ });
86
+ }
70
87
  return {
71
88
  cancelReservation: cancelReservationActionAttributes
72
89
  };
@@ -144,66 +144,122 @@ exports.cancelPendingReservation = cancelPendingReservation;
144
144
  * 予約をキャンセルする
145
145
  */
146
146
  function cancelReservation(actionAttributesList) {
147
+ // tslint:disable-next-line:max-func-body-length
147
148
  return (repos) => __awaiter(this, void 0, void 0, function* () {
148
149
  const now = new Date();
149
- const canceledReservations = [];
150
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
151
- let canceledReservation;
152
- const action = yield repos.action.start(actionAttributes);
153
- try {
154
- if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
155
- throw new factory.errors.NotImplemented('ReservationPackage not implemented');
156
- }
157
- else {
158
- const reservation = yield repos.reservation.findById({
159
- id: actionAttributes.object.id
160
- });
161
- // 予約取引を検索
162
- const reserveTransactions = yield repos.assetTransaction.search({
163
- limit: 1,
164
- page: 1,
165
- typeOf: factory.assetTransactionType.Reserve,
166
- object: { reservations: { id: { $in: [reservation.id] } } }
167
- });
168
- const reserveTransaction = reserveTransactions.shift();
169
- let exectedHolder;
170
- if (reserveTransaction !== undefined) {
171
- exectedHolder = reserveTransaction.id;
150
+ let canceledReservations = [];
151
+ if (actionAttributesList.length > 0) {
152
+ // tslint:disable-next-line:max-func-body-length
153
+ yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
154
+ const action = yield repos.action.start(actionAttributes);
155
+ let cancelResult;
156
+ try {
157
+ if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
158
+ // 予約取引を検索
159
+ const reserveTransactions = yield repos.assetTransaction.search({
160
+ limit: 1,
161
+ page: 1,
162
+ typeOf: factory.assetTransactionType.Reserve,
163
+ transactionNumber: { $eq: actionAttributes.object.reservationNumber }
164
+ });
165
+ const reserveTransaction = reserveTransactions.shift();
166
+ if (reserveTransaction === undefined) {
167
+ throw new factory.errors.NotFound('ReserveTransaction');
168
+ }
169
+ const reservationFor = reserveTransaction.object.reservationFor;
170
+ if (reservationFor === undefined) {
171
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
172
+ }
173
+ const subReservation = reserveTransaction.object.subReservation;
174
+ if (Array.isArray(subReservation) && subReservation.length > 0) {
175
+ yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
176
+ const cancelingReservation = Object.assign(Object.assign({}, cancelingSubReservation), { reservationFor });
177
+ yield processUnlockSeat({
178
+ reservation: cancelingReservation,
179
+ expectedHolder: reserveTransaction.id
180
+ })(repos);
181
+ yield processUnlockOfferRateLimit({ reservation: cancelingReservation, reservationFor })(repos);
182
+ })));
183
+ }
184
+ // 予約番号単位でキャンセル状態に変更する
185
+ cancelResult = yield repos.reservation.cancelByReservationNumber({
186
+ reservationNumber: actionAttributes.object.reservationNumber,
187
+ previousReservationStatus: actionAttributes.object.reservationStatus,
188
+ modifiedTime: now
189
+ });
172
190
  }
173
- if (typeof exectedHolder === 'string') {
174
- yield processUnlockSeat({
175
- reservation: reservation,
176
- expectedHolder: exectedHolder
177
- })(repos);
191
+ else {
192
+ const reservation = yield repos.reservation.findById({
193
+ id: actionAttributes.object.id
194
+ });
195
+ // 予約取引を検索
196
+ const reserveTransactions = yield repos.assetTransaction.search({
197
+ limit: 1,
198
+ page: 1,
199
+ typeOf: factory.assetTransactionType.Reserve,
200
+ object: { reservations: { id: { $in: [reservation.id] } } }
201
+ });
202
+ const reserveTransaction = reserveTransactions.shift();
203
+ let exectedHolder;
204
+ if (reserveTransaction !== undefined) {
205
+ exectedHolder = reserveTransaction.id;
206
+ }
207
+ if (typeof exectedHolder === 'string') {
208
+ yield processUnlockSeat({
209
+ reservation: reservation,
210
+ expectedHolder: exectedHolder
211
+ })(repos);
212
+ }
213
+ yield processUnlockOfferRateLimit({ reservation, reservationFor: reservation.reservationFor })(repos);
214
+ // 予約をキャンセル状態に変更する
215
+ const canceledReservation = yield repos.reservation.cancel({
216
+ id: reservation.id,
217
+ previousReservationStatus: actionAttributes.object.reservationStatus,
218
+ modifiedTime: now
219
+ });
220
+ canceledReservations.push(canceledReservation);
178
221
  }
179
- yield processUnlockOfferRateLimit({ reservation, reservationFor: reservation.reservationFor })(repos);
180
- // 予約をキャンセル状態に変更する
181
- canceledReservation = yield repos.reservation.cancel({
182
- id: reservation.id,
183
- previousReservationStatus: actionAttributes.object.reservationStatus,
184
- modifiedTime: now
185
- });
186
- canceledReservations.push(canceledReservation);
187
222
  }
188
- }
189
- catch (error) {
190
- // actionにエラー結果を追加
191
- try {
192
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
193
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
223
+ catch (error) {
224
+ // actionにエラー結果を追加
225
+ try {
226
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
227
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
228
+ }
229
+ catch (__) {
230
+ // 失敗したら仕方ない
231
+ }
232
+ throw error;
194
233
  }
195
- catch (__) {
196
- // 失敗したら仕方ない
234
+ const actionResult = Object.assign({}, (cancelResult !== undefined) ? {
235
+ cancelResult: {
236
+ n: cancelResult.n,
237
+ nModified: cancelResult.nModified,
238
+ ok: cancelResult.ok
239
+ }
240
+ } : undefined
241
+ // canceledReservationId: canceledReservation?.id
242
+ );
243
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
244
+ yield (0, onReservationCanceled_1.onReservationCanceledByAction)(actionAttributes)({ task: repos.task });
245
+ })));
246
+ if (actionAttributesList[0].object.typeOf === factory.reservationType.ReservationPackage) {
247
+ const reservationNumber = actionAttributesList[0].object.reservationNumber;
248
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
249
+ // 最新のconfirmedReservationsを検索
250
+ canceledReservations = yield repos.reservation.search({
251
+ reservationNumber: { $eq: reservationNumber },
252
+ typeOf: factory.reservationType.EventReservation
253
+ });
254
+ canceledReservations = canceledReservations.map((r) => {
255
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
256
+ delete r._id;
257
+ return r;
258
+ });
197
259
  }
198
- throw error;
199
260
  }
200
- const actionResult = {
201
- canceledReservationId: canceledReservation === null || canceledReservation === void 0 ? void 0 : canceledReservation.id
202
- };
203
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
204
- yield (0, onReservationCanceled_1.onReservationCanceledByAction)(actionAttributes)({ task: repos.task });
205
- })));
206
- yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, true)({ task: repos.task });
261
+ yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, true)({ task: repos.task });
262
+ }
207
263
  });
208
264
  }
209
265
  exports.cancelReservation = cancelReservation;
@@ -5,7 +5,7 @@ export interface IProject {
5
5
  id: string;
6
6
  typeOf: factory.organizationType.Project;
7
7
  }
8
- export declare type ISubReservation = Omit<IEventReservation, 'project' | 'reservationFor' | 'reservationNumber' | 'reservationStatus' | 'underName'>;
8
+ export declare type ISubReservation = Omit<IEventReservation, 'broker' | 'project' | 'reservationFor' | 'reservationNumber' | 'reservationStatus' | 'underName'>;
9
9
  /**
10
10
  * 確定予約通知
11
11
  */
@@ -110,7 +110,7 @@ function onReservationConfirmed(confirmedReservations) {
110
110
  // ReservationPackage通知に変更(2022-12-24~)
111
111
  // const informObject: IInformObject = confirmedReservations.map(maskUnderName);
112
112
  const informObject = [Object.assign({ project: confirmedReservations[0].project, reservationFor: confirmedReservations[0].reservationFor, reservationNumber: confirmedReservations[0].reservationNumber, reservationStatus: confirmedReservations[0].reservationStatus, subReservation: confirmedReservations.map((r) => {
113
- const { project, reservationFor, reservationNumber, reservationStatus, underName } = r, subReservation = __rest(r, ["project", "reservationFor", "reservationNumber", "reservationStatus", "underName"]);
113
+ const { broker, project, reservationFor, reservationNumber, reservationStatus, underName } = r, subReservation = __rest(r, ["broker", "project", "reservationFor", "reservationNumber", "reservationStatus", "underName"]);
114
114
  return subReservation;
115
115
  }), typeOf: factory.reservationType.ReservationPackage }, (typeof ((_b = confirmedReservations[0].underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
116
116
  ? { underName: (0, factory_1.maskUnderName)(confirmedReservations[0]).underName }
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.280.0-alpha.10",
13
- "@cinerino/sdk": "3.135.0-alpha.4",
12
+ "@chevre/factory": "4.280.0-alpha.11",
13
+ "@cinerino/sdk": "3.135.0-alpha.6",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.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.45"
123
+ "version": "20.1.0-alpha.47"
124
124
  }