@chevre/domain 21.37.0-alpha.8 → 21.37.0
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/example/src/chevre/processOrder.ts +87 -0
- package/example/src/chevre/transaction/processPlaceOrder.ts +17 -143
- package/lib/chevre/factory/reservedAgentIdentifireNames.js +2 -1
- package/lib/chevre/factory/transaction.d.ts +1 -4
- package/lib/chevre/repo/passport.d.ts +39 -0
- package/lib/chevre/repo/passport.js +134 -0
- package/lib/chevre/repo/task.d.ts +9 -0
- package/lib/chevre/repo/task.js +23 -2
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/lib/chevre/service/accountTransaction/deposit.js +0 -1
- package/lib/chevre/service/accountTransaction/transfer.js +0 -1
- package/lib/chevre/service/accountTransaction/withdraw.js +0 -1
- package/lib/chevre/service/assetTransaction/reserve/cancel.d.ts +22 -0
- package/lib/chevre/service/assetTransaction/reserve/cancel.js +41 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm/factory.d.ts +8 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm/factory.js +94 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm.d.ts +19 -0
- package/lib/chevre/service/assetTransaction/reserve/confirm.js +93 -0
- package/lib/chevre/service/assetTransaction/reserve/exportTasksById.d.ts +15 -0
- package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +99 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.d.ts +28 -0
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +405 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.d.ts +15 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.js +40 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.d.ts +54 -0
- package/lib/chevre/service/assetTransaction/reserve/{factory.js → start/factory/createReservation.js} +3 -222
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.d.ts +22 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +90 -0
- package/lib/chevre/service/assetTransaction/reserve/{factory → start/factory}/price.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/reserve/{factory → start/factory}/price.js +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +74 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +570 -0
- package/lib/chevre/service/assetTransaction/reserve.d.ts +6 -128
- package/lib/chevre/service/assetTransaction/reserve.js +9 -1047
- package/lib/chevre/service/offer/event/{defaultOffer.d.ts → authorize/defaultOffer.d.ts} +1 -1
- package/lib/chevre/service/offer/event/{defaultOffer.js → authorize/defaultOffer.js} +1 -1
- package/lib/chevre/service/offer/event/{factory.d.ts → authorize/factory.d.ts} +13 -20
- package/lib/chevre/service/offer/event/{factory.js → authorize/factory.js} +72 -146
- package/lib/chevre/service/offer/event/{processStartReserve4chevre.d.ts → authorize/processStartReserve4chevre.d.ts} +19 -19
- package/lib/chevre/service/offer/event/{processStartReserve4chevre.js → authorize/processStartReserve4chevre.js} +8 -13
- package/lib/chevre/service/offer/event/authorize.d.ts +1 -1
- package/lib/chevre/service/offer/event/authorize.js +104 -128
- package/lib/chevre/service/offer/event/importFromCOA/factory.d.ts +9 -0
- package/lib/chevre/service/offer/event/importFromCOA/factory.js +67 -0
- package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +0 -3
- package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +3 -3
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +4 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.d.ts +16 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +168 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +4 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -135
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +2 -1
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +3 -2
- package/lib/chevre/service/transaction/moneyTransfer.js +1 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/start/factory.d.ts +10 -0
- package/lib/chevre/service/transaction/placeOrderInProgress/start/factory.js +36 -0
- package/lib/chevre/service/transaction/placeOrderInProgress/start.d.ts +6 -1
- package/lib/chevre/service/transaction/placeOrderInProgress/start.js +26 -12
- package/lib/chevre/service/validation/validateOrder.js +1 -1
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +5 -1
- package/package.json +3 -3
- package/example/src/chevre/migrateAuthorizeEventServiceOfferResult.ts +0 -163
- package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +0 -96
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +0 -2
- package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +0 -29
- package/lib/chevre/service/transaction/validation.d.ts +0 -14
- package/lib/chevre/service/transaction/validation.js +0 -101
|
@@ -1,1052 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.exportTasksById = exports.
|
|
3
|
+
exports.exportTasksById = exports.start = exports.confirm = exports.cancel = void 0;
|
|
13
4
|
/**
|
|
14
5
|
* 予約取引サービス
|
|
15
6
|
*/
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const factory_1 = require("./reserve/factory");
|
|
25
|
-
const validateStartRequest_1 = require("./reserve/validateStartRequest");
|
|
26
|
-
const ONE_MONTH_IN_DAYS = 31;
|
|
27
|
-
/**
|
|
28
|
-
* 取引開始
|
|
29
|
-
*/
|
|
30
|
-
function start(params) {
|
|
31
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
var _a, _b, _c, _d;
|
|
33
|
-
const now = new Date();
|
|
34
|
-
const reservationNumber = params.transactionNumber;
|
|
35
|
-
if (typeof reservationNumber !== 'string' || reservationNumber.length === 0) {
|
|
36
|
-
throw new factory.errors.ArgumentNull('transactionNumber'); // 自動発行廃止(2022-05-17~)
|
|
37
|
-
}
|
|
38
|
-
// eventをfix
|
|
39
|
-
const reservationForId = (_a = params.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id;
|
|
40
|
-
if (typeof reservationForId !== 'string' || reservationForId.length === 0) {
|
|
41
|
-
throw new factory.errors.ArgumentNull('object.reservationFor.id');
|
|
42
|
-
}
|
|
43
|
-
let event;
|
|
44
|
-
if (typeof ((_b = params.preSearchedEvent) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') {
|
|
45
|
-
event = params.preSearchedEvent;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
event = yield repos.event.findMinimizedIndividualEventById({ id: reservationForId });
|
|
49
|
-
}
|
|
50
|
-
// validationを承認アクション開始前から移行(2023-01-27~)
|
|
51
|
-
(0, validateStartRequest_1.validateStartRequest)({
|
|
52
|
-
object: params.object,
|
|
53
|
-
event,
|
|
54
|
-
validateEventOfferPeriod: params.validateEventOfferPeriod,
|
|
55
|
-
validateEvent: params.validateEvent,
|
|
56
|
-
now,
|
|
57
|
-
store: { id: (_c = params.availableAtOrFrom) === null || _c === void 0 ? void 0 : _c.id }
|
|
58
|
-
});
|
|
59
|
-
const startParams = (0, factory_1.createStartParams)(Object.assign(Object.assign({}, params), { provider: { id: event.organizer.id }, reservationNumber,
|
|
60
|
-
event }));
|
|
61
|
-
// objectに必要な情報をそろえる
|
|
62
|
-
const { acceptedOffers4transactionObject, objectSubReservations } = yield createObjectAttributes({
|
|
63
|
-
reservationFor: startParams.object.reservationFor,
|
|
64
|
-
transaction: { transactionNumber: reservationNumber },
|
|
65
|
-
now,
|
|
66
|
-
object: params.object,
|
|
67
|
-
event,
|
|
68
|
-
preSearchedTicketOffers: params.preSearchedTicketOffers,
|
|
69
|
-
preSearchedUnitPriceOffers: params.preSearchedUnitPriceOffers,
|
|
70
|
-
availableAtOrFrom: { id: (_d = params.availableAtOrFrom) === null || _d === void 0 ? void 0 : _d.id },
|
|
71
|
-
validateAppliesToMovieTicket: params.validateAppliesToMovieTicket,
|
|
72
|
-
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd
|
|
73
|
-
})(repos);
|
|
74
|
-
// reimplement using startWithMinimalResponse(2024-07-02~)
|
|
75
|
-
// const transaction = await repos.assetTransaction.start<factory.assetTransactionType.Reserve>(startParams);
|
|
76
|
-
const { id } = yield repos.assetTransaction.startWithMinimalResponse(startParams);
|
|
77
|
-
// let objectSubReservations: IObjectSubReservation[] = [];
|
|
78
|
-
// const addReservationsResult = await addReservations({
|
|
79
|
-
yield addReservations({
|
|
80
|
-
reservationFor: startParams.object.reservationFor,
|
|
81
|
-
transaction: { id, transactionNumber: reservationNumber },
|
|
82
|
-
event,
|
|
83
|
-
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd,
|
|
84
|
-
acceptedOffers4transactionObject, objectSubReservations
|
|
85
|
-
})(repos);
|
|
86
|
-
// transaction = addReservationsResult.transaction;
|
|
87
|
-
// objectSubReservations = addReservationsResult.objectSubReservations;
|
|
88
|
-
return {
|
|
89
|
-
transaction: { id },
|
|
90
|
-
objectSubReservations,
|
|
91
|
-
// issuedThrough: addReservationsResult.issuedThrough
|
|
92
|
-
issuedThrough: startParams.object.issuedThrough
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
exports.start = start;
|
|
97
|
-
function createObjectAttributes(params) {
|
|
98
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
var _a;
|
|
100
|
-
const { event, now } = params;
|
|
101
|
-
const reservationNumber = params.transaction.transactionNumber;
|
|
102
|
-
const acceptedOffers = (Array.isArray(params.object.acceptedOffer)) ? params.object.acceptedOffer : [];
|
|
103
|
-
if (event.typeOf !== factory.eventType.ScreeningEvent && event.typeOf !== factory.eventType.Event) {
|
|
104
|
-
throw new factory.errors.Argument('object.reservationFor.id', `invalid event type ${event.typeOf}`);
|
|
105
|
-
}
|
|
106
|
-
if (event.typeOf === factory.eventType.ScreeningEvent || event.typeOf === factory.eventType.Event) {
|
|
107
|
-
validateEvent({ now, event });
|
|
108
|
-
}
|
|
109
|
-
// 受け入れたオファーIDだけ取得する(2023-01-26~)
|
|
110
|
-
const acceptedOfferIds = [...new Set(acceptedOffers.map((o) => String(o.id)))];
|
|
111
|
-
let ticketOffers;
|
|
112
|
-
let availableOffers;
|
|
113
|
-
// 承認アクションを介した予約取引開始時の冗長なオファー検索処理について最適化(2023-01-27~)
|
|
114
|
-
if (Array.isArray(params.preSearchedTicketOffers) && Array.isArray(params.preSearchedUnitPriceOffers)) {
|
|
115
|
-
ticketOffers = params.preSearchedTicketOffers;
|
|
116
|
-
availableOffers = params.preSearchedUnitPriceOffers;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
// 興行オファー検索
|
|
120
|
-
const searchEventTicketOffersResult = yield OfferService.event.searchEventTicketOffers({
|
|
121
|
-
ids: acceptedOfferIds,
|
|
122
|
-
event: { id: event.id },
|
|
123
|
-
// 対応アプリケーション条件追加(2023-01-27~)
|
|
124
|
-
store: { id: (_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id },
|
|
125
|
-
priceSpecification: {},
|
|
126
|
-
includedInDataCatalog: { id: '' },
|
|
127
|
-
onlyValid: true,
|
|
128
|
-
addSortIndex: false,
|
|
129
|
-
validateOfferRateLimit: true,
|
|
130
|
-
useIncludeInDataCatalog: false
|
|
131
|
-
})(repos);
|
|
132
|
-
ticketOffers = searchEventTicketOffersResult.ticketOffers;
|
|
133
|
-
availableOffers = searchEventTicketOffersResult.unitPriceOffers;
|
|
134
|
-
}
|
|
135
|
-
const availableSeatOffers = yield searchAvailableSeatOffers({ acceptedOffers, event })(repos);
|
|
136
|
-
return createAcceptedOffers4transactionObject({
|
|
137
|
-
acceptedOffers, ticketOffers, availableOffers, now,
|
|
138
|
-
event, availableSeatOffers, reservationNumber,
|
|
139
|
-
availableAtOrFrom: params.availableAtOrFrom,
|
|
140
|
-
validateAppliesToMovieTicket: params.validateAppliesToMovieTicket
|
|
141
|
-
})(repos);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 予約追加
|
|
146
|
-
*/
|
|
147
|
-
function addReservations(params) {
|
|
148
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
const reservationNumber = params.transaction.transactionNumber;
|
|
150
|
-
const { event, reservationFor, acceptedOffers4transactionObject, objectSubReservations } = params;
|
|
151
|
-
// 取引に予約追加
|
|
152
|
-
let lockedOfferRateLimitKeys = [];
|
|
153
|
-
try {
|
|
154
|
-
lockedOfferRateLimitKeys = yield processLockOfferRateLimit({
|
|
155
|
-
reservations: objectSubReservations,
|
|
156
|
-
reservationFor,
|
|
157
|
-
reservationNumber
|
|
158
|
-
})(repos);
|
|
159
|
-
// 上書きの必要なし(2024-07-01~)
|
|
160
|
-
// transaction = await repos.assetTransaction.addReservations({
|
|
161
|
-
yield repos.assetTransaction.addReservations({
|
|
162
|
-
typeOf: factory.assetTransactionType.Reserve,
|
|
163
|
-
id: params.transaction.id,
|
|
164
|
-
object: {
|
|
165
|
-
acceptedOffer: acceptedOffers4transactionObject,
|
|
166
|
-
// issuedThroughを追加(2023-06-05~)
|
|
167
|
-
// issuedThrough, // start時保管へ移行(2024-07-01~)
|
|
168
|
-
// reservationFor, // start時保管へ移行(2024-07-01~)
|
|
169
|
-
subReservation: objectSubReservations
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
if (lockedOfferRateLimitKeys.length > 0) {
|
|
175
|
-
yield Promise.all(objectSubReservations.map((reservation) => __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
yield (0, cancelReservation_1.processUnlockOfferRateLimit)({
|
|
177
|
-
reservation: {
|
|
178
|
-
reservationNumber,
|
|
179
|
-
reservedTicket: reservation.reservedTicket
|
|
180
|
-
},
|
|
181
|
-
reservationFor
|
|
182
|
-
})(repos);
|
|
183
|
-
})));
|
|
184
|
-
}
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
// 座席指定でも座席ロック
|
|
188
|
-
// イベントキャパシティ設定のみでも座席ロック
|
|
189
|
-
yield processLockSeats({
|
|
190
|
-
event: event,
|
|
191
|
-
reservations: objectSubReservations,
|
|
192
|
-
transaction: {
|
|
193
|
-
id: params.transaction.id,
|
|
194
|
-
transactionNumber: params.transaction.transactionNumber
|
|
195
|
-
// object: { useHoldStockByTransactionNumber: transaction.object.useHoldStockByTransactionNumber === true }
|
|
196
|
-
},
|
|
197
|
-
stockHoldUntilDaysAfterEventEnd: params.stockHoldUntilDaysAfterEventEnd
|
|
198
|
-
})(repos);
|
|
199
|
-
// ストックホルダー処理(stockHolderで残席数を集計しているので必要)
|
|
200
|
-
yield onReservationsCreated({ event, transaction: { transactionNumber: reservationNumber } })(repos);
|
|
201
|
-
// return { objectSubReservations };
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* イベントに対する座席オファーを座席コードとセクションコード指定で検索する
|
|
206
|
-
*/
|
|
207
|
-
function searchEventSeatOffers(params) {
|
|
208
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
var _a, _b, _c, _d, _e, _f;
|
|
210
|
-
let offers = [];
|
|
211
|
-
// 座席指定利用可能かどうか
|
|
212
|
-
const eventOffers = params.event.offers;
|
|
213
|
-
const reservedSeatsAvailable = ((_b = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) !== undefined;
|
|
214
|
-
if (reservedSeatsAvailable) {
|
|
215
|
-
// 座席タイプ価格仕様を検索
|
|
216
|
-
const priceSpecs = yield repos.priceSpecification.search({
|
|
217
|
-
project: { id: { $eq: params.event.project.id } },
|
|
218
|
-
typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
|
|
219
|
-
appliesToCategoryCode: {
|
|
220
|
-
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } }
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
const roomBranchCode = String((_d = (_c = eventOffers.itemOffered) === null || _c === void 0 ? void 0 : _c.availableChannel) === null || _d === void 0 ? void 0 : _d.serviceLocation.branchCode);
|
|
224
|
-
const movieTheaterBranchCode = String((_f = (_e = eventOffers.itemOffered) === null || _e === void 0 ? void 0 : _e.availableChannel) === null || _f === void 0 ? void 0 : _f.serviceLocation.containedInPlace.branchCode);
|
|
225
|
-
const seats = yield repos.seat.searchSeats({
|
|
226
|
-
project: { id: { $eq: params.event.project.id } },
|
|
227
|
-
branchCode: { $in: params.branchCode.$in },
|
|
228
|
-
containedInPlace: {
|
|
229
|
-
branchCode: {
|
|
230
|
-
$in: params.containedInPlace.branchCode.$in
|
|
231
|
-
},
|
|
232
|
-
containedInPlace: {
|
|
233
|
-
branchCode: { $eq: roomBranchCode },
|
|
234
|
-
containedInPlace: {
|
|
235
|
-
branchCode: { $eq: movieTheaterBranchCode }
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
$projection: Object.assign({}, params.$projection)
|
|
240
|
-
});
|
|
241
|
-
if (seats.length > 0) {
|
|
242
|
-
const availabilities = yield repos.stockHolder.searchHolders({
|
|
243
|
-
project: { id: params.event.project.id },
|
|
244
|
-
eventId: params.event.id,
|
|
245
|
-
startDate: moment(params.event.startDate)
|
|
246
|
-
.toDate(),
|
|
247
|
-
hasTicketedSeat: true,
|
|
248
|
-
offers: seats.map((s) => {
|
|
249
|
-
var _a;
|
|
250
|
-
return {
|
|
251
|
-
seatNumber: s.branchCode,
|
|
252
|
-
seatSection: (_a = s.containedInPlace) === null || _a === void 0 ? void 0 : _a.branchCode
|
|
253
|
-
};
|
|
254
|
-
})
|
|
255
|
-
});
|
|
256
|
-
offers = seats.map((seat, index) => {
|
|
257
|
-
return OfferService.addOffers2Seat({
|
|
258
|
-
seat,
|
|
259
|
-
// unavailableOffers: [],
|
|
260
|
-
// availability: availabilities[index].availability,
|
|
261
|
-
availability: (typeof availabilities[index] === 'string')
|
|
262
|
-
? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
|
|
263
|
-
: factory.itemAvailability.InStock,
|
|
264
|
-
priceSpecs
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return offers;
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
function searchAvailableSeatOffers(params) {
|
|
273
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
274
|
-
// 座席オファー検索(必要な分だけ)
|
|
275
|
-
const { acceptedSeatNumbers, acceptedSeatSections } = getAcceptedSeatNumbersAndSeatSections({ acceptedOffers: params.acceptedOffers });
|
|
276
|
-
return searchEventSeatOffers({
|
|
277
|
-
branchCode: { $in: acceptedSeatNumbers },
|
|
278
|
-
containedInPlace: { branchCode: { $in: acceptedSeatSections } },
|
|
279
|
-
event: params.event,
|
|
280
|
-
// 試しに冗長な情報を非取得にしてみる
|
|
281
|
-
$projection: {
|
|
282
|
-
'containedInPlace.containedInPlace': 0
|
|
283
|
-
}
|
|
284
|
-
})(repos);
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
function validateEvent(params) {
|
|
288
|
-
// キャンセルステータスであれば予約不可
|
|
289
|
-
if (params.event.eventStatus === factory.eventStatusType.EventCancelled) {
|
|
290
|
-
throw new factory.errors.Argument('Event', `Event status ${params.event.eventStatus}`);
|
|
291
|
-
}
|
|
292
|
-
// 予約取引開始可能なイベント開始日時範囲を明確に制限(2024-03-11~)
|
|
293
|
-
const reservableThrough = moment(params.now)
|
|
294
|
-
.add(settings_1.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS, 'days');
|
|
295
|
-
const reservableFrom = moment(params.now)
|
|
296
|
-
.add(-ONE_MONTH_IN_DAYS, 'days');
|
|
297
|
-
if (!moment(params.event.startDate)
|
|
298
|
-
.isBetween(reservableFrom, reservableThrough, 'second', '[]')) {
|
|
299
|
-
throw new factory.errors.Argument('Event', `bookingTime must be between ${settings_1.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS} days before and ${ONE_MONTH_IN_DAYS} days after the event start date`);
|
|
300
|
-
}
|
|
301
|
-
// イベントが一定期間後であれば予約不可
|
|
302
|
-
// if (moment(params.event.startDate)
|
|
303
|
-
// .isAfter(reservableThrough)) {
|
|
304
|
-
// throw new factory.errors.Argument(
|
|
305
|
-
// 'Event',
|
|
306
|
-
// `Maximum reservation grace period is ${MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS} days`
|
|
307
|
-
// );
|
|
308
|
-
// }
|
|
309
|
-
}
|
|
310
|
-
function createAcceptedOffers4transactionObject(params) {
|
|
311
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
312
|
-
// 予約番号
|
|
313
|
-
// const reservationNumber = params.transaction.object.reservationNumber;
|
|
314
|
-
const reservationNumber = params.reservationNumber;
|
|
315
|
-
if (typeof reservationNumber !== 'string') {
|
|
316
|
-
throw new factory.errors.Internal('Reservation number undefined');
|
|
317
|
-
}
|
|
318
|
-
const objectSubReservations = yield createReservations4transactionObject(params)(repos);
|
|
319
|
-
const acceptedOffers4transactionObject = [];
|
|
320
|
-
let reservationIndex = -1;
|
|
321
|
-
for (const acceptedOffer of params.acceptedOffers) {
|
|
322
|
-
reservationIndex += 1;
|
|
323
|
-
const ticketOffer = params.ticketOffers.find((t) => t.id === acceptedOffer.id);
|
|
324
|
-
if (ticketOffer === undefined) {
|
|
325
|
-
throw new factory.errors.NotFound('Ticket Offer');
|
|
326
|
-
}
|
|
327
|
-
const reservationId = `${reservationNumber}-${reservationIndex}`;
|
|
328
|
-
// 入金先検証
|
|
329
|
-
yield validatePointAward({ project: { id: params.event.project.id }, acceptedOffer })(repos);
|
|
330
|
-
const pointAward = (0, factory_1.createPointAward)({
|
|
331
|
-
project: { id: params.event.project.id },
|
|
332
|
-
acceptedOffer: acceptedOffer,
|
|
333
|
-
offer: ticketOffer,
|
|
334
|
-
reservation: { id: reservationId }
|
|
335
|
-
});
|
|
336
|
-
// acceptedOffers4transactionObjectには必要な情報のみ保管する
|
|
337
|
-
acceptedOffers4transactionObject.push({
|
|
338
|
-
id: acceptedOffer.id,
|
|
339
|
-
itemOffered: Object.assign(Object.assign({}, (pointAward !== undefined) ? { pointAward } : undefined), { serviceOutput: { id: reservationId } })
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
return { acceptedOffers4transactionObject, objectSubReservations };
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
function createReservations4transactionObject(params) {
|
|
346
|
-
// tslint:disable-next-line:max-func-body-length
|
|
347
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
348
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
349
|
-
// 予約番号
|
|
350
|
-
// const reservationNumber = params.transaction.object.reservationNumber;
|
|
351
|
-
const reservationNumber = params.reservationNumber;
|
|
352
|
-
if (typeof reservationNumber !== 'string') {
|
|
353
|
-
throw new factory.errors.Internal('Reservation number undefined');
|
|
354
|
-
}
|
|
355
|
-
// 指定席のみかどうか
|
|
356
|
-
const eventOffers = params.event.offers;
|
|
357
|
-
const reservedSeatsOnly = ((_b = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) !== undefined;
|
|
358
|
-
const reservations = [];
|
|
359
|
-
let reservationIndex = -1;
|
|
360
|
-
for (const acceptedOffer of params.acceptedOffers) {
|
|
361
|
-
reservationIndex += 1;
|
|
362
|
-
const reservationId = `${reservationNumber}-${reservationIndex}`;
|
|
363
|
-
const ticketOffer = params.ticketOffers.find((t) => t.id === acceptedOffer.id);
|
|
364
|
-
if (ticketOffer === undefined) {
|
|
365
|
-
throw new factory.errors.NotFound('Ticket Offer');
|
|
366
|
-
}
|
|
367
|
-
const ticketType = params.availableOffers.find((o) => o.id === acceptedOffer.id);
|
|
368
|
-
if (ticketType === undefined) {
|
|
369
|
-
throw new factory.errors.NotFound(ticketOffer.typeOf);
|
|
370
|
-
}
|
|
371
|
-
// 事前予約要件検証(2023-08-10~)
|
|
372
|
-
validateAdvanceBookingRequirement({
|
|
373
|
-
unitPriceOffer: ticketType,
|
|
374
|
-
now: params.now,
|
|
375
|
-
reservationFor: params.event
|
|
376
|
-
});
|
|
377
|
-
const programMembershipUsed = yield validateProgramMembershipUsed({
|
|
378
|
-
acceptedOffer,
|
|
379
|
-
project: { id: params.event.project.id }
|
|
380
|
-
})(repos);
|
|
381
|
-
// チケット作成
|
|
382
|
-
const reservedTicket = (0, factory_1.createReservedTicket)({
|
|
383
|
-
id: reservationId,
|
|
384
|
-
acceptedOffer: acceptedOffer,
|
|
385
|
-
availableOffer: ticketType,
|
|
386
|
-
dateIssued: params.now,
|
|
387
|
-
reservationFor: { id: params.event.id },
|
|
388
|
-
reservedSeatsOnly,
|
|
389
|
-
availableSeatOffers: params.availableSeatOffers,
|
|
390
|
-
ticketOffer: ticketOffer
|
|
391
|
-
});
|
|
392
|
-
const additionalTicketText = (0, factory_1.createAdditionalTicketText)({ acceptedOffer, reservedTicket });
|
|
393
|
-
const additionalProperty = (0, factory_1.createAdditionalProperty)({ acceptedOffer });
|
|
394
|
-
// 座席指定であれば、座席タイプチャージを検索する
|
|
395
|
-
const seatPriceComponent = [];
|
|
396
|
-
// 区分加算料金を適用しないオプションを追加(2023-01-26~)
|
|
397
|
-
const ignoreCategoryCodeChargeSpec = ((_c = ticketType.settings) === null || _c === void 0 ? void 0 : _c.ignoreCategoryCodeChargeSpec) === true;
|
|
398
|
-
if (!ignoreCategoryCodeChargeSpec) {
|
|
399
|
-
const seatSection = (_d = reservedTicket.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatSection;
|
|
400
|
-
const seatNumber = (_e = reservedTicket.ticketedSeat) === null || _e === void 0 ? void 0 : _e.seatNumber;
|
|
401
|
-
if (typeof seatSection === 'string' && typeof seatNumber === 'string') {
|
|
402
|
-
const offersOnSeat = (_f = params.availableSeatOffers.find((o) => {
|
|
403
|
-
var _a;
|
|
404
|
-
return o.branchCode === seatNumber && ((_a = o.containedInPlace) === null || _a === void 0 ? void 0 : _a.branchCode) === seatSection;
|
|
405
|
-
})) === null || _f === void 0 ? void 0 : _f.offers;
|
|
406
|
-
if (Array.isArray(offersOnSeat)) {
|
|
407
|
-
const availableSeatOffer = offersOnSeat[0];
|
|
408
|
-
const seatPriceSpecs = (_g = availableSeatOffer === null || availableSeatOffer === void 0 ? void 0 : availableSeatOffer.priceSpecification) === null || _g === void 0 ? void 0 : _g.priceComponent;
|
|
409
|
-
if (Array.isArray(seatPriceSpecs)) {
|
|
410
|
-
seatPriceComponent.push(...seatPriceSpecs);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
// 指定されたアドオンがオファーに存在すれば、アドオンの単価仕様作成
|
|
416
|
-
const acceptedAddOns = [];
|
|
417
|
-
let availableAddOns;
|
|
418
|
-
const acceptedAddOnsParams = acceptedOffer.addOn;
|
|
419
|
-
if (Array.isArray(acceptedAddOnsParams) && acceptedAddOnsParams.length > 0) {
|
|
420
|
-
// アドオンオファー検索(2023-03-02~)
|
|
421
|
-
availableAddOns = yield searchAvailableAddOns({
|
|
422
|
-
ids: acceptedAddOnsParams.map((acceptedAddOn) => String(acceptedAddOn.id)),
|
|
423
|
-
project: { id: params.event.project.id },
|
|
424
|
-
ticketOffer,
|
|
425
|
-
availableAtOrFrom: params.availableAtOrFrom
|
|
426
|
-
})(repos);
|
|
427
|
-
}
|
|
428
|
-
if (Array.isArray(availableAddOns) && Array.isArray(acceptedAddOnsParams)) {
|
|
429
|
-
acceptedAddOnsParams.forEach((acceptedAddOnParams) => {
|
|
430
|
-
var _a, _b, _c;
|
|
431
|
-
const availableAddOn = availableAddOns === null || availableAddOns === void 0 ? void 0 : availableAddOns.find((addOn) => addOn.id === acceptedAddOnParams.id);
|
|
432
|
-
if (availableAddOn !== undefined) {
|
|
433
|
-
// acceptedAddOnsの重複を避ける(単価オファーIDに対して)
|
|
434
|
-
if (!acceptedAddOns.some((addOn) => addOn.id === availableAddOn.id)) {
|
|
435
|
-
const availableAddOnReferenceQuantityValue = availableAddOn.priceSpecification.referenceQuantity.value;
|
|
436
|
-
if (typeof availableAddOnReferenceQuantityValue !== 'number') {
|
|
437
|
-
throw new factory.errors.NotImplemented('addOn.priceSpecification.referenceQuantity.value must be number');
|
|
438
|
-
}
|
|
439
|
-
// 受入数量はデフォルトで単価オファーの基準数量
|
|
440
|
-
let referenceQuantityValueAccepted = availableAddOnReferenceQuantityValue;
|
|
441
|
-
// 数量指定を検証(2023-08-31~)
|
|
442
|
-
const specifiedReferencedQuantityValue = (_b = (_a = acceptedAddOnParams.priceSpecification) === null || _a === void 0 ? void 0 : _a.referenceQuantity) === null || _b === void 0 ? void 0 : _b.value;
|
|
443
|
-
if (typeof specifiedReferencedQuantityValue === 'number') {
|
|
444
|
-
if (specifiedReferencedQuantityValue < 1) {
|
|
445
|
-
throw new factory.errors.Argument('addOn.priceSpecification.referenceQuantity.value must be > 0');
|
|
446
|
-
}
|
|
447
|
-
// 数量が適用単位要件を満たしていなければエラー
|
|
448
|
-
if (specifiedReferencedQuantityValue % availableAddOnReferenceQuantityValue !== 0) {
|
|
449
|
-
throw new factory.errors.Argument('addOn.priceSpecification.referenceQuantity.value', `Offer ${availableAddOn.id} requires reference quantity value ${specifiedReferencedQuantityValue}`);
|
|
450
|
-
}
|
|
451
|
-
// 基準数量上書き
|
|
452
|
-
referenceQuantityValueAccepted = specifiedReferencedQuantityValue;
|
|
453
|
-
}
|
|
454
|
-
const priceAccepted = availableAddOn.priceSpecification.price *
|
|
455
|
-
(referenceQuantityValueAccepted / availableAddOnReferenceQuantityValue);
|
|
456
|
-
const accountsReceivableAccepted = (typeof ((_c = availableAddOn.priceSpecification.accounting) === null || _c === void 0 ? void 0 : _c.accountsReceivable) === 'number')
|
|
457
|
-
? availableAddOn.priceSpecification.accounting.accountsReceivable *
|
|
458
|
-
(referenceQuantityValueAccepted / availableAddOnReferenceQuantityValue)
|
|
459
|
-
: undefined;
|
|
460
|
-
const acceptedAddOn = Object.assign(Object.assign({}, availableAddOn), { priceSpecification: Object.assign(Object.assign(Object.assign({}, availableAddOn.priceSpecification), (typeof accountsReceivableAccepted === 'number')
|
|
461
|
-
? {
|
|
462
|
-
accounting: Object.assign(Object.assign({}, availableAddOn.priceSpecification.accounting), { accountsReceivable: accountsReceivableAccepted, typeOf: 'Accounting' })
|
|
463
|
-
}
|
|
464
|
-
: undefined), { price: priceAccepted, referenceQuantity: Object.assign(Object.assign({}, availableAddOn.priceSpecification.referenceQuantity), { value: referenceQuantityValueAccepted }) }) });
|
|
465
|
-
acceptedAddOns.push(acceptedAddOn);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
// acceptedAddOns = availableAddOns.filter(
|
|
470
|
-
// (availableAddOn) => acceptedAddOnsParams.some((acceptedAddOn) => availableAddOn.id === acceptedAddOn.id)
|
|
471
|
-
// );
|
|
472
|
-
}
|
|
473
|
-
const subReservation = (_j = (_h = acceptedOffer.itemOffered) === null || _h === void 0 ? void 0 : _h.serviceOutput) === null || _j === void 0 ? void 0 : _j.subReservation;
|
|
474
|
-
reservations.push((0, factory_1.createReservation)({
|
|
475
|
-
project: { id: params.event.project.id, typeOf: factory.organizationType.Project },
|
|
476
|
-
id: reservationId,
|
|
477
|
-
reservationFor: params.event,
|
|
478
|
-
reservedTicket: reservedTicket,
|
|
479
|
-
additionalProperty: additionalProperty,
|
|
480
|
-
additionalTicketText: additionalTicketText,
|
|
481
|
-
ticketOffer: ticketOffer,
|
|
482
|
-
seatPriceComponent: seatPriceComponent,
|
|
483
|
-
acceptedAddOns: acceptedAddOns,
|
|
484
|
-
subReservation: subReservation,
|
|
485
|
-
programMembershipUsed,
|
|
486
|
-
availableOffer: ticketType,
|
|
487
|
-
appliesToMovieTicket: (_k = acceptedOffer.priceSpecification) === null || _k === void 0 ? void 0 : _k.appliesToMovieTicket,
|
|
488
|
-
validateAppliesToMovieTicket: params.validateAppliesToMovieTicket
|
|
489
|
-
}));
|
|
490
|
-
}
|
|
491
|
-
return reservations;
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
function searchAvailableAddOns(params) {
|
|
495
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
496
|
-
var _a;
|
|
497
|
-
const availableAddOns = [];
|
|
498
|
-
if (Array.isArray(params.ticketOffer.addOn)) {
|
|
499
|
-
const addOnProductIds = [...new Set(params.ticketOffer.addOn.map((o) => String(o.itemOffered.id)))];
|
|
500
|
-
for (const addOnProductId of addOnProductIds) {
|
|
501
|
-
const { offers, product } = yield OfferService.product.search(Object.assign({ ids: params.ids, project: { id: params.project.id }, itemOffered: { id: addOnProductId }, onlyValid: true, addSortIndex: false, includedInDataCatalog: { id: '' }, useIncludeInDataCatalog: false }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
|
|
502
|
-
? { availableAt: { id: params.availableAtOrFrom.id } }
|
|
503
|
-
: undefined))(repos);
|
|
504
|
-
availableAddOns.push(...offers.map((o) => {
|
|
505
|
-
const itemOffered4addOn = {
|
|
506
|
-
description: product.description,
|
|
507
|
-
id: product.id,
|
|
508
|
-
name: product.name,
|
|
509
|
-
productID: product.productID,
|
|
510
|
-
typeOf: product.typeOf
|
|
511
|
-
};
|
|
512
|
-
const unitPriceSpec = o.priceSpecification.priceComponent.find((component) => {
|
|
513
|
-
return component.typeOf === factory.priceSpecificationType.UnitPriceSpecification;
|
|
514
|
-
});
|
|
515
|
-
if ((unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.typeOf) !== factory.priceSpecificationType.UnitPriceSpecification) {
|
|
516
|
-
throw new factory.errors.NotFound('UnitPriceSpecification of an addOn');
|
|
517
|
-
}
|
|
518
|
-
return Object.assign(Object.assign({ alternateName: o.alternateName, availability: o.availability, description: o.description, id: String(o.id), identifier: o.identifier, itemOffered: itemOffered4addOn, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: unitPriceSpec, typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
|
|
519
|
-
}));
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return availableAddOns;
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
function getAcceptedSeatNumbersAndSeatSections(params) {
|
|
526
|
-
const acceptedSeatNumbers = [];
|
|
527
|
-
const acceptedSeatSections = [];
|
|
528
|
-
params.acceptedOffers.forEach((o) => {
|
|
529
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
530
|
-
const acceptedSeatNumber = (_d = (_c = (_b = (_a = o.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatNumber;
|
|
531
|
-
const acceptedSeatSection = (_h = (_g = (_f = (_e = o.itemOffered) === null || _e === void 0 ? void 0 : _e.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservedTicket) === null || _g === void 0 ? void 0 : _g.ticketedSeat) === null || _h === void 0 ? void 0 : _h.seatSection;
|
|
532
|
-
if (typeof acceptedSeatNumber === 'string' && acceptedSeatNumber.length > 0) {
|
|
533
|
-
acceptedSeatNumbers.push(acceptedSeatNumber);
|
|
534
|
-
}
|
|
535
|
-
if (typeof acceptedSeatSection === 'string' && acceptedSeatSection.length > 0) {
|
|
536
|
-
acceptedSeatSections.push(acceptedSeatSection);
|
|
537
|
-
}
|
|
538
|
-
const subReservation = (_k = (_j = o.itemOffered) === null || _j === void 0 ? void 0 : _j.serviceOutput) === null || _k === void 0 ? void 0 : _k.subReservation;
|
|
539
|
-
if (Array.isArray(subReservation)) {
|
|
540
|
-
subReservation.forEach((s) => {
|
|
541
|
-
var _a, _b, _c, _d;
|
|
542
|
-
const subReservationSeatNumber = (_b = (_a = s.reservedTicket) === null || _a === void 0 ? void 0 : _a.ticketedSeat) === null || _b === void 0 ? void 0 : _b.seatNumber;
|
|
543
|
-
const subReservationSeatSection = (_d = (_c = s.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatSection;
|
|
544
|
-
if (typeof subReservationSeatNumber === 'string' && subReservationSeatNumber.length > 0) {
|
|
545
|
-
acceptedSeatNumbers.push(subReservationSeatNumber);
|
|
546
|
-
}
|
|
547
|
-
if (typeof subReservationSeatSection === 'string' && subReservationSeatSection.length > 0) {
|
|
548
|
-
acceptedSeatSections.push(subReservationSeatSection);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
return {
|
|
554
|
-
acceptedSeatNumbers,
|
|
555
|
-
acceptedSeatSections
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* 事前予約要件を検証する
|
|
560
|
-
*/
|
|
561
|
-
function validateAdvanceBookingRequirement(params) {
|
|
562
|
-
var _a, _b;
|
|
563
|
-
const advanceBookingRequirementMinValue = (_a = params.unitPriceOffer.advanceBookingRequirement) === null || _a === void 0 ? void 0 : _a.minValue;
|
|
564
|
-
const advanceBookingRequirementUnitCode = (_b = params.unitPriceOffer.advanceBookingRequirement) === null || _b === void 0 ? void 0 : _b.unitCode;
|
|
565
|
-
if (typeof advanceBookingRequirementMinValue === 'number' && typeof advanceBookingRequirementUnitCode === 'string') {
|
|
566
|
-
if (advanceBookingRequirementMinValue < 0) {
|
|
567
|
-
throw new factory.errors.NotImplemented('negative value as advanceBookingRequirement.minValue not implemented');
|
|
568
|
-
}
|
|
569
|
-
if (advanceBookingRequirementUnitCode !== factory.unitCode.Sec) {
|
|
570
|
-
throw new factory.errors.NotImplemented(`only ${factory.unitCode.Sec} implemented`);
|
|
571
|
-
}
|
|
572
|
-
const reservationForMustStartAfter = moment(params.now)
|
|
573
|
-
.add(advanceBookingRequirementMinValue, 'seconds');
|
|
574
|
-
const requirementSatisfied = moment(params.reservationFor.startDate)
|
|
575
|
-
.isSameOrAfter(reservationForMustStartAfter);
|
|
576
|
-
if (!requirementSatisfied) {
|
|
577
|
-
throw new factory.errors.Argument('acceptedOffer.id', 'advanceBookingRequirement not satisfied');
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
function validateProgramMembershipUsed(params) {
|
|
582
|
-
// tslint:disable-next-line:max-func-body-length
|
|
583
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
584
|
-
var _a, _b, _c;
|
|
585
|
-
const now = new Date();
|
|
586
|
-
let programMembershipUsed;
|
|
587
|
-
const requestedProgramMembershipUsed = (_b = (_a = params.acceptedOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.programMembershipUsed;
|
|
588
|
-
if (typeof requestedProgramMembershipUsed === 'string') {
|
|
589
|
-
throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'must be object');
|
|
590
|
-
}
|
|
591
|
-
const programMembershipUsedIdentifier = requestedProgramMembershipUsed === null || requestedProgramMembershipUsed === void 0 ? void 0 : requestedProgramMembershipUsed.identifier;
|
|
592
|
-
const issuedThroughId = (_c = requestedProgramMembershipUsed === null || requestedProgramMembershipUsed === void 0 ? void 0 : requestedProgramMembershipUsed.issuedThrough) === null || _c === void 0 ? void 0 : _c.id;
|
|
593
|
-
if (typeof programMembershipUsedIdentifier === 'string' && programMembershipUsedIdentifier.length > 0) {
|
|
594
|
-
if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
|
|
595
|
-
throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
|
|
596
|
-
}
|
|
597
|
-
let permitIssuedThrough;
|
|
598
|
-
// まずメンバーシップを検索して、存在しなければCreditCardを検索(どちらが発行元サービスか不明なので)
|
|
599
|
-
permitIssuedThrough = (yield repos.product.searchProducts({
|
|
600
|
-
limit: 1,
|
|
601
|
-
page: 1,
|
|
602
|
-
id: { $eq: issuedThroughId },
|
|
603
|
-
typeOf: { $eq: factory.product.ProductType.MembershipService }
|
|
604
|
-
}, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
|
|
605
|
-
if (permitIssuedThrough === undefined) {
|
|
606
|
-
permitIssuedThrough = (yield repos.paymentService.searchPaymentServices({
|
|
607
|
-
limit: 1,
|
|
608
|
-
page: 1,
|
|
609
|
-
id: { $eq: issuedThroughId },
|
|
610
|
-
typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard }
|
|
611
|
-
}, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], [])).shift();
|
|
612
|
-
}
|
|
613
|
-
if (typeof (permitIssuedThrough === null || permitIssuedThrough === void 0 ? void 0 : permitIssuedThrough.typeOf) !== 'string') {
|
|
614
|
-
throw new factory.errors.NotFound(`Permit issuer service [${issuedThroughId}]`);
|
|
615
|
-
}
|
|
616
|
-
// permitIssuedThrough =
|
|
617
|
-
// await repos.product.findById({ id: issuedThroughId }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], []);
|
|
618
|
-
switch (permitIssuedThrough.typeOf) {
|
|
619
|
-
// 発行サービスがCreditCardのケースに対応(2023-09-01~)
|
|
620
|
-
case factory.service.paymentService.PaymentServiceType.CreditCard:
|
|
621
|
-
// 決済サービスのserviceOutputにPermitが存在すれば、設定されたメンバーシップ区分のPermitをprogramMembershipUsedとして適用する
|
|
622
|
-
let issuedThroughServiceType;
|
|
623
|
-
if (Array.isArray(permitIssuedThrough.serviceOutput)) {
|
|
624
|
-
const serviceOutputAsPermit = permitIssuedThrough.serviceOutput.find((output) => output.typeOf === factory.permit.PermitType.Permit);
|
|
625
|
-
if ((serviceOutputAsPermit === null || serviceOutputAsPermit === void 0 ? void 0 : serviceOutputAsPermit.typeOf) === factory.permit.PermitType.Permit) {
|
|
626
|
-
issuedThroughServiceType = serviceOutputAsPermit.issuedThrough.serviceType;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
if ((issuedThroughServiceType === null || issuedThroughServiceType === void 0 ? void 0 : issuedThroughServiceType.typeOf) === 'CategoryCode') {
|
|
630
|
-
programMembershipUsed = {
|
|
631
|
-
project: permitIssuedThrough.project,
|
|
632
|
-
typeOf: factory.permit.PermitType.Permit,
|
|
633
|
-
identifier: programMembershipUsedIdentifier,
|
|
634
|
-
issuedThrough: {
|
|
635
|
-
id: permitIssuedThrough.id,
|
|
636
|
-
serviceType: issuedThroughServiceType,
|
|
637
|
-
typeOf: permitIssuedThrough.typeOf
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'issuedThrough has no serviceOutput as Permit');
|
|
643
|
-
}
|
|
644
|
-
break;
|
|
645
|
-
case factory.product.ProductType.MembershipService:
|
|
646
|
-
// requestedProgramMembershipUsedの発行サービスIDから外部連携設定を取得する
|
|
647
|
-
const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
|
|
648
|
-
// メンバーシップの存在確認
|
|
649
|
-
const serviceOutput = yield permitService.findByIdentifier({
|
|
650
|
-
project: { id: params.project.id },
|
|
651
|
-
identifier: programMembershipUsedIdentifier,
|
|
652
|
-
issuedThrough: { typeOf: factory.product.ProductType.MembershipService }
|
|
653
|
-
});
|
|
654
|
-
// 有効期間のチェック
|
|
655
|
-
if (serviceOutput.validFrom === undefined || serviceOutput.validFrom === null
|
|
656
|
-
|| serviceOutput.validUntil === undefined || serviceOutput.validUntil === null) {
|
|
657
|
-
throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'not valid programMembership');
|
|
658
|
-
}
|
|
659
|
-
if (moment(serviceOutput.validFrom)
|
|
660
|
-
.isAfter(moment(now))
|
|
661
|
-
|| moment(serviceOutput.validUntil)
|
|
662
|
-
.isBefore(moment(now))) {
|
|
663
|
-
throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'unavailable programMembership');
|
|
664
|
-
}
|
|
665
|
-
programMembershipUsed = {
|
|
666
|
-
project: serviceOutput.project,
|
|
667
|
-
typeOf: serviceOutput.typeOf,
|
|
668
|
-
identifier: serviceOutput.identifier,
|
|
669
|
-
issuedThrough: serviceOutput.issuedThrough
|
|
670
|
-
};
|
|
671
|
-
break;
|
|
672
|
-
default:
|
|
673
|
-
throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', `${permitIssuedThrough.typeOf} not implemented`);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
return programMembershipUsed;
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
function createPermitService(params) {
|
|
680
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
681
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
682
|
-
// const product = <Pick<factory.product.IProduct, 'availableChannel'>>
|
|
683
|
-
// await repos.product.findProductById({ id: params.issuedThrough.id }, ['availableChannel'], []);
|
|
684
|
-
const product = (yield repos.product.searchProducts({
|
|
685
|
-
limit: 1,
|
|
686
|
-
page: 1,
|
|
687
|
-
id: { $eq: params.issuedThrough.id }
|
|
688
|
-
}, ['availableChannel'], [])).shift();
|
|
689
|
-
if (product === undefined) {
|
|
690
|
-
throw new factory.errors.NotFound('Product');
|
|
691
|
-
}
|
|
692
|
-
const permitServiceEndpoint = (_a = product.availableChannel) === null || _a === void 0 ? void 0 : _a.serviceUrl;
|
|
693
|
-
const permitServiceAuthorizeServerDomain = (_c = (_b = product.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.authorizeServerDomain;
|
|
694
|
-
const permitServiceClientId = (_e = (_d = product.availableChannel) === null || _d === void 0 ? void 0 : _d.credentials) === null || _e === void 0 ? void 0 : _e.clientId;
|
|
695
|
-
const permitServiceClientSecret = (_g = (_f = product.availableChannel) === null || _f === void 0 ? void 0 : _f.credentials) === null || _g === void 0 ? void 0 : _g.clientSecret;
|
|
696
|
-
if (typeof permitServiceEndpoint !== 'string' || permitServiceEndpoint.length === 0
|
|
697
|
-
|| typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
|
|
698
|
-
|| typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
|
|
699
|
-
|| typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
|
|
700
|
-
throw new factory.errors.Internal('product availableChannel invalid');
|
|
701
|
-
}
|
|
702
|
-
return new (yield pecorinoapi.loadPecorino()).service.Permit({
|
|
703
|
-
endpoint: permitServiceEndpoint,
|
|
704
|
-
auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
|
|
705
|
-
domain: permitServiceAuthorizeServerDomain,
|
|
706
|
-
clientId: permitServiceClientId,
|
|
707
|
-
clientSecret: permitServiceClientSecret,
|
|
708
|
-
scopes: [],
|
|
709
|
-
state: ''
|
|
710
|
-
})
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
function validatePointAward(params) {
|
|
715
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
716
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
717
|
-
// 口座番号確認ではなく、Permit識別子確認
|
|
718
|
-
const permitIdentifier = (_c = (_b = (_a = params.acceptedOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.pointAward) === null || _b === void 0 ? void 0 : _b.toLocation) === null || _c === void 0 ? void 0 : _c.identifier;
|
|
719
|
-
const issuedThroughId = (_g = (_f = (_e = (_d = params.acceptedOffer.itemOffered) === null || _d === void 0 ? void 0 : _d.pointAward) === null || _e === void 0 ? void 0 : _e.toLocation) === null || _f === void 0 ? void 0 : _f.issuedThrough) === null || _g === void 0 ? void 0 : _g.id;
|
|
720
|
-
if (typeof permitIdentifier === 'string' && permitIdentifier.length > 0) {
|
|
721
|
-
if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
|
|
722
|
-
throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.pointAward.toLocation.issuedThrough.id');
|
|
723
|
-
}
|
|
724
|
-
// pointAwardの指定がある場合、Permitの存在確認
|
|
725
|
-
const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
|
|
726
|
-
yield permitService.findByIdentifier({
|
|
727
|
-
project: { id: params.project.id },
|
|
728
|
-
identifier: permitIdentifier,
|
|
729
|
-
issuedThrough: { typeOf: factory.product.ProductType.PaymentCard }
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
}
|
|
734
|
-
function processLockOfferRateLimit(params) {
|
|
735
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
736
|
-
const rateLimitKeys = [];
|
|
737
|
-
params.reservations.forEach((reservation) => {
|
|
738
|
-
var _a, _b;
|
|
739
|
-
const scope = (_a = reservation.reservedTicket.ticketType.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope;
|
|
740
|
-
const unitInSeconds = (_b = reservation.reservedTicket.ticketType.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds;
|
|
741
|
-
if (typeof scope === 'string' && typeof unitInSeconds === 'number') {
|
|
742
|
-
const rateLimitKey = {
|
|
743
|
-
reservedTicket: {
|
|
744
|
-
ticketType: {
|
|
745
|
-
validRateLimit: {
|
|
746
|
-
scope: scope,
|
|
747
|
-
unitInSeconds: unitInSeconds
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
},
|
|
751
|
-
reservationFor: {
|
|
752
|
-
startDate: (params.reservationFor.typeOf === factory.eventType.ScreeningEvent)
|
|
753
|
-
? moment(params.reservationFor.startDate)
|
|
754
|
-
.toDate()
|
|
755
|
-
: moment(params.reservationFor.departureTime)
|
|
756
|
-
.toDate()
|
|
757
|
-
},
|
|
758
|
-
reservationNumber: params.reservationNumber
|
|
759
|
-
};
|
|
760
|
-
rateLimitKeys.push(rateLimitKey);
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
yield repos.offerRateLimit.lock(rateLimitKeys);
|
|
764
|
-
return rateLimitKeys;
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* 座席ロックプロセス
|
|
769
|
-
*/
|
|
770
|
-
function processLockSeats(params) {
|
|
771
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
772
|
-
var _a, _b, _c, _d;
|
|
773
|
-
const offers = [];
|
|
774
|
-
params.reservations.forEach((r) => {
|
|
775
|
-
var _a, _b;
|
|
776
|
-
const seatSection = (_a = r.reservedTicket.ticketedSeat) === null || _a === void 0 ? void 0 : _a.seatSection;
|
|
777
|
-
const seatNumber = (_b = r.reservedTicket.ticketedSeat) === null || _b === void 0 ? void 0 : _b.seatNumber;
|
|
778
|
-
// 指定席のみの場合、ticketedSeatの存在は保証されている
|
|
779
|
-
if (typeof seatSection === 'string' && typeof seatNumber === 'string') {
|
|
780
|
-
// subReservationがあれば、そちらもロック
|
|
781
|
-
const subReservations = r.subReservation;
|
|
782
|
-
if (Array.isArray(subReservations)) {
|
|
783
|
-
subReservations.forEach((subReservation) => {
|
|
784
|
-
var _a, _b, _c, _d;
|
|
785
|
-
const seatSection4sub = (_b = (_a = subReservation.reservedTicket) === null || _a === void 0 ? void 0 : _a.ticketedSeat) === null || _b === void 0 ? void 0 : _b.seatSection;
|
|
786
|
-
const seatNumber4sub = (_d = (_c = subReservation.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.seatNumber;
|
|
787
|
-
// 指定席のみの場合、ticketedSeatの存在は保証されている
|
|
788
|
-
if (typeof seatSection4sub !== 'string' || typeof seatNumber4sub !== 'string') {
|
|
789
|
-
throw new factory.errors.ArgumentNull('subReservation.reservedTicket.ticketedSeat');
|
|
790
|
-
}
|
|
791
|
-
offers.push({
|
|
792
|
-
seatSection: seatSection4sub,
|
|
793
|
-
seatNumber: seatNumber4sub
|
|
794
|
-
});
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
offers.push({
|
|
798
|
-
seatSection: seatSection,
|
|
799
|
-
seatNumber: seatNumber
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
// 指定席でない場合、予約IDでロック
|
|
804
|
-
offers.push({
|
|
805
|
-
itemOffered: { serviceOutput: { id: r.id } },
|
|
806
|
-
seatSection: '',
|
|
807
|
-
seatNumber: ''
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
const expires = moment(params.event.endDate)
|
|
812
|
-
// 設定化(2023-06-05~)
|
|
813
|
-
// .add(1, 'month')
|
|
814
|
-
.add(params.stockHoldUntilDaysAfterEventEnd, 'days')
|
|
815
|
-
.toDate();
|
|
816
|
-
// holder:取引番号に対応(2023-06-05~)
|
|
817
|
-
// let holder: string = params.transaction.id;
|
|
818
|
-
// if (params.transaction.object?.useHoldStockByTransactionNumber === true) {
|
|
819
|
-
// holder = params.transaction.transactionNumber;
|
|
820
|
-
// }
|
|
821
|
-
const holder = params.transaction.transactionNumber; // fix as transactionNumber(2024-07-02~)
|
|
822
|
-
const hasTicketedSeat = ((_c = (_b = (_a = params.event.offers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) === null || _c === void 0 ? void 0 : _c.typeOf) === factory.placeType.Seat;
|
|
823
|
-
const maximumAttendeeCapacity4event = (_d = params.event.location) === null || _d === void 0 ? void 0 : _d.maximumAttendeeCapacity;
|
|
824
|
-
if (typeof maximumAttendeeCapacity4event === 'number') {
|
|
825
|
-
yield repos.stockHolder.lockIfNotLimitExceeded({
|
|
826
|
-
project: { id: params.event.project.id },
|
|
827
|
-
eventId: params.event.id,
|
|
828
|
-
startDate: moment(params.event.startDate)
|
|
829
|
-
.toDate(),
|
|
830
|
-
hasTicketedSeat,
|
|
831
|
-
offers,
|
|
832
|
-
expires,
|
|
833
|
-
holder
|
|
834
|
-
}, maximumAttendeeCapacity4event);
|
|
835
|
-
}
|
|
836
|
-
else {
|
|
837
|
-
yield repos.stockHolder.lock({
|
|
838
|
-
project: { id: params.event.project.id },
|
|
839
|
-
eventId: params.event.id,
|
|
840
|
-
startDate: moment(params.event.startDate)
|
|
841
|
-
.toDate(),
|
|
842
|
-
hasTicketedSeat,
|
|
843
|
-
offers,
|
|
844
|
-
expires,
|
|
845
|
-
holder
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
/**
|
|
851
|
-
* 予約作成時イベント
|
|
852
|
-
*/
|
|
853
|
-
function onReservationsCreated(params) {
|
|
854
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
855
|
-
// 集計タスク
|
|
856
|
-
yield (0, onEventChanged_1.createAggregateScreeningEventIfNotExist)({
|
|
857
|
-
project: params.event.project,
|
|
858
|
-
reservationFor: [{ id: params.event.id }],
|
|
859
|
-
force: false,
|
|
860
|
-
identifier: `onReservationsCreated:${params.transaction.transactionNumber}`
|
|
861
|
-
})({ task: repos.task });
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* 取引確定
|
|
866
|
-
*/
|
|
867
|
-
function confirm(params) {
|
|
868
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
869
|
-
let transaction;
|
|
870
|
-
// 取引存在確認
|
|
871
|
-
if (typeof params.id === 'string') {
|
|
872
|
-
transaction = yield repos.assetTransaction.findById({
|
|
873
|
-
typeOf: factory.assetTransactionType.Reserve,
|
|
874
|
-
id: params.id
|
|
875
|
-
}, ['project', 'transactionNumber'] // projection(2024-07-01~)
|
|
876
|
-
);
|
|
877
|
-
}
|
|
878
|
-
else if (typeof params.transactionNumber === 'string') {
|
|
879
|
-
transaction = yield repos.assetTransaction.findByTransactionNumber({
|
|
880
|
-
typeOf: factory.assetTransactionType.Reserve,
|
|
881
|
-
transactionNumber: params.transactionNumber
|
|
882
|
-
}, ['project', 'transactionNumber'] // projection(2024-07-01~)
|
|
883
|
-
);
|
|
884
|
-
}
|
|
885
|
-
else {
|
|
886
|
-
throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
|
|
887
|
-
}
|
|
888
|
-
const order = yield fixOrderAsPurpose(params, transaction)(repos);
|
|
889
|
-
const { potentialActions, underName } = (0, factory_1.createPotentialActions)({
|
|
890
|
-
// ...params,
|
|
891
|
-
// transaction,
|
|
892
|
-
order
|
|
893
|
-
});
|
|
894
|
-
// 取引確定
|
|
895
|
-
const result = {};
|
|
896
|
-
yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Reserve, id: transaction.id, result: result,
|
|
897
|
-
// potentialActions: (USE_ASSET_TRANSACTION_SYNC_PROCESSING)
|
|
898
|
-
// ? { reserve: [] }
|
|
899
|
-
// : potentialActions, // discontinue(2024-07-01~)
|
|
900
|
-
potentialActions }, (typeof (underName === null || underName === void 0 ? void 0 : underName.typeOf) === 'string')
|
|
901
|
-
? { object: { underName } }
|
|
902
|
-
: undefined));
|
|
903
|
-
if (settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
|
|
904
|
-
// sync対応(2023-01-13~)
|
|
905
|
-
yield (0, confirmReservation_1.confirmReservation)({
|
|
906
|
-
// optimize(2024-07-01~)
|
|
907
|
-
// actionAttributesList: potentialActions.reserve,
|
|
908
|
-
potentialReserveAction: { object: { reservationNumber: transaction.transactionNumber } },
|
|
909
|
-
useOnReservationConfirmed: true,
|
|
910
|
-
byTask: true
|
|
911
|
-
})(repos);
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
exports.confirm = confirm;
|
|
916
|
-
function fixOrderAsPurpose(params, transaction) {
|
|
917
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
918
|
-
var _a, _b, _c, _d, _e, _f;
|
|
919
|
-
let order;
|
|
920
|
-
const payPurposeConfirmationNumber = (_c = (_b = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.reserve) === null || _b === void 0 ? void 0 : _b.purpose) === null || _c === void 0 ? void 0 : _c.confirmationNumber;
|
|
921
|
-
const payPurposeOrderNumber = (_f = (_e = (_d = params.potentialActions) === null || _d === void 0 ? void 0 : _d.reserve) === null || _e === void 0 ? void 0 : _e.purpose) === null || _f === void 0 ? void 0 : _f.orderNumber;
|
|
922
|
-
if (typeof payPurposeConfirmationNumber === 'string'
|
|
923
|
-
&& payPurposeConfirmationNumber.length > 0
|
|
924
|
-
&& typeof payPurposeOrderNumber === 'string'
|
|
925
|
-
&& payPurposeOrderNumber.length > 0) {
|
|
926
|
-
const orders = yield repos.order.search({
|
|
927
|
-
limit: 1,
|
|
928
|
-
page: 1,
|
|
929
|
-
project: { id: { $eq: transaction.project.id } },
|
|
930
|
-
confirmationNumbers: [payPurposeConfirmationNumber],
|
|
931
|
-
orderNumbers: [payPurposeOrderNumber]
|
|
932
|
-
}, { customer: 1, orderNumber: 1, typeOf: 1 });
|
|
933
|
-
order = orders.shift();
|
|
934
|
-
if (order === undefined) {
|
|
935
|
-
throw new factory.errors.NotFound('Order as purpose');
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
return order;
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* 取引中止
|
|
943
|
-
*/
|
|
944
|
-
function cancel(params) {
|
|
945
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
946
|
-
// まず取引状態変更
|
|
947
|
-
const { id } = yield repos.assetTransaction.cancel({
|
|
948
|
-
typeOf: factory.assetTransactionType.Reserve,
|
|
949
|
-
id: params.id,
|
|
950
|
-
transactionNumber: params.transactionNumber
|
|
951
|
-
});
|
|
952
|
-
// 本来非同期でタスクが実行されるが、同期的に仮予約取消が実行されていないと、サービス利用側が困る可能性があるので、
|
|
953
|
-
// 同期的にもcancelPendingReservationを実行しておく
|
|
954
|
-
// optimize(2024-07-01~)
|
|
955
|
-
// const cancelActionAttributes = createCancelPendingReservationAction({ transaction });
|
|
956
|
-
// if (cancelActionAttributes !== undefined) {
|
|
957
|
-
// await cancelPendingReservation(cancelActionAttributes)(repos);
|
|
958
|
-
// }
|
|
959
|
-
yield (0, cancelReservation_1.cancelPendingReservation)({
|
|
960
|
-
purpose: {
|
|
961
|
-
id,
|
|
962
|
-
typeOf: factory.assetTransactionType.Reserve
|
|
963
|
-
}
|
|
964
|
-
})(repos);
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
exports.cancel = cancel;
|
|
968
|
-
/**
|
|
969
|
-
* 取引タスク出力
|
|
970
|
-
*/
|
|
971
|
-
function exportTasksById(params) {
|
|
972
|
-
// tslint:disable-next-line:max-func-body-length
|
|
973
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
974
|
-
const transaction = yield repos.assetTransaction.findById({
|
|
975
|
-
typeOf: factory.assetTransactionType.Reserve,
|
|
976
|
-
id: params.id
|
|
977
|
-
}, ['status', 'transactionNumber', 'project', 'typeOf'] // projection(2024-07-01~)
|
|
978
|
-
);
|
|
979
|
-
// const potentialActions = transaction.potentialActions;
|
|
980
|
-
const taskAttributes = [];
|
|
981
|
-
let cancelPendingReservationTask;
|
|
982
|
-
switch (transaction.status) {
|
|
983
|
-
case factory.transactionStatusType.Confirmed:
|
|
984
|
-
// potentialActions依存を完全廃止(2024-07-01~)
|
|
985
|
-
// if (potentialActions !== undefined) {
|
|
986
|
-
// if (Array.isArray(potentialActions.reserve) && potentialActions.reserve.length > 0) {
|
|
987
|
-
// }
|
|
988
|
-
// }
|
|
989
|
-
if (!settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
|
|
990
|
-
const reserveTask = {
|
|
991
|
-
project: transaction.project,
|
|
992
|
-
name: factory.taskName.Reserve,
|
|
993
|
-
status: factory.taskStatus.Ready,
|
|
994
|
-
runsAt: new Date(),
|
|
995
|
-
remainingNumberOfTries: 10,
|
|
996
|
-
numberOfTried: 0,
|
|
997
|
-
executionResults: [],
|
|
998
|
-
data: { object: { reservationNumber: transaction.transactionNumber } } // optimize(2024-07-01~)
|
|
999
|
-
};
|
|
1000
|
-
taskAttributes.push(reserveTask);
|
|
1001
|
-
}
|
|
1002
|
-
break;
|
|
1003
|
-
case factory.transactionStatusType.Canceled:
|
|
1004
|
-
// sync対応(2023-01-13~)
|
|
1005
|
-
if (!settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
|
|
1006
|
-
// const cancelActionAttributes4canceled = createCancelPendingReservationAction({ transaction });
|
|
1007
|
-
// if (cancelActionAttributes4canceled !== undefined) {
|
|
1008
|
-
// }
|
|
1009
|
-
cancelPendingReservationTask = {
|
|
1010
|
-
project: transaction.project,
|
|
1011
|
-
name: factory.taskName.CancelPendingReservation,
|
|
1012
|
-
status: factory.taskStatus.Ready,
|
|
1013
|
-
runsAt: new Date(),
|
|
1014
|
-
remainingNumberOfTries: 10,
|
|
1015
|
-
numberOfTried: 0,
|
|
1016
|
-
executionResults: [],
|
|
1017
|
-
data: {
|
|
1018
|
-
// optimize(2024-07-01~)
|
|
1019
|
-
// actionAttributes: [cancelActionAttributes4canceled],
|
|
1020
|
-
purpose: { id: transaction.id, typeOf: transaction.typeOf }
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
taskAttributes.push(cancelPendingReservationTask);
|
|
1024
|
-
}
|
|
1025
|
-
break;
|
|
1026
|
-
case factory.transactionStatusType.Expired:
|
|
1027
|
-
// const cancelActionAttributes = createCancelPendingReservationAction({ transaction });
|
|
1028
|
-
// if (cancelActionAttributes !== undefined) {
|
|
1029
|
-
// }
|
|
1030
|
-
cancelPendingReservationTask = {
|
|
1031
|
-
project: transaction.project,
|
|
1032
|
-
name: factory.taskName.CancelPendingReservation,
|
|
1033
|
-
status: factory.taskStatus.Ready,
|
|
1034
|
-
runsAt: new Date(),
|
|
1035
|
-
remainingNumberOfTries: 10,
|
|
1036
|
-
numberOfTried: 0,
|
|
1037
|
-
executionResults: [],
|
|
1038
|
-
data: {
|
|
1039
|
-
// optimize(2024-07-01~)
|
|
1040
|
-
// actionAttributes: [cancelActionAttributes]
|
|
1041
|
-
purpose: { id: transaction.id, typeOf: transaction.typeOf }
|
|
1042
|
-
}
|
|
1043
|
-
};
|
|
1044
|
-
taskAttributes.push(cancelPendingReservationTask);
|
|
1045
|
-
break;
|
|
1046
|
-
default:
|
|
1047
|
-
throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
1048
|
-
}
|
|
1049
|
-
return repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
exports.exportTasksById = exportTasksById;
|
|
7
|
+
const cancel_1 = require("./reserve/cancel");
|
|
8
|
+
Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return cancel_1.cancel; } });
|
|
9
|
+
const confirm_1 = require("./reserve/confirm");
|
|
10
|
+
Object.defineProperty(exports, "confirm", { enumerable: true, get: function () { return confirm_1.confirm; } });
|
|
11
|
+
const exportTasksById_1 = require("./reserve/exportTasksById");
|
|
12
|
+
Object.defineProperty(exports, "exportTasksById", { enumerable: true, get: function () { return exportTasksById_1.exportTasksById; } });
|
|
13
|
+
const start_1 = require("./reserve/start");
|
|
14
|
+
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
|