@chevre/domain 21.2.0-alpha.84 → 21.2.0-alpha.86

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.
@@ -23,7 +23,7 @@ class MongoRepository {
23
23
  }
24
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
25
25
  static CREATE_MONGO_CONDITIONS(params) {
26
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;
27
27
  const andConditions = [
28
28
  {
29
29
  typeOf: params.typeOf
@@ -184,7 +184,16 @@ class MongoRepository {
184
184
  }
185
185
  });
186
186
  }
187
- const objectReservationNumberEq = (_0 = (_z = params.object) === null || _z === void 0 ? void 0 : _z.reservationNumber) === null || _0 === void 0 ? void 0 : _0.$eq;
187
+ const objectReservationNumberIn = (_0 = (_z = params.object) === null || _z === void 0 ? void 0 : _z.reservationNumber) === null || _0 === void 0 ? void 0 : _0.$in;
188
+ if (Array.isArray(objectReservationNumberIn)) {
189
+ andConditions.push({
190
+ 'object.reservationNumber': {
191
+ $exists: true,
192
+ $in: objectReservationNumberIn
193
+ }
194
+ });
195
+ }
196
+ const objectReservationNumberEq = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.reservationNumber) === null || _2 === void 0 ? void 0 : _2.$eq;
188
197
  if (typeof objectReservationNumberEq === 'string') {
189
198
  andConditions.push({
190
199
  'object.reservationNumber': {
@@ -193,7 +202,7 @@ class MongoRepository {
193
202
  }
194
203
  });
195
204
  }
196
- const objectSubReservationIdIn = (_3 = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.reservations) === null || _2 === void 0 ? void 0 : _2.id) === null || _3 === void 0 ? void 0 : _3.$in;
205
+ const objectSubReservationIdIn = (_5 = (_4 = (_3 = params.object) === null || _3 === void 0 ? void 0 : _3.reservations) === null || _4 === void 0 ? void 0 : _4.id) === null || _5 === void 0 ? void 0 : _5.$in;
197
206
  if (Array.isArray(objectSubReservationIdIn)) {
198
207
  andConditions.push({
199
208
  'object.subReservation.id': {
@@ -228,7 +237,7 @@ class MongoRepository {
228
237
  }
229
238
  }
230
239
  }
231
- const objectUnderNameIdEq = (_6 = (_5 = (_4 = params.object) === null || _4 === void 0 ? void 0 : _4.underName) === null || _5 === void 0 ? void 0 : _5.id) === null || _6 === void 0 ? void 0 : _6.$eq;
240
+ const objectUnderNameIdEq = (_8 = (_7 = (_6 = params.object) === null || _6 === void 0 ? void 0 : _6.underName) === null || _7 === void 0 ? void 0 : _7.id) === null || _8 === void 0 ? void 0 : _8.$eq;
232
241
  if (typeof objectUnderNameIdEq === 'string') {
233
242
  andConditions.push({
234
243
  'object.underName.id': {
@@ -239,7 +248,7 @@ class MongoRepository {
239
248
  }
240
249
  break;
241
250
  case factory.assetTransactionType.RegisterService:
242
- const objectItemOfferedServiceOutputIdentifierEq = (_10 = (_9 = (_8 = (_7 = params.object) === null || _7 === void 0 ? void 0 : _7.itemOffered) === null || _8 === void 0 ? void 0 : _8.serviceOutput) === null || _9 === void 0 ? void 0 : _9.identifier) === null || _10 === void 0 ? void 0 : _10.$eq;
251
+ const objectItemOfferedServiceOutputIdentifierEq = (_12 = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.itemOffered) === null || _10 === void 0 ? void 0 : _10.serviceOutput) === null || _11 === void 0 ? void 0 : _11.identifier) === null || _12 === void 0 ? void 0 : _12.$eq;
243
252
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
244
253
  andConditions.push({
245
254
  'object.itemOffered.serviceOutput.identifier': {
@@ -248,7 +257,7 @@ class MongoRepository {
248
257
  }
249
258
  });
250
259
  }
251
- const objectItemOfferedServiceOutputIdentifierIn = (_14 = (_13 = (_12 = (_11 = params.object) === null || _11 === void 0 ? void 0 : _11.itemOffered) === null || _12 === void 0 ? void 0 : _12.serviceOutput) === null || _13 === void 0 ? void 0 : _13.identifier) === null || _14 === void 0 ? void 0 : _14.$in;
260
+ const objectItemOfferedServiceOutputIdentifierIn = (_16 = (_15 = (_14 = (_13 = params.object) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.serviceOutput) === null || _15 === void 0 ? void 0 : _15.identifier) === null || _16 === void 0 ? void 0 : _16.$in;
252
261
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
253
262
  andConditions.push({
254
263
  'object.itemOffered.serviceOutput.identifier': {
@@ -1,6 +1,8 @@
1
+ import { MongoRepository as ActionRepo } from '../../repo/action';
2
+ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
1
3
  import { MongoRepository as ReservationRepo } from '../../repo/reservation';
2
4
  import { MongoRepository as TaskRepo } from '../../repo/task';
3
- export declare function checkInRerservation(params: {
5
+ interface ICheckInReservationParams {
4
6
  project: {
5
7
  id: string;
6
8
  };
@@ -20,7 +22,13 @@ export declare function checkInRerservation(params: {
20
22
  ids?: string[];
21
23
  };
22
24
  };
25
+ }
26
+ export declare function checkInReservation(params: ICheckInReservationParams & {
27
+ reserveIfNotYet: boolean;
23
28
  }): (repos: {
29
+ action: ActionRepo;
30
+ assetTransaction: AssetTransactionRepo;
24
31
  reservation: ReservationRepo;
25
32
  task: TaskRepo;
26
33
  }) => Promise<void>;
34
+ export {};
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // import * as factory from '../../factory';
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,41 +9,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
9
  });
11
10
  };
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.checkInRerservation = void 0;
14
- // import { confirmReservation } from './confirmReservation';
12
+ exports.checkInReservation = void 0;
13
+ const factory = require("../../factory");
14
+ const confirmReservation_1 = require("./confirmReservation");
15
15
  const onReservationCheckedIn_1 = require("./potentialActions/onReservationCheckedIn");
16
- function checkInRerservation(params) {
16
+ function checkInReservation(params) {
17
17
  return (repos) => __awaiter(this, void 0, void 0, function* () {
18
18
  const now = new Date();
19
+ // confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
20
+ if (params.reserveIfNotYet === true) {
21
+ yield reserveIfNotYet(params)(repos);
22
+ }
19
23
  // 発券処理(Array対応)
20
24
  let checkedInReservationIds;
21
25
  if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
22
- // confirmReservationが間に合わない可能性を考慮する(2023-05-30~)
23
- // const reserveTransactions = await repos.assetTransaction.search<factory.assetTransactionType.Reserve>({
24
- // typeOf: factory.assetTransactionType.Reserve,
25
- // object: {
26
- // reservations: {
27
- // id: { $in: params.object.ids }
28
- // }
29
- // }
30
- // });
31
- // await Promise.all(reserveTransactions.map(async (reserveTransaction) => {
32
- // await confirmReservation([{
33
- // project: reserveTransaction.project,
34
- // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction,
35
- // // result: {},
36
- // object: reservationPackage,
37
- // agent: reserveTransaction.project,
38
- // potentialActions: {
39
- // moneyTransfer: moneyTransferActions
40
- // },
41
- // purpose: { typeOf: transaction.typeOf, id: transaction.id }
42
- // }])(repos);
43
- // }))
26
+ const existingReservationCount = yield repos.reservation.count({
27
+ id: { $in: params.object.ids },
28
+ typeOf: factory.reservationType.EventReservation
29
+ });
30
+ if (existingReservationCount !== params.object.ids.length) {
31
+ throw new factory.errors.NotFound(factory.reservationType.EventReservation, `Some reservations dot not exist. ${params.object.ids.join(',')}`);
32
+ }
44
33
  yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
45
34
  checkedInReservationIds = params.object.ids;
46
35
  }
47
36
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
37
+ for (const reservationNumber of params.object.reservationNumbers) {
38
+ const existingReservationCount = yield repos.reservation.count({
39
+ reservationNumber: { $eq: reservationNumber },
40
+ typeOf: factory.reservationType.EventReservation
41
+ });
42
+ if (existingReservationCount === 0) {
43
+ throw new factory.errors.NotFound(factory.reservationType.EventReservation, `Some reservations dot not exist. ${params.object.reservationNumbers.join(',')}`);
44
+ }
45
+ }
48
46
  yield repos.reservation.checkInIfNot({ reservationNumber: { $in: params.object.reservationNumbers }, now });
49
47
  // 予約番号リストを予約IDリストに変換
50
48
  checkedInReservationIds = yield repos.reservation.searchIdsByReservationNumber({
@@ -61,4 +59,49 @@ function checkInRerservation(params) {
61
59
  })({ task: repos.task });
62
60
  });
63
61
  }
64
- exports.checkInRerservation = checkInRerservation;
62
+ exports.checkInReservation = checkInReservation;
63
+ function reserveIfNotYet(params) {
64
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
65
+ let reserveTransactions = [];
66
+ if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
67
+ reserveTransactions = yield repos.assetTransaction.search({
68
+ typeOf: factory.assetTransactionType.Reserve,
69
+ object: {
70
+ reservations: { id: { $in: params.object.ids } }
71
+ },
72
+ statuses: [factory.transactionStatusType.Confirmed]
73
+ }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
74
+ }
75
+ if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
76
+ reserveTransactions = yield repos.assetTransaction.search({
77
+ typeOf: factory.assetTransactionType.Reserve,
78
+ object: {
79
+ reservationNumber: { $in: params.object.reservationNumbers }
80
+ },
81
+ statuses: [factory.transactionStatusType.Confirmed]
82
+ }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
83
+ }
84
+ yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
85
+ var _a;
86
+ if (typeof ((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
87
+ yield (0, confirmReservation_1.confirmReservation)({
88
+ actionAttributesList: [{
89
+ project: reserveTransaction.project,
90
+ typeOf: factory.actionType.ReserveAction,
91
+ object: {
92
+ typeOf: reserveTransaction.object.typeOf,
93
+ reservationNumber: reserveTransaction.object.reservationNumber,
94
+ reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
95
+ ? reserveTransaction.object.reservationStatus
96
+ : factory.reservationStatusType.ReservationPending,
97
+ reservationFor: reserveTransaction.object.reservationFor
98
+ },
99
+ agent: reserveTransaction.project,
100
+ purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
101
+ }],
102
+ useOnReservationConfirmed: false // ここでは確定予約の存在を担保すればよいだけ
103
+ })(repos);
104
+ }
105
+ })));
106
+ });
107
+ }
@@ -3,8 +3,8 @@
3
3
  */
4
4
  import { maskUnderName } from './reserve/factory';
5
5
  import { cancelPendingReservation, cancelReservation } from './reserve/cancelReservation';
6
- import { checkInRerservation } from './reserve/checkInReservation';
6
+ import { checkInReservation } from './reserve/checkInReservation';
7
7
  import { confirmReservation } from './reserve/confirmReservation';
8
8
  import { useReservation } from './reserve/useReservation';
9
9
  import { verifyToken4reservation } from './reserve/verifyToken4reservation';
10
- export { maskUnderName, cancelPendingReservation, cancelReservation, checkInRerservation, confirmReservation, useReservation, verifyToken4reservation };
10
+ export { maskUnderName, cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, useReservation, verifyToken4reservation };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyToken4reservation = exports.useReservation = exports.confirmReservation = exports.checkInRerservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
3
+ exports.verifyToken4reservation = exports.useReservation = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
4
4
  /**
5
5
  * 予約サービス
6
6
  */
@@ -10,7 +10,7 @@ const cancelReservation_1 = require("./reserve/cancelReservation");
10
10
  Object.defineProperty(exports, "cancelPendingReservation", { enumerable: true, get: function () { return cancelReservation_1.cancelPendingReservation; } });
11
11
  Object.defineProperty(exports, "cancelReservation", { enumerable: true, get: function () { return cancelReservation_1.cancelReservation; } });
12
12
  const checkInReservation_1 = require("./reserve/checkInReservation");
13
- Object.defineProperty(exports, "checkInRerservation", { enumerable: true, get: function () { return checkInReservation_1.checkInRerservation; } });
13
+ Object.defineProperty(exports, "checkInReservation", { enumerable: true, get: function () { return checkInReservation_1.checkInReservation; } });
14
14
  const confirmReservation_1 = require("./reserve/confirmReservation");
15
15
  Object.defineProperty(exports, "confirmReservation", { enumerable: true, get: function () { return confirmReservation_1.confirmReservation; } });
16
16
  const useReservation_1 = require("./reserve/useReservation");
@@ -11,6 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const factory = require("../../factory");
14
+ const action_1 = require("../../repo/action");
15
+ const assetTransaction_1 = require("../../repo/assetTransaction");
14
16
  const code_1 = require("../../repo/code");
15
17
  const order_1 = require("../../repo/order");
16
18
  const ownershipInfo_1 = require("../../repo/ownershipInfo");
@@ -23,6 +25,8 @@ const reserve_1 = require("../reserve");
23
25
  function call(data) {
24
26
  return (settings) => __awaiter(this, void 0, void 0, function* () {
25
27
  yield onAuthorizationCreated(data)({
28
+ action: new action_1.MongoRepository(settings.connection),
29
+ assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
26
30
  code: new code_1.MongoRepository(settings.connection),
27
31
  order: new order_1.MongoRepository(settings.connection),
28
32
  ownershipInfo: new ownershipInfo_1.MongoRepository(settings.connection),
@@ -86,14 +90,17 @@ function onAuthorizationCreated(params) {
86
90
  default:
87
91
  // no op
88
92
  }
89
- yield (0, reserve_1.checkInRerservation)({
93
+ yield (0, reserve_1.checkInReservation)({
90
94
  project: { id: params.project.id },
91
95
  object: {
92
96
  ids: reservationIds,
93
97
  reservationNumbers: reservationNumbers,
94
98
  reservationFor: { ids: reservationForIds }
95
- }
99
+ },
100
+ reserveIfNotYet: false
96
101
  })({
102
+ action: repos.action,
103
+ assetTransaction: repos.assetTransaction,
97
104
  reservation: repos.reservation,
98
105
  task: repos.task
99
106
  });
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.20",
12
+ "@chevre/factory": "4.313.0-alpha.21",
13
13
  "@cinerino/sdk": "3.157.0-alpha.5",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.84"
120
+ "version": "21.2.0-alpha.86"
121
121
  }