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

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.
@@ -729,7 +729,8 @@ function confirm(params) {
729
729
  // sync対応(2023-01-13~)
730
730
  yield (0, confirmReservation_1.confirmReservation)({
731
731
  actionAttributesList: potentialActions.reserve,
732
- useOnReservationConfirmed: true
732
+ useOnReservationConfirmed: true,
733
+ byTask: true
733
734
  })(repos);
734
735
  }
735
736
  });
@@ -10,13 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.checkInReservation = void 0;
13
+ const createDebug = require("debug");
13
14
  const factory = require("../../factory");
14
15
  const confirmReservation_1 = require("./confirmReservation");
15
16
  const onReservationCheckedIn_1 = require("./potentialActions/onReservationCheckedIn");
17
+ const debug = createDebug('chevre-domain:service:reserve:checkInReservation');
16
18
  function checkInReservation(params) {
17
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
18
20
  const now = new Date();
19
21
  // confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
22
+ debug('reserveIfNotYet?', params.reserveIfNotYet, 'ids:', params.object.ids, 'reservationNumbers:', params.object.reservationNumbers);
20
23
  if (params.reserveIfNotYet === true) {
21
24
  yield reserveIfNotYet(params)(repos);
22
25
  }
@@ -71,6 +74,7 @@ function reserveIfNotYet(params) {
71
74
  },
72
75
  statuses: [factory.transactionStatusType.Confirmed]
73
76
  }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
77
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. ids:', params.object.ids);
74
78
  }
75
79
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
76
80
  reserveTransactions = yield repos.assetTransaction.search({
@@ -80,6 +84,7 @@ function reserveIfNotYet(params) {
80
84
  },
81
85
  statuses: [factory.transactionStatusType.Confirmed]
82
86
  }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
87
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. reservationNumbers:', params.object.reservationNumbers);
83
88
  }
84
89
  yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
85
90
  var _a;
@@ -99,8 +104,10 @@ function reserveIfNotYet(params) {
99
104
  agent: reserveTransaction.project,
100
105
  purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
101
106
  }],
102
- useOnReservationConfirmed: false // ここでは確定予約の存在を担保すればよいだけ
107
+ useOnReservationConfirmed: false,
108
+ byTask: false
103
109
  })(repos);
110
+ debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.object.reservationNumber);
104
111
  }
105
112
  })));
106
113
  });
@@ -1,6 +1,3 @@
1
- /**
2
- * 予約サービス
3
- */
4
1
  import * as factory from '../../factory';
5
2
  import { MongoRepository as ActionRepo } from '../../repo/action';
6
3
  import { MongoRepository as AssetTrasactionRepo } from '../../repo/assetTransaction';
