@chevre/domain 21.2.0-alpha.87 → 21.2.0-alpha.89
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.
- package/lib/chevre/repo/reservation.js +6 -2
- package/lib/chevre/service/payment/any.js +7 -0
- package/lib/chevre/service/reserve/checkInReservation.js +4 -4
- package/lib/chevre/service/reserve/confirmReservation.js +2 -2
- package/lib/chevre/service/reserve/useReservation.d.ts +2 -0
- package/lib/chevre/service/reserve/useReservation.js +47 -0
- package/lib/chevre/service/task/useReservation.js +2 -0
- package/package.json +1 -1
|
@@ -10,8 +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.MongoRepository = void 0;
|
|
13
|
+
const createDebug = require("debug");
|
|
13
14
|
const reservation_1 = require("./mongoose/schemas/reservation");
|
|
14
15
|
const factory = require("../factory");
|
|
16
|
+
const debug = createDebug('chevre-domain:repo');
|
|
15
17
|
/**
|
|
16
18
|
* 予約リポジトリ
|
|
17
19
|
*/
|
|
@@ -925,10 +927,12 @@ class MongoRepository {
|
|
|
925
927
|
}
|
|
926
928
|
confirmByIdIfNotExist(params) {
|
|
927
929
|
return __awaiter(this, void 0, void 0, function* () {
|
|
928
|
-
yield this.reservationModel.
|
|
930
|
+
const confirmedReservation = yield this.reservationModel.findOneAndUpdate({ _id: { $eq: params.reservation.id } }, {
|
|
929
931
|
$setOnInsert: Object.assign(Object.assign(Object.assign({}, params.reservation), { _id: params.reservation.id, reservationFor: params.reservationFor, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }), (params.underName !== undefined) ? { underName: params.underName } : undefined)
|
|
930
|
-
})
|
|
932
|
+
}, { new: true })
|
|
933
|
+
.select({ _id: 1 })
|
|
931
934
|
.exec();
|
|
935
|
+
debug('confirmByIdIfNotExist processed.confirmedReservation:', confirmedReservation);
|
|
932
936
|
});
|
|
933
937
|
}
|
|
934
938
|
/**
|
|
@@ -326,6 +326,13 @@ function authorize(params) {
|
|
|
326
326
|
}
|
|
327
327
|
// 即時に決済取引を中止するか?(2023-02-03~)
|
|
328
328
|
if (params.useCancelPayTransactionOnFailed) {
|
|
329
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
330
|
+
// TODO abortエラーの場合は状態不明なので即時中止しない
|
|
331
|
+
// {
|
|
332
|
+
// "type": "aborted",
|
|
333
|
+
// "message": "The user aborted a request.",
|
|
334
|
+
// "name": "AbortError"
|
|
335
|
+
// }
|
|
329
336
|
yield processVoidPayTransaction({
|
|
330
337
|
project: action.project,
|
|
331
338
|
agent: { id: action.project.id },
|
|
@@ -19,7 +19,7 @@ function checkInReservation(params) {
|
|
|
19
19
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
const now = new Date();
|
|
21
21
|
// confirmReservationが間に合わない可能性を考慮する(2023-06-01~)
|
|
22
|
-
debug('reserveIfNotYet?', params.reserveIfNotYet, params.object.ids, params.object.reservationNumbers);
|
|
22
|
+
debug('reserveIfNotYet?', params.reserveIfNotYet, 'ids:', params.object.ids, 'reservationNumbers:', params.object.reservationNumbers);
|
|
23
23
|
if (params.reserveIfNotYet === true) {
|
|
24
24
|
yield reserveIfNotYet(params)(repos);
|
|
25
25
|
}
|
|
@@ -74,7 +74,7 @@ function reserveIfNotYet(params) {
|
|
|
74
74
|
},
|
|
75
75
|
statuses: [factory.transactionStatusType.Confirmed]
|
|
76
76
|
}, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
|
|
77
|
-
debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet.', params.object.ids);
|
|
77
|
+
debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. ids:', params.object.ids);
|
|
78
78
|
}
|
|
79
79
|
if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
|
|
80
80
|
reserveTransactions = yield repos.assetTransaction.search({
|
|
@@ -84,7 +84,7 @@ function reserveIfNotYet(params) {
|
|
|
84
84
|
},
|
|
85
85
|
statuses: [factory.transactionStatusType.Confirmed]
|
|
86
86
|
}, ['_id', 'transactionNumber', 'object', 'project', 'typeOf']);
|
|
87
|
-
debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet.', params.object.reservationNumbers);
|
|
87
|
+
debug(reserveTransactions.length, 'reserveTransactions found in reserveIfNotYet. reservationNumbers:', params.object.reservationNumbers);
|
|
88
88
|
}
|
|
89
89
|
yield Promise.all(reserveTransactions.map((reserveTransaction) => __awaiter(this, void 0, void 0, function* () {
|
|
90
90
|
var _a;
|
|
@@ -107,7 +107,7 @@ function reserveIfNotYet(params) {
|
|
|
107
107
|
useOnReservationConfirmed: false,
|
|
108
108
|
byTask: false
|
|
109
109
|
})(repos);
|
|
110
|
-
debug('confirmReservation processed in reserveIfNotYet.', reserveTransaction.object.reservationNumber);
|
|
110
|
+
debug('confirmReservation processed in reserveIfNotYet. reservationNumber:', reserveTransaction.object.reservationNumber);
|
|
111
111
|
}
|
|
112
112
|
})));
|
|
113
113
|
});
|
|
@@ -54,7 +54,7 @@ function reserveIfNotYet(params, options) {
|
|
|
54
54
|
var _a;
|
|
55
55
|
const reservationPackage = params.object;
|
|
56
56
|
// 冪等性を担保(2023-05-31~)
|
|
57
|
-
debug('
|
|
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,7 +69,7 @@ function reserveIfNotYet(params, options) {
|
|
|
69
69
|
typeOf: { $in: [params.purpose.typeOf] }
|
|
70
70
|
}
|
|
71
71
|
}, ['_id'], []);
|
|
72
|
-
debug(completedActions.length, 'completed reserveAction found', options === null || options === void 0 ? void 0 : options.byTask, reservationPackage.reservationNumber);
|
|
72
|
+
debug(completedActions.length, 'completed reserveAction found. byTask:', options === null || options === void 0 ? void 0 : options.byTask, 'reservationNumber:', reservationPackage.reservationNumber);
|
|
73
73
|
if (completedActions.length === 0) {
|
|
74
74
|
const action = yield repos.action.start(params);
|
|
75
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';
|
|
@@ -28,6 +29,7 @@ export declare function useReservation(params: {
|
|
|
28
29
|
reserveIfNotYet: boolean;
|
|
29
30
|
}): (repos: {
|
|
30
31
|
action: ActionRepo;
|
|
32
|
+
assetTransaction: AssetTransactionRepo;
|
|
31
33
|
order: OrderRepo;
|
|
32
34
|
reservation: ReservationRepo;
|
|
33
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
|
+
}
|
|
@@ -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");
|
|
@@ -25,6 +26,7 @@ function call(data) {
|
|
|
25
26
|
// タスク作成前に検証済なので検証不要
|
|
26
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