@chevre/domain 21.2.0-alpha.81 → 21.2.0-alpha.82

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.
@@ -727,7 +727,10 @@ function confirm(params) {
727
727
  : undefined));
728
728
  if (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
729
729
  // sync対応(2023-01-13~)
730
- yield (0, confirmReservation_1.confirmReservation)(potentialActions.reserve)(repos);
730
+ yield (0, confirmReservation_1.confirmReservation)({
731
+ actionAttributesList: potentialActions.reserve,
732
+ useOnReservationConfirmed: true
733
+ })(repos);
731
734
  }
732
735
  });
733
736
  }
@@ -9,7 +9,10 @@ import { MongoRepository as TaskRepo } from '../../repo/task';
9
9
  /**
10
10
  * 予約を確定する
11
11
  */
12
- export declare function confirmReservation(actionAttributesList: factory.action.reserve.IAttributes[]): (repos: {
12
+ export declare function confirmReservation(params: {
13
+ actionAttributesList: factory.action.reserve.IAttributes[];
14
+ useOnReservationConfirmed: boolean;
15
+ }): (repos: {
13
16
  action: ActionRepo;
14
17
  assetTransaction: AssetTrasactionRepo;
15
18
  reservation: ReservationRepo;
@@ -18,106 +18,131 @@ const onReservationConfirmed_1 = require("./potentialActions/onReservationConfir
18
18
  /**
19
19
  * 予約を確定する
20
20
  */
21
- function confirmReservation(actionAttributesList) {
22
- // tslint:disable-next-line:max-func-body-length
21
+ function confirmReservation(params) {
23
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
- let confirmedReservations = [];
25
- if (actionAttributesList.length > 0) {
26
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
27
- var _a;
28
- const reservationPackage = actionAttributes.object;
29
- const action = yield repos.action.start(actionAttributes);
30
- try {
31
- const reserveTransactions = yield repos.assetTransaction.search({
32
- limit: 1,
33
- page: 1,
34
- typeOf: factory.assetTransactionType.Reserve,
35
- transactionNumber: { $eq: reservationPackage.reservationNumber }
23
+ if (params.actionAttributesList.length > 0) {
24
+ yield Promise.all(params.actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
25
+ yield reserveIfNotYet(actionAttributes)(repos);
26
+ if (params.useOnReservationConfirmed) {
27
+ yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
28
+ }
29
+ })));
30
+ if (params.useOnReservationConfirmed) {
31
+ let confirmedReservations = [];
32
+ // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
33
+ const reservationNumber = params.actionAttributesList[0].object.reservationNumber;
34
+ if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
35
+ // 最新のconfirmedReservationsを検索
36
+ confirmedReservations = yield repos.reservation.search({
37
+ reservationNumber: { $eq: reservationNumber },
38
+ typeOf: factory.reservationType.EventReservation
36
39
  });
37
- const reserveTransaction = reserveTransactions.shift();
38
- if (reserveTransaction === undefined) {
39
- throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
40
- }
41
- let underName;
42
- // 予約取引に保管されたunderNameを使用する(2023-05-30~)
43
- if (typeof ((_a = reserveTransaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
44
- underName = reserveTransaction.object.underName;
45
- // 廃止(2023-05-31~)→予約取引から取得に変更
46
- // } else if (typeof reservationPackage.underName?.typeOf === 'string') {
47
- // underName = reservationPackage.underName;
48
- }
49
- // ReservationPackageに対応(2022-12-22~)
50
- if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
51
- // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
52
- if (reserveTransaction.object.disablePendingReservations === true) {
53
- const reservationFor = reserveTransaction.object.reservationFor;
54
- const subReservations = reserveTransaction.object.subReservation;
55
- if (Array.isArray(subReservations)
56
- && typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.typeOf) === 'string') {
57
- yield Promise.all(subReservations.map((subReservation) => __awaiter(this, void 0, void 0, function* () {
58
- yield repos.reservation.confirmByIdIfNotExist({
59
- reservation: subReservation,
60
- reservationFor,
61
- underName
62
- });
63
- })));
64
- }
65
- }
66
- else {
67
- // 予約を確定状態に変更する
68
- yield repos.reservation.confirmByReservationNumber({
69
- reservationNumber: reservationPackage.reservationNumber,
70
- previousReservationStatus: reservationPackage.reservationStatus,
71
- underName
72
- });
40
+ confirmedReservations = confirmedReservations.map((r) => {
41
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
42
+ delete r._id;
43
+ return r;
44
+ });
45
+ }
46
+ yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
47
+ }
48
+ }
49
+ });
50
+ }
51
+ exports.confirmReservation = confirmReservation;
52
+ // tslint:disable-next-line:max-func-body-length
53
+ function reserveIfNotYet(params) {
54
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
55
+ var _a;
56
+ const reservationPackage = params.object;
57
+ // 冪等性を担保(2023-05-31~)
58
+ const completedActions = yield repos.action.search({
59
+ limit: 1,
60
+ page: 1,
61
+ typeOf: { $eq: params.typeOf },
62
+ object: {
63
+ typeOf: { $eq: params.object.typeOf }
64
+ // reservationNumber: { $eq: params.object.reservationNumber }
65
+ },
66
+ purpose: {
67
+ id: { $in: [params.purpose.id] },
68
+ typeOf: { $in: [params.purpose.typeOf] }
69
+ }
70
+ }, ['_id'], []);
71
+ if (completedActions.length === 0) {
72
+ const action = yield repos.action.start(params);
73
+ try {
74
+ const reserveTransactions = yield repos.assetTransaction.search({
75
+ limit: 1,
76
+ page: 1,
77
+ typeOf: factory.assetTransactionType.Reserve,
78
+ transactionNumber: { $eq: reservationPackage.reservationNumber }
79
+ });
80
+ const reserveTransaction = reserveTransactions.shift();
81
+ if (reserveTransaction === undefined) {
82
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
83
+ }
84
+ let underName;
85
+ // 予約取引に保管されたunderNameを使用する(2023-05-30~)
86
+ if (typeof ((_a = reserveTransaction.object.underName) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') {
87
+ underName = reserveTransaction.object.underName;
88
+ // 廃止(2023-05-31~)→予約取引から取得に変更
89
+ // } else if (typeof reservationPackage.underName?.typeOf === 'string') {
90
+ // underName = reservationPackage.underName;
91
+ }
92
+ // ReservationPackageに対応(2022-12-22~)
93
+ if (reservationPackage.typeOf === factory.reservationType.ReservationPackage) {
94
+ // Pendingの予約が存在しないバージョンに対応する(2023-05-29~)
95
+ if (reserveTransaction.object.disablePendingReservations === true) {
96
+ const reservationFor = reserveTransaction.object.reservationFor;
97
+ const subReservations = reserveTransaction.object.subReservation;
98
+ if (Array.isArray(subReservations)
99
+ && typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.typeOf) === 'string') {
100
+ yield Promise.all(subReservations.map((subReservation) => __awaiter(this, void 0, void 0, function* () {
101
+ yield repos.reservation.confirmByIdIfNotExist({
102
+ reservation: subReservation,
103
+ reservationFor,
104
+ underName
105
+ });
106
+ })));
73
107
  }
74
108
  }
75
109
  else {
76
- // 廃止(2023-01-18)
77
- throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
78
110
  // 予約を確定状態に変更する
79
- // await repos.reservation.confirm<factory.reservationType.EventReservation>({
80
- // id: reservation.id,
81
- // previousReservationStatus: reservation.reservationStatus,
82
- // underName: reservation.underName
83
- // });
84
- // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
85
- // delete (<any>reservation)._id;
86
- // confirmedReservations.push(reservation);
111
+ yield repos.reservation.confirmByReservationNumber({
112
+ reservationNumber: reservationPackage.reservationNumber,
113
+ previousReservationStatus: reservationPackage.reservationStatus,
114
+ underName
115
+ });
87
116
  }
88
117
  }
89
- catch (error) {
90
- // actionにエラー結果を追加
91
- try {
92
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
93
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
94
- }
95
- catch (__) {
96
- // 失敗したら仕方ない
97
- }
98
- throw error;
99
- }
100
- // アクション完了
101
- const actionResult = {};
102
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
103
- yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
104
- })));
105
- // 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
106
- const reservationNumber = actionAttributesList[0].object.reservationNumber;
107
- if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
108
- // 最新のconfirmedReservationsを検索
109
- confirmedReservations = yield repos.reservation.search({
110
- reservationNumber: { $eq: reservationNumber },
111
- typeOf: factory.reservationType.EventReservation
112
- });
113
- confirmedReservations = confirmedReservations.map((r) => {
118
+ else {
119
+ // 廃止(2023-01-18)
120
+ throw new factory.errors.Forbidden(`${reservationPackage.typeOf} not acceptable`);
121
+ // 予約を確定状態に変更する
122
+ // await repos.reservation.confirm<factory.reservationType.EventReservation>({
123
+ // id: reservation.id,
124
+ // previousReservationStatus: reservation.reservationStatus,
125
+ // underName: reservation.underName
126
+ // });
114
127
  // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
115
- delete r._id;
116
- return r;
117
- });
128
+ // delete (<any>reservation)._id;
129
+ // confirmedReservations.push(reservation);
130
+ }
131
+ }
132
+ catch (error) {
133
+ // actionにエラー結果を追加
134
+ try {
135
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
136
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
137
+ }
138
+ catch (__) {
139
+ // 失敗したら仕方ない
140
+ }
141
+ throw error;
118
142
  }
119
- yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
143
+ // アクション完了
144
+ const actionResult = {};
145
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
120
146
  }
121
147
  });
122
148
  }
123
- exports.confirmReservation = confirmReservation;
@@ -20,7 +20,10 @@ const ReserveService = require("../reserve");
20
20
  */
21
21
  function call(data) {
22
22
  return (settings) => __awaiter(this, void 0, void 0, function* () {
23
- yield ReserveService.confirmReservation(data.actionAttributes)({
23
+ yield ReserveService.confirmReservation({
24
+ actionAttributesList: data.actionAttributes,
25
+ useOnReservationConfirmed: true
26
+ })({
24
27
  action: new action_1.MongoRepository(settings.connection),
25
28
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
26
29
  reservation: new reservation_1.MongoRepository(settings.connection),
package/package.json CHANGED
@@ -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.81"
120
+ "version": "21.2.0-alpha.82"
121
121
  }