@@ -12,6 +9,7 @@ import { MongoRepository as TaskRepo } from '../../repo/task';
12
9
  export declare function confirmReservation(params: {
13
10
  actionAttributesList: factory.action.reserve.IAttributes[];
14
11
  useOnReservationConfirmed: boolean;
12
+ byTask: boolean;
15
13
  }): (repos: {
16
14
  action: ActionRepo;
17
15
  assetTransaction: AssetTrasactionRepo;
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.confirmReservation = void 0;
13
- /**
14
- * 予約サービス
15
- */
13
+ const createDebug = require("debug");
16
14
  const factory = require("../../factory");
17
15
  const onReservationConfirmed_1 = require("./potentialActions/onReservationConfirmed");
16
+ const debug = createDebug('chevre-domain:service:reserve:confirmReservation');
18
17
  /**
19
18
  * 予約を確定する
20
19
  */
@@ -22,7 +21,7 @@ function confirmReservation(params) {
22
21
  return (repos) => __awaiter(this, void 0, void 0, function* () {
23
22
  if (params.actionAttributesList.length > 0) {
24
23
  yield Promise.all(params.actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
25
- yield reserveIfNotYet(actionAttributes)(repos);
24
+ yield reserveIfNotYet(actionAttributes, { byTask: params.byTask })(repos);
26
25
  if (params.useOnReservationConfirmed) {
27
26
  yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
28
27
  }
@@ -49,12 +48,13 @@ function confirmReservation(params) {
49
48
  });
50
49
  }
51
50
  exports.confirmReservation = confirmReservation;
52
- function reserveIfNotYet(params) {
51
+ function reserveIfNotYet(params, options) {
53
52
  // tslint:disable-next-line:max-func-body-length
54
53
  return (repos) => __awaiter(this, void 0, void 0, function* () {
55
54
  var _a;
56
55
  const reservationPackage = params.object;
57
56
  // 冪等性を担保(2023-05-31~)
57
+ debug('searching completed reserveAction... byTask:', options === null || options === void 0 ? void 0 : options.byTask, 'reservationNumber:', reservationPackage.reservationNumber);
58
58
  const completedActions = yield repos.action.search({
59
59
  limit: 1,
60
60
  page: 1,
@@ -69,6 +69,7 @@ function reserveIfNotYet(params) {
69
69
  typeOf: { $in: [params.purpose.typeOf] }
70
70
  }
71
71
  }, ['_id'], []);
72
+ debug(completedActions.length, 'completed reserveAction found. byTask:', options === null || options === void 0 ? void 0 : options.byTask, 'reservationNumber:', reservationPackage.reservationNumber);
72
73
  if (completedActions.length === 0) {
73
74
  const action = yield repos.action.start(params);
74
75
  try {
@@ -1,5 +1,6 @@
1
1
  import * as factory from '../../factory';
2
2
  import { MongoRepository as ActionRepo } from '../../repo/action';
3
+ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
3
4
  import { MongoRepository as OrderRepo } from '../../repo/order';
4
5
  import { MongoRepository as ReservationRepo } from '../../repo/reservation';
5
6
  import { MongoRepository as TaskRepo } from '../../repo/task';
@@ -25,8 +26,10 @@ export declare function useReservation(params: {
25
26
  identifier?: string;
26
27
  };
27
28
  verifyToken: boolean;
29
+ reserveIfNotYet: boolean;
28
30
  }): (repos: {
29
31
  action: ActionRepo;
32
+ assetTransaction: AssetTransactionRepo;
30
33
  order: OrderRepo;
31
34
  reservation: ReservationRepo;
32
35
  task: TaskRepo;
@@ -10,9 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useReservation = void 0;
13
+ const createDebug = require("debug");
13
14
  const factory = require("../../factory");
15
+ const confirmReservation_1 = require("./confirmReservation");
14
16
  const onReservationUsed_1 = require("./potentialActions/onReservationUsed");
15
17
  const verifyToken4reservation_1 = require("./verifyToken4reservation");
18
+ const debug = createDebug('chevre-domain:service:reserve:useReservation');
16
19
  /**
17
20
  * 予約使用
18
21
  */
@@ -34,6 +37,11 @@ function useReservation(params) {
34
37
  })({ order: repos.order });
35
38
  }
36
39
  }
40
+ // confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
41
+ debug('reserveIfNotYet?', params.reserveIfNotYet, 'id:', params.object.id);
42
+ if (params.reserveIfNotYet === true) {
43
+ yield reserveIfNotYet({ object: params.object })(repos);
44
+ }
37
45
  // 予約検索
38
46
  // 取得属性最適化(2023-01-30~)
39
47
  const reservation = yield repos.reservation.findById({
@@ -88,3 +96,42 @@ function useReservation(params) {
88
96
  });
89
97
  }
90
98
  exports.useReservation = useReservation;
99
+ function reserveIfNotYet(params) {
100
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
101
+ let reserveTransactions = [];
102
+ if (typeof params.object.id === 'string' && params.object.id.length > 0) {
103
+ reserveTransactions = yield repos.assetTransaction.search({
104
+ typeOf: factory.assetTransactionType.Reserve,
105
+ object: {
106
+ reservations: { id: { $in: [params.object.id] } }
107
+ },
108
+ statuses: [factory.transactionStatusType.Confirmed]
109
+ }, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
110
+ debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. id:', params.object.id);
111
+ }
112
+ yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
113
+ var _a;
114
+ if (typeof ((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
115
+ yield (0, confirmReservation_1.confirmReservation)({
116
+ actionAttributesList: [{
117
+ project: reserveTransaction.project,
118
+ typeOf: factory.actionType.ReserveAction,
119
+ object: {
120
+ typeOf: reserveTransaction.object.typeOf,
121
+ reservationNumber: reserveTransaction.object.reservationNumber,
122
+ reservationStatus: (typeof reserveTransaction.object.reservationStatus === 'string')
123
+ ? reserveTransaction.object.reservationStatus
124
+ : factory.reservationStatusType.ReservationPending,
125
+ reservationFor: reserveTransaction.object.reservationFor
126
+ },
127
+ agent: reserveTransaction.project,
128
+ purpose: { typeOf: reserveTransaction.typeOf, id: reserveTransaction.id }
129
+ }],
130
+ useOnReservationConfirmed: false,
131
+ byTask: false
132
+ })(repos);
133
+ debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.object.reservationNumber);
134
+ }
135
+ })));
136
+ });
137
+ }
@@ -97,7 +97,7 @@ function onAuthorizationCreated(params) {
97
97
  reservationNumbers: reservationNumbers,
98
98
  reservationFor: { ids: reservationForIds }
99
99
  },
100
- reserveIfNotYet: false
100
+ reserveIfNotYet: params.reserveIfNotYet
101
101
  })({
102
102
  action: repos.action,
103
103
  assetTransaction: repos.assetTransaction,
@@ -22,7 +22,8 @@ function call(data) {
22
22
  return (settings) => __awaiter(this, void 0, void 0, function* () {
23
23
  yield ReserveService.confirmReservation({
24
24
  actionAttributesList: data.actionAttributes,
25
- useOnReservationConfirmed: true
25
+ useOnReservationConfirmed: true,
26
+ byTask: true
26
27
  })({
27
28
  action: new action_1.MongoRepository(settings.connection),
28
29
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
@@ -11,6 +11,7 @@ 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 action_1 = require("../../repo/action");
14
+ const assetTransaction_1 = require("../../repo/assetTransaction");
14
15
  const order_1 = require("../../repo/order");
15
16
  const reservation_1 = require("../../repo/reservation");
16
17
  const task_1 = require("../../repo/task");
@@ -23,8 +24,9 @@ function call(data) {
23
24
  var _a, _b;
24
25
  yield (0, reserve_1.useReservation)(Object.assign(Object.assign({ project: data.project, agent: data.agent, object: data.object,
25
26
  // タスク作成前に検証済なので検証不要
26
- verifyToken: false }, (typeof ((_a = data.instrument) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { instrument: data.instrument } : undefined), (typeof ((_b = data.location) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { location: data.location } : undefined))({
27
+ verifyToken: false, reserveIfNotYet: data.reserveIfNotYet }, (typeof ((_a = data.instrument) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { instrument: data.instrument } : undefined), (typeof ((_b = data.location) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { location: data.location } : undefined))({
27
28
  action: new action_1.MongoRepository(settings.connection),
29
+ assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
28
30
  order: new order_1.MongoRepository(settings.connection),
29
31
  reservation: new reservation_1.MongoRepository(settings.connection),
30
32
  task: new task_1.MongoRepository(settings.connection)
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.21",
12
+ "@chevre/factory": "4.313.0-alpha.22",
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.86"
120
+ "version": "21.2.0-alpha.88"
121
121
  }