@chevre/domain 25.0.0-alpha.2 → 25.0.0-alpha.20
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/emailMessageBuilder.d.ts +10 -4
- package/lib/chevre/emailMessageBuilder.js +48 -73
- package/lib/chevre/repo/acceptedOffer.d.ts +1 -5
- package/lib/chevre/repo/acceptedOffer.js +5 -5
- package/lib/chevre/repo/acceptedOfferInReserve.d.ts +1 -5
- package/lib/chevre/repo/acceptedOfferInReserve.js +4 -4
- package/lib/chevre/repo/emailMessage.d.ts +18 -9
- package/lib/chevre/repo/emailMessage.js +26 -36
- package/lib/chevre/repo/factory/acceptedOffer/reserveTransaction2itemOffered.d.ts +1 -3
- package/lib/chevre/repo/factory/acceptedOffer/reserveTransaction2itemOffered.js +2 -3
- package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +9 -1
- package/lib/chevre/repo/mongoose/schemas/emailMessages.js +5 -20
- package/lib/chevre/repo/mongoose/schemas/order.d.ts +4 -0
- package/lib/chevre/repo/mongoose/schemas/order.js +11 -110
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +0 -6
- package/lib/chevre/repo/order.d.ts +9 -6
- package/lib/chevre/repo/order.js +45 -26
- package/lib/chevre/repo/orderInTransaction.d.ts +50 -32
- package/lib/chevre/repo/orderInTransaction.js +109 -73
- package/lib/chevre/repo/orderNumber.d.ts +4 -0
- package/lib/chevre/repo/orderNumber.js +32 -60
- package/lib/chevre/repo/passport.d.ts +5 -2
- package/lib/chevre/repo/transaction/placeOrder.js +12 -10
- package/lib/chevre/repo/transaction.d.ts +6 -2
- package/lib/chevre/repo/transaction.js +6 -2
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +0 -2
- package/lib/chevre/service/offer/any.d.ts +3 -8
- package/lib/chevre/service/offer/any.js +7 -6
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +0 -2
- package/lib/chevre/service/offer/event/authorize.d.ts +0 -4
- package/lib/chevre/service/offer/event/authorize.js +5 -6
- package/lib/chevre/service/offer/event/voidTransaction.js +29 -17
- package/lib/chevre/service/offer/event/voidTransactionByActionId.js +16 -12
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +0 -6
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +10 -12
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +7 -7
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +21 -17
- package/lib/chevre/service/order/deleteOrder.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.d.ts +4 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -26
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +3 -2
- package/lib/chevre/service/order/placeOrder/factory.d.ts +1 -1
- package/lib/chevre/service/order/placeOrder/factory.js +10 -8
- package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.d.ts +1 -3
- package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +3 -15
- package/lib/chevre/service/order/placeOrder.js +6 -6
- package/lib/chevre/service/order.d.ts +1 -2
- package/lib/chevre/service/order.js +1 -5
- package/lib/chevre/service/payment/any/authorize/fixOrderAsNeeded.d.ts +2 -4
- package/lib/chevre/service/payment/any/authorize/fixOrderAsNeeded.js +4 -6
- package/lib/chevre/service/payment/any/authorize.d.ts +2 -0
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -4
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +5 -8
- package/lib/chevre/service/reserve/findByCode.js +1 -1
- package/lib/chevre/service/reserve/searchByOrder.js +1 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +8 -10
- package/lib/chevre/service/task/authorizePayment.js +2 -6
- package/lib/chevre/service/task/confirmReserveTransaction.js +1 -1
- package/lib/chevre/service/task/payment/payByTask.js +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +6 -9
- package/lib/chevre/service/transaction/placeOrder/confirm/factory/result.d.ts +7 -2
- package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.d.ts +3 -3
- package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +8 -23
- package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.d.ts +3 -3
- package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +1 -6
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -7
- package/lib/chevre/service/transaction/placeOrder/confirm.js +38 -35
- package/lib/chevre/service/transaction/placeOrder/issueOrderNumberIfNotExist.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/issueOrderNumberIfNotExist.js +1 -0
- package/lib/chevre/service/transaction/placeOrder/start/factory.d.ts +19 -4
- package/lib/chevre/service/transaction/placeOrder/start/factory.js +23 -12
- package/lib/chevre/service/transaction/placeOrder/start.d.ts +7 -4
- package/lib/chevre/service/transaction/placeOrder/start.js +23 -2
- package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +0 -4
- package/lib/chevre/service/transaction/placeOrder/updateAgent.js +20 -22
- package/lib/chevre/service/transaction/placeOrder.d.ts +1 -2
- package/lib/chevre/service/transaction/placeOrder.js +1 -3
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +2 -37
- package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.d.ts +2 -2
- package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +3 -18
- package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +0 -1
- package/lib/chevre/service/transaction/returnOrder/potentialActions.js +0 -4
- package/lib/chevre/service/transaction/returnOrder/preStart.js +1 -1
- package/lib/chevre/service/transaction/returnOrder.d.ts +0 -2
- package/lib/chevre/service/transaction/returnOrder.js +13 -12
- package/lib/chevre/service/validation/validateOrder.js +1 -1
- package/lib/chevre/service.d.ts +0 -2
- package/lib/chevre/service.js +0 -2
- package/package.json +2 -2
- package/lib/chevre/factory/order.d.ts +0 -2
- package/lib/chevre/factory/order.js +0 -5
- package/lib/chevre/service/order/placeOrderWithoutTransaction.d.ts +0 -22
- package/lib/chevre/service/order/placeOrderWithoutTransaction.js +0 -51
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrderInTransactionRepo = void 0;
|
|
4
4
|
// import { isDeepStrictEqual } from 'util';
|
|
5
|
+
const errorHandler_1 = require("../errorHandler");
|
|
5
6
|
const factory_1 = require("../factory");
|
|
6
7
|
const order_1 = require("./mongoose/schemas/order");
|
|
7
8
|
const acceptedOfferInReserve_1 = require("./acceptedOfferInReserve");
|
|
@@ -15,13 +16,86 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
15
16
|
super(connection);
|
|
16
17
|
this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
|
|
17
18
|
}
|
|
19
|
+
async createPlaceOrderIfNotExists(params) {
|
|
20
|
+
const { orderNumber, project, identifier, broker, seller, customer } = params;
|
|
21
|
+
const setOnInsert = {
|
|
22
|
+
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
23
|
+
orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
24
|
+
orderNumber,
|
|
25
|
+
project,
|
|
26
|
+
identifier, // 取引ID(2026-06-22~)
|
|
27
|
+
...((seller !== undefined) && { seller }),
|
|
28
|
+
...((customer !== undefined) && { customer }),
|
|
29
|
+
...((broker !== undefined) && { broker })
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
return this.orderModel.updateOne({
|
|
33
|
+
identifier: { $eq: identifier }, // 取引IDに対してユニークネスを保証する
|
|
34
|
+
}, { $setOnInsert: setOnInsert }, { upsert: true })
|
|
35
|
+
.exec();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
let throwsError = true;
|
|
39
|
+
if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
|
|
40
|
+
// すでにidentifierが存在する場合ok
|
|
41
|
+
throwsError = false;
|
|
42
|
+
}
|
|
43
|
+
if (throwsError) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 注文取引から注文番号を参照する
|
|
50
|
+
* 存在しなければNotFoundError
|
|
51
|
+
*/
|
|
52
|
+
async findOrderNumberByIdentifier(params, options) {
|
|
53
|
+
const { project, identifier } = params;
|
|
54
|
+
const onlyPlaceOrder = options.onlyPlaceOrder === true;
|
|
55
|
+
const doc = await this.orderModel.findOne({
|
|
56
|
+
identifier: { $eq: identifier },
|
|
57
|
+
'project.id': { $eq: project.id },
|
|
58
|
+
...((onlyPlaceOrder) && { typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder } })
|
|
59
|
+
}, {
|
|
60
|
+
_id: 0,
|
|
61
|
+
orderNumber: 1
|
|
62
|
+
})
|
|
63
|
+
.lean()
|
|
64
|
+
.exec();
|
|
65
|
+
if (doc === null) {
|
|
66
|
+
throw new factory_1.factory.errors.NotFound('orderInTransaction');
|
|
67
|
+
}
|
|
68
|
+
return doc.orderNumber;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 注文ドキュメントからcustomer属性を参照する
|
|
72
|
+
* customer未設定であれば、NotFound
|
|
73
|
+
*/
|
|
74
|
+
async findCustomerByOrderIdentifier(params) {
|
|
75
|
+
const doc = await this.orderModel.findOne({
|
|
76
|
+
identifier: { $eq: params.identifier }
|
|
77
|
+
// typeOf: { $eq: factory.transactionType.PlaceOrder } // 検証しない
|
|
78
|
+
}, {
|
|
79
|
+
_id: 0,
|
|
80
|
+
customer: 1
|
|
81
|
+
})
|
|
82
|
+
.lean()
|
|
83
|
+
.exec();
|
|
84
|
+
if (doc === null) {
|
|
85
|
+
throw new factory_1.factory.errors.NotFound('orderInTransaction');
|
|
86
|
+
}
|
|
87
|
+
if (typeof doc.customer?.typeOf !== 'string') {
|
|
88
|
+
throw new factory_1.factory.errors.NotFound('orderInTransaction.customer');
|
|
89
|
+
}
|
|
90
|
+
return doc.customer;
|
|
91
|
+
}
|
|
18
92
|
/**
|
|
19
93
|
* 取引進行中の注文からacceptedOffersを検索する
|
|
20
94
|
* 予約取引から予約ごとの価格仕様も参照する
|
|
21
95
|
*/
|
|
22
|
-
async
|
|
96
|
+
async findAcceptedOffersWithPriceByIdentifier(params) {
|
|
23
97
|
const doc = await this.orderModel.findOne({
|
|
24
|
-
|
|
98
|
+
identifier: { $eq: params.identifier },
|
|
25
99
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
|
|
26
100
|
}, { acceptedOffers: 1 })
|
|
27
101
|
.lean()
|
|
@@ -38,7 +112,7 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
38
112
|
let acceptedOffersByReserveTransaction = [];
|
|
39
113
|
const reservationNumbers = [...new Set(doc.acceptedOffers.map((aceptedOffer) => aceptedOffer.itemOffered.reservationNumber))];
|
|
40
114
|
if (reservationNumbers.length > 0) {
|
|
41
|
-
acceptedOffersByReserveTransaction = await this.findAcceptedOffersByReservationNumbers({ reservationNumbers }
|
|
115
|
+
acceptedOffersByReserveTransaction = await this.findAcceptedOffersByReservationNumbers({ reservationNumbers });
|
|
42
116
|
}
|
|
43
117
|
return doc.acceptedOffers.map((acceptedOffer) => {
|
|
44
118
|
const acceptedOfferByReserve = acceptedOffersByReserveTransaction.find((acceptedOfferByReserveTransaction) => acceptedOfferByReserveTransaction.itemOffered.id === acceptedOffer.itemOffered.id);
|
|
@@ -59,40 +133,19 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
59
133
|
};
|
|
60
134
|
});
|
|
61
135
|
}
|
|
62
|
-
// /**
|
|
63
|
-
// * 取引進行中の注文からacceptedOffersを検索する
|
|
64
|
-
// */
|
|
65
|
-
// public async findAcceptedOffersByOrderNumber(
|
|
66
|
-
// params: { orderNumber: { $eq: string } }
|
|
67
|
-
// ): Promise<Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'serialNumber'>[]> {
|
|
68
|
-
// const doc = await this.orderModel.findOne<HydratedDocument<Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'serialNumber'>>>(
|
|
69
|
-
// {
|
|
70
|
-
// orderNumber: { $eq: params.orderNumber.$eq },
|
|
71
|
-
// typeOf: { $eq: factory.transactionType.PlaceOrder }
|
|
72
|
-
// },
|
|
73
|
-
// { acceptedOffers: 1 }
|
|
74
|
-
// )
|
|
75
|
-
// .lean<Pick<IOrderInTransaction, 'acceptedOffers'>>()
|
|
76
|
-
// .exec();
|
|
77
|
-
// if (doc === null) {
|
|
78
|
-
// throw new factory.errors.NotFound('orderInTransaction');
|
|
79
|
-
// }
|
|
80
|
-
// return doc.acceptedOffers;
|
|
81
|
-
// }
|
|
82
136
|
/**
|
|
83
137
|
* 注文を受注する
|
|
84
138
|
* typeOf: PlaceOrder -> typeOf: Order
|
|
85
139
|
*/
|
|
86
|
-
async
|
|
140
|
+
async placeOrderByIdentifier(filter, order) {
|
|
141
|
+
const { identifier } = filter;
|
|
87
142
|
if (!(order.orderDate instanceof Date)) {
|
|
88
143
|
throw new factory_1.factory.errors.Argument('orderDate', 'must be Date');
|
|
89
144
|
}
|
|
90
|
-
// acceptedOffersを上書きしない
|
|
91
|
-
// const { acceptedOffers, ...orderWithoutAcceptedOffers } = order;
|
|
92
145
|
const setFields = order;
|
|
93
146
|
// typeOf:PlaceOrderのドキュメントが存在すれば、typeOf:Orderに変更する
|
|
94
147
|
await this.orderModel.updateOne({
|
|
95
|
-
|
|
148
|
+
identifier: { $eq: identifier },
|
|
96
149
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
|
|
97
150
|
}, { $set: setFields }, {})
|
|
98
151
|
.exec();
|
|
@@ -101,43 +154,44 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
101
154
|
* 注文documentがなければ作成し、受け入れられたオファーを追加する
|
|
102
155
|
* このメソッドでdocumentが初めて生成される(typeOf:PlaceOrderとして)
|
|
103
156
|
*/
|
|
104
|
-
async
|
|
157
|
+
async acceptOfferByIdentifier(params) {
|
|
105
158
|
if (!Array.isArray(params.acceptedOffers) || params.acceptedOffers.length === 0) {
|
|
106
159
|
return;
|
|
107
160
|
}
|
|
108
|
-
const
|
|
109
|
-
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
110
|
-
orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
111
|
-
orderNumber: params.orderNumber,
|
|
112
|
-
project: params.project
|
|
113
|
-
};
|
|
114
|
-
return this.orderModel.updateOne({
|
|
161
|
+
const result = await this.orderModel.updateOne({
|
|
115
162
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
116
|
-
|
|
163
|
+
identifier: { $eq: params.identifier },
|
|
117
164
|
// プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
|
|
118
165
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
119
166
|
'project.id': { $eq: params.project.id }
|
|
120
167
|
}, {
|
|
121
|
-
$setOnInsert: setOnInsert,
|
|
168
|
+
// $setOnInsert: setOnInsert, // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
122
169
|
$push: {
|
|
123
170
|
acceptedOffers: {
|
|
124
171
|
$each: params.acceptedOffers
|
|
125
172
|
}
|
|
126
173
|
}
|
|
127
|
-
}, {
|
|
174
|
+
}, {
|
|
175
|
+
// upsert: true // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
176
|
+
})
|
|
128
177
|
.exec();
|
|
178
|
+
if (result.matchedCount !== 1) {
|
|
179
|
+
console.error(params, result);
|
|
180
|
+
throw new factory_1.factory.errors.Internal(`orderInTransaction not found`);
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
129
183
|
}
|
|
130
184
|
/**
|
|
131
185
|
* serialNumberからオファーを除外する
|
|
132
186
|
* ホワイトリストとブラックリスト両方に対応
|
|
133
187
|
*/
|
|
134
|
-
async
|
|
188
|
+
async voidAcceptedOfferByIdentifier(params) {
|
|
135
189
|
const serialNumberIn = params.acceptedOffers.serialNumber.$in;
|
|
136
190
|
const serialNumberNin = params.acceptedOffers.serialNumber.$nin;
|
|
137
191
|
if (Array.isArray(serialNumberIn) && serialNumberIn.length > 0) {
|
|
138
192
|
return this.orderModel.updateOne({
|
|
139
193
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
140
|
-
|
|
194
|
+
identifier: { $eq: params.identifier }
|
|
141
195
|
}, {
|
|
142
196
|
$pull: {
|
|
143
197
|
acceptedOffers: {
|
|
@@ -150,7 +204,7 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
150
204
|
else if (Array.isArray(serialNumberNin) && serialNumberNin.length > 0) {
|
|
151
205
|
return this.orderModel.updateOne({
|
|
152
206
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
153
|
-
|
|
207
|
+
identifier: { $eq: params.identifier }
|
|
154
208
|
}, {
|
|
155
209
|
$pull: {
|
|
156
210
|
acceptedOffers: {
|
|
@@ -164,51 +218,33 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
164
218
|
return;
|
|
165
219
|
}
|
|
166
220
|
}
|
|
167
|
-
async
|
|
168
|
-
const { customer,
|
|
221
|
+
async setCustomerByIdentifier(params) {
|
|
222
|
+
const { customer, identifier, project } = params;
|
|
169
223
|
const filter = {
|
|
170
224
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
171
|
-
|
|
225
|
+
identifier: { $eq: identifier },
|
|
172
226
|
// プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
|
|
173
227
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
174
228
|
'project.id': { $eq: project.id }
|
|
175
229
|
};
|
|
176
|
-
const setOnInsert = {
|
|
177
|
-
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
178
|
-
orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
179
|
-
orderNumber,
|
|
180
|
-
project
|
|
181
|
-
};
|
|
182
230
|
const setKeys = { customer };
|
|
183
|
-
|
|
184
|
-
$setOnInsert: setOnInsert,
|
|
231
|
+
const result = await this.orderModel.updateOne(filter, {
|
|
232
|
+
// $setOnInsert: setOnInsert, // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
185
233
|
$set: setKeys
|
|
186
|
-
}, {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* 注文ドキュメントからcustomer属性を参照する
|
|
191
|
-
* customer未設定であれば、NotFound
|
|
192
|
-
*/
|
|
193
|
-
async findCustomerByOrderNumber(params) {
|
|
194
|
-
const doc = await this.orderModel.findOne({
|
|
195
|
-
orderNumber: { $eq: params.orderNumber.$eq }
|
|
196
|
-
// typeOf: { $eq: factory.transactionType.PlaceOrder } // 検証しない
|
|
197
|
-
}, { customer: 1 })
|
|
198
|
-
.lean()
|
|
234
|
+
}, {
|
|
235
|
+
// upsert: true // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
236
|
+
})
|
|
199
237
|
.exec();
|
|
200
|
-
if (
|
|
201
|
-
|
|
238
|
+
if (result.matchedCount !== 1) {
|
|
239
|
+
console.error(params, result);
|
|
240
|
+
throw new factory_1.factory.errors.Internal(`orderInTransaction not found`);
|
|
202
241
|
}
|
|
203
|
-
|
|
204
|
-
throw new factory_1.factory.errors.NotFound('orderInTransaction.customer');
|
|
205
|
-
}
|
|
206
|
-
return doc.customer;
|
|
242
|
+
return result;
|
|
207
243
|
}
|
|
208
|
-
async
|
|
244
|
+
async deleteByIdentifier(params) {
|
|
209
245
|
return this.orderModel.deleteOne({
|
|
210
246
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
211
|
-
|
|
247
|
+
identifier: { $eq: params.identifier }
|
|
212
248
|
})
|
|
213
249
|
.exec();
|
|
214
250
|
}
|
|
@@ -5,6 +5,9 @@ import type { Connection } from 'mongoose';
|
|
|
5
5
|
export declare class OrderNumberRepo {
|
|
6
6
|
private readonly counterRepo;
|
|
7
7
|
private readonly settingModel;
|
|
8
|
+
private static cachedSettings;
|
|
9
|
+
private static cacheExpiry;
|
|
10
|
+
private static readonly CACHE_TTL_MS;
|
|
8
11
|
constructor(params: {
|
|
9
12
|
connection: Connection;
|
|
10
13
|
});
|
|
@@ -22,6 +25,7 @@ export declare class OrderNumberRepo {
|
|
|
22
25
|
orderDate: Date;
|
|
23
26
|
}): Promise<string>;
|
|
24
27
|
decrypt(id: string): Promise<string>;
|
|
28
|
+
clearSettingCache(): void;
|
|
25
29
|
/**
|
|
26
30
|
* 注文番号生成設定を検索する
|
|
27
31
|
*/
|
|
@@ -17,36 +17,25 @@ const ORDER_NUMBER_SEPARATOR = '-';
|
|
|
17
17
|
class OrderNumberRepo {
|
|
18
18
|
counterRepo;
|
|
19
19
|
settingModel;
|
|
20
|
+
// static にすることで、クラスが何回 new されてもメモリ上で1つだけ保持される
|
|
21
|
+
static cachedSettings;
|
|
22
|
+
static cacheExpiry = 0;
|
|
23
|
+
static CACHE_TTL_MS = 10 * 60 * 1000; // 10分
|
|
20
24
|
constructor(params) {
|
|
21
25
|
this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
|
|
22
26
|
this.settingModel = params.connection.model(setting_1.modelName, (0, setting_1.createSchema)());
|
|
23
27
|
}
|
|
24
|
-
// public static GENERATE_VERSION0(timestamp: string, seq: number): string {
|
|
25
|
-
// let orderNumber = `${timestamp}${seq}`;
|
|
26
|
-
// // checkdigit
|
|
27
|
-
// const cd = cdigit.luhn.compute(orderNumber);
|
|
28
|
-
// orderNumber = fpe({ password: cd })
|
|
29
|
-
// .encrypt(orderNumber);
|
|
30
|
-
// orderNumber = `${cd}${orderNumber}`;
|
|
31
|
-
// return orderNumber;
|
|
32
|
-
// }
|
|
33
28
|
/**
|
|
34
29
|
* 注文日時から新しい注文番号を発行する
|
|
35
30
|
* グローバルユニークである前提
|
|
36
31
|
*/
|
|
37
32
|
async issueOrderNumber(params) {
|
|
38
|
-
const { fpeSecret, version
|
|
39
|
-
// versioningForceProjects
|
|
40
|
-
// versioningExceptionProjects
|
|
41
|
-
} = await this.findSetting();
|
|
33
|
+
const { fpeSecret, version } = await this.findSetting();
|
|
42
34
|
const timestamp = (0, moment_timezone_1.default)(params.orderDate)
|
|
43
35
|
.valueOf()
|
|
44
36
|
.toString();
|
|
45
|
-
// const projectPrefix = params.project.alternateName
|
|
46
|
-
// .toUpperCase();
|
|
47
37
|
const projectPrefix = params.project.alternateName
|
|
48
38
|
.toUpperCase().at(0);
|
|
49
|
-
// const dataFeedIdentifier = `${projectPrefix}:${timestamp}`;
|
|
50
39
|
const dataFeedIdentifier = timestamp; // reconsider increment scope(2026-02-21~)
|
|
51
40
|
const dataFeedExpires = (0, moment_timezone_1.default)(params.orderDate)
|
|
52
41
|
.add(1, 'minute') // ミリ秒でカウントしていくので、注文日時後1分で十分
|
|
@@ -57,32 +46,16 @@ class OrderNumberRepo {
|
|
|
57
46
|
expires: dataFeedExpires
|
|
58
47
|
});
|
|
59
48
|
let orderNumber;
|
|
60
|
-
const useVersioning = (validFrom instanceof Date && (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
orderNumber
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
].join(ORDER_NUMBER_SEPARATOR)}`;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// discontinue version0(2026-02-13~)
|
|
74
|
-
throw new factory_1.factory.errors.NotImplemented('orderNumber with no version discontinued');
|
|
75
|
-
// orderNumber = OrderNumberRepo.GENERATE_VERSION0(timestamp, incrReply);
|
|
76
|
-
// orderNumber = `${projectPrefix}${orderNumber}`;
|
|
77
|
-
// orderNumber = `${[
|
|
78
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
79
|
-
// orderNumber.slice(0, 4),
|
|
80
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
81
|
-
// orderNumber.slice(4, 11),
|
|
82
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
83
|
-
// orderNumber.slice(11)
|
|
84
|
-
// ].join(ORDER_NUMBER_SEPARATOR)}`;
|
|
85
|
-
}
|
|
49
|
+
// const useVersioning: boolean = (validFrom instanceof Date && moment(validFrom)
|
|
50
|
+
// .isSameOrBefore(params.orderDate));
|
|
51
|
+
const transactionFactory = new transactionNumber_1.TransactionNumberFactory({ fpeSecret, version });
|
|
52
|
+
orderNumber = transactionFactory.generate(timestamp, incrReply);
|
|
53
|
+
orderNumber = `${projectPrefix}${orderNumber}`; // 桁数をversion0に合わせるためにエイリアスの1文字目のみを採用
|
|
54
|
+
orderNumber = `${[
|
|
55
|
+
orderNumber.slice(0, 4),
|
|
56
|
+
orderNumber.slice(4, 11),
|
|
57
|
+
orderNumber.slice(11)
|
|
58
|
+
].join(ORDER_NUMBER_SEPARATOR)}`;
|
|
86
59
|
return orderNumber;
|
|
87
60
|
}
|
|
88
61
|
async decrypt(id) {
|
|
@@ -97,41 +70,40 @@ class OrderNumberRepo {
|
|
|
97
70
|
throw new factory_1.factory.errors.NotImplemented('no version not implemented');
|
|
98
71
|
}
|
|
99
72
|
}
|
|
73
|
+
clearSettingCache() {
|
|
74
|
+
OrderNumberRepo.cacheExpiry = 0;
|
|
75
|
+
OrderNumberRepo.cachedSettings = undefined;
|
|
76
|
+
}
|
|
100
77
|
/**
|
|
101
78
|
* 注文番号生成設定を検索する
|
|
102
79
|
*/
|
|
103
80
|
async findSetting() {
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
// キャッシュ参照(2026-06-22~)
|
|
83
|
+
if (OrderNumberRepo.cachedSettings !== undefined && now < OrderNumberRepo.cacheExpiry) {
|
|
84
|
+
return OrderNumberRepo.cachedSettings;
|
|
85
|
+
}
|
|
104
86
|
const filterQuery = { 'project.id': { $eq: '*' } };
|
|
105
|
-
const
|
|
87
|
+
const setting = await this.settingModel.findOne(filterQuery, {
|
|
106
88
|
_id: 0,
|
|
107
89
|
orderNumber: 1
|
|
108
|
-
}
|
|
109
|
-
const setting = await this.settingModel.findOne(filterQuery, projection)
|
|
90
|
+
})
|
|
110
91
|
.lean()
|
|
111
92
|
.exec();
|
|
112
93
|
if (setting === null || setting.orderNumber === undefined) {
|
|
113
|
-
|
|
114
|
-
// versioningForceProjects: []
|
|
115
|
-
// versioningExceptionProjects: []
|
|
116
|
-
};
|
|
94
|
+
throw new factory_1.factory.errors.NotFound('setting.orderNumber');
|
|
117
95
|
}
|
|
118
|
-
const { fpeSecret, version
|
|
96
|
+
const { fpeSecret, version } = setting.orderNumber;
|
|
119
97
|
if (typeof fpeSecret !== 'string' || fpeSecret === '') {
|
|
120
98
|
throw new factory_1.factory.errors.NotFound('setting.orderNumber.secret');
|
|
121
99
|
}
|
|
122
100
|
if (typeof version !== 'string' || version === '') {
|
|
123
101
|
throw new factory_1.factory.errors.NotFound('setting.orderNumber.version');
|
|
124
102
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
129
|
-
fpeSecret, version, validFrom
|
|
130
|
-
// versioningForceProjects: [
|
|
131
|
-
// ...(Array.isArray(versioningForceProjects)) ? versioningForceProjects : []
|
|
132
|
-
// ]
|
|
133
|
-
// versioningExceptionProjects: (Array.isArray(versioningExceptionProjects)) ? versioningExceptionProjects : []
|
|
134
|
-
};
|
|
103
|
+
// キャッシュを更新
|
|
104
|
+
OrderNumberRepo.cachedSettings = { fpeSecret, version };
|
|
105
|
+
OrderNumberRepo.cacheExpiry = now + OrderNumberRepo.CACHE_TTL_MS;
|
|
106
|
+
return OrderNumberRepo.cachedSettings;
|
|
135
107
|
}
|
|
136
108
|
}
|
|
137
109
|
exports.OrderNumberRepo = OrderNumberRepo;
|
|
@@ -20,7 +20,6 @@ interface IOptions {
|
|
|
20
20
|
secret: string;
|
|
21
21
|
passportValidator?: IPassportValidator;
|
|
22
22
|
}
|
|
23
|
-
type IStartParams = (factory.transaction.placeOrder.IStartParamsWithoutDetail) & {};
|
|
24
23
|
/**
|
|
25
24
|
* 取引許可証リポジトリ
|
|
26
25
|
*/
|
|
@@ -34,7 +33,11 @@ export declare class PassportRepo {
|
|
|
34
33
|
/**
|
|
35
34
|
* 許可証トークンがあれば検証する
|
|
36
35
|
*/
|
|
37
|
-
validatePassportTokenIfExist(params:
|
|
36
|
+
validatePassportTokenIfExist(params: {
|
|
37
|
+
object?: {
|
|
38
|
+
passport?: factory.transaction.IPassportBeforeStart;
|
|
39
|
+
};
|
|
40
|
+
}): Promise<{
|
|
38
41
|
passport?: IVerifiedPassport;
|
|
39
42
|
customerType?: string;
|
|
40
43
|
}>;
|
|
@@ -122,16 +122,18 @@ class PlaceOrderRepo {
|
|
|
122
122
|
if (Array.isArray(sellerIdIn)) {
|
|
123
123
|
andConditions.push({ 'seller.id': { $exists: true, $in: sellerIdIn } });
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
125
|
+
// result.orderは完全に廃止したので検索条件としても廃止(2026-06-26~)
|
|
126
|
+
// const resultOrderNumberIn = params.result?.order?.orderNumbers;
|
|
127
|
+
// if (Array.isArray(resultOrderNumberIn)) {
|
|
128
|
+
// andConditions.push({ 'result.order.orderNumber': { $exists: true, $in: resultOrderNumberIn } });
|
|
129
|
+
// }
|
|
130
|
+
// result.orderは完全に廃止したので検索条件としても廃止(2026-06-26~)
|
|
131
|
+
// const resultOrderConfirmationNumberEq = params.result?.order?.confirmationNumber?.$eq;
|
|
132
|
+
// if (typeof resultOrderConfirmationNumberEq === 'string') {
|
|
133
|
+
// andConditions.push({
|
|
134
|
+
// 'result.order.confirmationNumber': { $exists: true, $eq: resultOrderConfirmationNumberEq }
|
|
135
|
+
// });
|
|
136
|
+
// }
|
|
135
137
|
const objectOrderNumberEq = params.object?.orderNumber?.$eq;
|
|
136
138
|
if (typeof objectOrderNumberEq === 'string') {
|
|
137
139
|
andConditions.push({ 'object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Connection } from 'mongoose';
|
|
1
|
+
import type { Connection, UpdateQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
3
|
import { IDocType } from './mongoose/schemas/transaction';
|
|
4
4
|
interface IAggregationByStatus {
|
|
@@ -116,6 +116,10 @@ export declare class TransactionRepo {
|
|
|
116
116
|
filter: any;
|
|
117
117
|
$unset: any;
|
|
118
118
|
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
119
|
+
updateById4migration(params: {
|
|
120
|
+
id: string;
|
|
121
|
+
update: UpdateQuery<IDocType>;
|
|
122
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
119
123
|
/**
|
|
120
124
|
* 終了日時を一定期間過ぎたアクションを削除する
|
|
121
125
|
*/
|
|
@@ -126,7 +130,7 @@ export declare class TransactionRepo {
|
|
|
126
130
|
$lt: Date;
|
|
127
131
|
};
|
|
128
132
|
}): Promise<import("mongodb").DeleteResult>;
|
|
129
|
-
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
133
|
+
getCursor(conditions: any, projection: any, sort?: factory.sortType): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
130
134
|
object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
|
|
131
135
|
error?: any;
|
|
132
136
|
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
@@ -297,6 +297,10 @@ class TransactionRepo {
|
|
|
297
297
|
return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
298
298
|
.exec();
|
|
299
299
|
}
|
|
300
|
+
async updateById4migration(params) {
|
|
301
|
+
return this.transactionModel.updateOne({ _id: { $eq: params.id } }, params.update)
|
|
302
|
+
.exec();
|
|
303
|
+
}
|
|
300
304
|
/**
|
|
301
305
|
* 終了日時を一定期間過ぎたアクションを削除する
|
|
302
306
|
*/
|
|
@@ -312,9 +316,9 @@ class TransactionRepo {
|
|
|
312
316
|
})
|
|
313
317
|
.exec();
|
|
314
318
|
}
|
|
315
|
-
getCursor(conditions, projection) {
|
|
319
|
+
getCursor(conditions, projection, sort) {
|
|
316
320
|
return this.transactionModel.find(conditions, projection)
|
|
317
|
-
.sort({ startDate: factory_1.factory.sortType.Descending })
|
|
321
|
+
.sort({ startDate: (sort === factory_1.factory.sortType.Ascending) ? sort : factory_1.factory.sortType.Descending })
|
|
318
322
|
.cursor();
|
|
319
323
|
}
|
|
320
324
|
async aggregatePlaceOrder(params) {
|
|
@@ -15,7 +15,6 @@ import type { PaymentServiceRepo } from '../../../repo/paymentService';
|
|
|
15
15
|
import { SeatRepo } from '../../../repo/place/seat';
|
|
16
16
|
import type { PriceSpecificationRepo } from '../../../repo/priceSpecification';
|
|
17
17
|
import type { ProductRepo } from '../../../repo/product';
|
|
18
|
-
import type { ProjectRepo } from '../../../repo/project';
|
|
19
18
|
import type { OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
|
|
20
19
|
import type { SettingRepo } from '../../../repo/setting';
|
|
21
20
|
import type { StockHolderRepo } from '../../../repo/stockHolder';
|
|
@@ -37,7 +36,6 @@ interface IStartOperationRepos {
|
|
|
37
36
|
paymentService: PaymentServiceRepo;
|
|
38
37
|
product: ProductRepo;
|
|
39
38
|
priceSpecification: PriceSpecificationRepo;
|
|
40
|
-
project: ProjectRepo;
|
|
41
39
|
seat: SeatRepo;
|
|
42
40
|
setting: SettingRepo;
|
|
43
41
|
task: TaskRepo;
|
|
@@ -6,16 +6,11 @@ interface IAcceptOfferOperationRepos {
|
|
|
6
6
|
type IAcceptOfferOperation<T> = (repos: IAcceptOfferOperationRepos) => Promise<T>;
|
|
7
7
|
export type IAuthorizeActionWithInstrument = Pick<factory.action.authorize.offer.eventService.IAction, 'instrument'>;
|
|
8
8
|
export declare function acceptOffer(params: {
|
|
9
|
-
orderNumber: string;
|
|
10
9
|
project: {
|
|
11
10
|
id: string;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* COA以外では注文ドキュメントにpriceSpecificationが存在しないのでIFを補完
|
|
16
|
-
*/
|
|
17
|
-
priceSpecification?: factory.order.ITicketPriceSpecification;
|
|
18
|
-
})[];
|
|
12
|
+
placeOrderId: string;
|
|
13
|
+
acceptedOffers: IMinimizedAcceptedOffer[] | factory.order.ICOAAcceptedOffer[];
|
|
19
14
|
}): IAcceptOfferOperation<void>;
|
|
20
15
|
export declare function voidAcceptedOffer(params: {
|
|
21
16
|
/**
|
|
@@ -25,7 +20,7 @@ export declare function voidAcceptedOffer(params: {
|
|
|
25
20
|
* instrument.serialNumberからvoidする場合に指定
|
|
26
21
|
*/
|
|
27
22
|
authorizeActionsWithInstrument: IAuthorizeActionWithInstrument[];
|
|
28
|
-
|
|
23
|
+
placeOrderId: string;
|
|
29
24
|
}): (repos: {
|
|
30
25
|
orderInTransaction: OrderInTransactionRepo;
|
|
31
26
|
}) => Promise<void>;
|
|
@@ -10,16 +10,16 @@ const factory_1 = require("../../factory");
|
|
|
10
10
|
const debug = (0, debug_1.default)('chevre-domain:service:offer');
|
|
11
11
|
function acceptOffer(params) {
|
|
12
12
|
return async (repos) => {
|
|
13
|
-
await repos.orderInTransaction.
|
|
14
|
-
orderNumber: params.orderNumber,
|
|
13
|
+
await repos.orderInTransaction.acceptOfferByIdentifier({
|
|
15
14
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
15
|
+
identifier: params.placeOrderId,
|
|
16
16
|
acceptedOffers: params.acceptedOffers
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
function voidAcceptedOffer(params) {
|
|
21
21
|
return async (repos) => {
|
|
22
|
-
const {
|
|
22
|
+
const { placeOrderId } = params;
|
|
23
23
|
// let reservationNumbers: string[] = [];
|
|
24
24
|
// authorizeActions.forEach((authorizeAction) => {
|
|
25
25
|
// const reserveTransactionNumberByAction = authorizeAction.object.pendingTransaction?.transactionNumber;
|
|
@@ -40,10 +40,11 @@ function voidAcceptedOffer(params) {
|
|
|
40
40
|
const serialNumbers = params.authorizeActionsWithInstrument
|
|
41
41
|
.filter(({ instrument }) => typeof instrument.transactionNumber === 'string')
|
|
42
42
|
.map(({ instrument }) => String(instrument.transactionNumber));
|
|
43
|
-
debug('removing acceptedOffers from PlaceOrder...',
|
|
43
|
+
debug('removing acceptedOffers from PlaceOrder...', placeOrderId, 'serialNumbers:', serialNumbers);
|
|
44
44
|
if (serialNumbers.length > 0) {
|
|
45
|
-
const result = await repos.orderInTransaction.
|
|
46
|
-
orderNumber,
|
|
45
|
+
const result = await repos.orderInTransaction.voidAcceptedOfferByIdentifier({
|
|
46
|
+
// orderNumber,
|
|
47
|
+
identifier: placeOrderId,
|
|
47
48
|
acceptedOffers: { serialNumber: { $in: serialNumbers } }
|
|
48
49
|
});
|
|
49
50
|
debug('acceptedOffers removed from PlaceOrder by serialNumbers.', result);
|
|
@@ -15,7 +15,6 @@ import type { PaymentServiceRepo } from '../../../../repo/paymentService';
|
|
|
15
15
|
import type { SeatRepo } from '../../../../repo/place/seat';
|
|
16
16
|
import type { PriceSpecificationRepo } from '../../../../repo/priceSpecification';
|
|
17
17
|
import type { ProductRepo } from '../../../../repo/product';
|
|
18
|
-
import type { ProjectRepo } from '../../../../repo/project';
|
|
19
18
|
import type { OfferRateLimitRepo } from '../../../../repo/rateLimit/offer';
|
|
20
19
|
import type { SettingRepo } from '../../../../repo/setting';
|
|
21
20
|
import type { StockHolderRepo } from '../../../../repo/stockHolder';
|
|
@@ -63,7 +62,6 @@ declare function processStartReserve4chevre(params: {
|
|
|
63
62
|
paymentService: PaymentServiceRepo;
|
|
64
63
|
product: ProductRepo;
|
|
65
64
|
priceSpecification: PriceSpecificationRepo;
|
|
66
|
-
project: ProjectRepo;
|
|
67
65
|
seat: SeatRepo;
|
|
68
66
|
setting: SettingRepo;
|
|
69
67
|
task: TaskRepo;
|