@chevre/domain 25.0.0-alpha.19 → 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/repo/orderInTransaction.d.ts +15 -25
- package/lib/chevre/repo/orderInTransaction.js +24 -46
- package/lib/chevre/service/offer/any.d.ts +1 -2
- package/lib/chevre/service/offer/any.js +6 -6
- package/lib/chevre/service/offer/event/authorize.js +0 -1
- 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.js +5 -5
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +5 -6
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +19 -16
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +3 -2
- 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 +3 -3
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +0 -4
- package/lib/chevre/service/transaction/placeOrder/confirm.js +6 -5
- package/lib/chevre/service/transaction/placeOrder/issueOrderNumberIfNotExist.js +0 -9
- package/lib/chevre/service/transaction/placeOrder/updateAgent.js +8 -9
- package/package.json +1 -1
|
@@ -79,21 +79,18 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
|
79
79
|
onlyPlaceOrder: boolean;
|
|
80
80
|
}): Promise<string>;
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
82
|
+
* 注文ドキュメントからcustomer属性を参照する
|
|
83
|
+
* customer未設定であれば、NotFound
|
|
84
84
|
*/
|
|
85
|
-
|
|
85
|
+
findCustomerByOrderIdentifier(params: {
|
|
86
86
|
identifier: string;
|
|
87
|
-
|
|
88
|
-
id: string;
|
|
89
|
-
};
|
|
90
|
-
}): Promise<Pick<IOrderInTransaction, 'customer'>>;
|
|
87
|
+
}): Promise<factory.order.ICustomer>;
|
|
91
88
|
/**
|
|
92
89
|
* 取引進行中の注文からacceptedOffersを検索する
|
|
93
90
|
* 予約取引から予約ごとの価格仕様も参照する
|
|
94
91
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
findAcceptedOffersWithPriceByIdentifier(params: {
|
|
93
|
+
identifier: string;
|
|
97
94
|
project: {
|
|
98
95
|
id: string;
|
|
99
96
|
};
|
|
@@ -104,20 +101,22 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
|
104
101
|
* 注文を受注する
|
|
105
102
|
* typeOf: PlaceOrder -> typeOf: Order
|
|
106
103
|
*/
|
|
107
|
-
|
|
104
|
+
placeOrderByIdentifier(filter: {
|
|
105
|
+
identifier: string;
|
|
106
|
+
}, order: IPlacingOrder): Promise<void>;
|
|
108
107
|
/**
|
|
109
108
|
* 注文documentがなければ作成し、受け入れられたオファーを追加する
|
|
110
109
|
* このメソッドでdocumentが初めて生成される(typeOf:PlaceOrderとして)
|
|
111
110
|
*/
|
|
112
|
-
|
|
111
|
+
acceptOfferByIdentifier(params: Pick<IOrderInTransaction, 'project' | 'identifier'> & {
|
|
113
112
|
acceptedOffers: IMinimizedAcceptedOffer[] | factory.order.ICOAAcceptedOffer[];
|
|
114
113
|
}): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
115
114
|
/**
|
|
116
115
|
* serialNumberからオファーを除外する
|
|
117
116
|
* ホワイトリストとブラックリスト両方に対応
|
|
118
117
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
voidAcceptedOfferByIdentifier(params: {
|
|
119
|
+
identifier: string;
|
|
121
120
|
acceptedOffers: {
|
|
122
121
|
serialNumber: {
|
|
123
122
|
$in?: string[];
|
|
@@ -125,20 +124,11 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
|
125
124
|
};
|
|
126
125
|
};
|
|
127
126
|
}): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
128
|
-
|
|
127
|
+
setCustomerByIdentifier(params: Pick<IOrderInTransaction, 'project' | 'identifier'> & {
|
|
129
128
|
customer: factory.order.ICustomer;
|
|
130
129
|
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
* customer未設定であれば、NotFound
|
|
134
|
-
*/
|
|
135
|
-
findCustomerByOrderNumber(params: {
|
|
136
|
-
orderNumber: {
|
|
137
|
-
$eq: string;
|
|
138
|
-
};
|
|
139
|
-
}): Promise<factory.order.ICustomer>;
|
|
140
|
-
deleteByOrderNumber(params: {
|
|
141
|
-
orderNumber: string;
|
|
130
|
+
deleteByIdentifier(params: {
|
|
131
|
+
identifier: string;
|
|
142
132
|
}): Promise<import("mongodb").DeleteResult>;
|
|
143
133
|
}
|
|
144
134
|
export {};
|
|
@@ -68,15 +68,13 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
68
68
|
return doc.orderNumber;
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
* 注文ドキュメントからcustomer属性を参照する
|
|
72
|
+
* customer未設定であれば、NotFound
|
|
73
73
|
*/
|
|
74
|
-
async
|
|
75
|
-
const { project, identifier } = params;
|
|
74
|
+
async findCustomerByOrderIdentifier(params) {
|
|
76
75
|
const doc = await this.orderModel.findOne({
|
|
77
|
-
identifier: { $eq: identifier }
|
|
78
|
-
typeOf: { $eq:
|
|
79
|
-
'project.id': { $eq: project.id }
|
|
76
|
+
identifier: { $eq: params.identifier }
|
|
77
|
+
// typeOf: { $eq: factory.transactionType.PlaceOrder } // 検証しない
|
|
80
78
|
}, {
|
|
81
79
|
_id: 0,
|
|
82
80
|
customer: 1
|
|
@@ -86,15 +84,18 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
86
84
|
if (doc === null) {
|
|
87
85
|
throw new factory_1.factory.errors.NotFound('orderInTransaction');
|
|
88
86
|
}
|
|
89
|
-
|
|
87
|
+
if (typeof doc.customer?.typeOf !== 'string') {
|
|
88
|
+
throw new factory_1.factory.errors.NotFound('orderInTransaction.customer');
|
|
89
|
+
}
|
|
90
|
+
return doc.customer;
|
|
90
91
|
}
|
|
91
92
|
/**
|
|
92
93
|
* 取引進行中の注文からacceptedOffersを検索する
|
|
93
94
|
* 予約取引から予約ごとの価格仕様も参照する
|
|
94
95
|
*/
|
|
95
|
-
async
|
|
96
|
+
async findAcceptedOffersWithPriceByIdentifier(params) {
|
|
96
97
|
const doc = await this.orderModel.findOne({
|
|
97
|
-
|
|
98
|
+
identifier: { $eq: params.identifier },
|
|
98
99
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
|
|
99
100
|
}, { acceptedOffers: 1 })
|
|
100
101
|
.lean()
|
|
@@ -136,16 +137,15 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
136
137
|
* 注文を受注する
|
|
137
138
|
* typeOf: PlaceOrder -> typeOf: Order
|
|
138
139
|
*/
|
|
139
|
-
async
|
|
140
|
+
async placeOrderByIdentifier(filter, order) {
|
|
141
|
+
const { identifier } = filter;
|
|
140
142
|
if (!(order.orderDate instanceof Date)) {
|
|
141
143
|
throw new factory_1.factory.errors.Argument('orderDate', 'must be Date');
|
|
142
144
|
}
|
|
143
|
-
// acceptedOffersを上書きしない
|
|
144
|
-
// const { acceptedOffers, ...orderWithoutAcceptedOffers } = order;
|
|
145
145
|
const setFields = order;
|
|
146
146
|
// typeOf:PlaceOrderのドキュメントが存在すれば、typeOf:Orderに変更する
|
|
147
147
|
await this.orderModel.updateOne({
|
|
148
|
-
|
|
148
|
+
identifier: { $eq: identifier },
|
|
149
149
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
|
|
150
150
|
}, { $set: setFields }, {})
|
|
151
151
|
.exec();
|
|
@@ -154,15 +154,13 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
154
154
|
* 注文documentがなければ作成し、受け入れられたオファーを追加する
|
|
155
155
|
* このメソッドでdocumentが初めて生成される(typeOf:PlaceOrderとして)
|
|
156
156
|
*/
|
|
157
|
-
async
|
|
157
|
+
async acceptOfferByIdentifier(params) {
|
|
158
158
|
if (!Array.isArray(params.acceptedOffers) || params.acceptedOffers.length === 0) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
-
// const { orderNumber, project, identifier } = params;
|
|
162
|
-
// await this.createPlaceOrderIfNotExists({ orderNumber, project, identifier }); // 取引開始時に完全移行(2026-06-25~)
|
|
163
161
|
const result = await this.orderModel.updateOne({
|
|
164
162
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
165
|
-
|
|
163
|
+
identifier: { $eq: params.identifier },
|
|
166
164
|
// プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
|
|
167
165
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
168
166
|
'project.id': { $eq: params.project.id }
|
|
@@ -187,13 +185,13 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
187
185
|
* serialNumberからオファーを除外する
|
|
188
186
|
* ホワイトリストとブラックリスト両方に対応
|
|
189
187
|
*/
|
|
190
|
-
async
|
|
188
|
+
async voidAcceptedOfferByIdentifier(params) {
|
|
191
189
|
const serialNumberIn = params.acceptedOffers.serialNumber.$in;
|
|
192
190
|
const serialNumberNin = params.acceptedOffers.serialNumber.$nin;
|
|
193
191
|
if (Array.isArray(serialNumberIn) && serialNumberIn.length > 0) {
|
|
194
192
|
return this.orderModel.updateOne({
|
|
195
193
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
196
|
-
|
|
194
|
+
identifier: { $eq: params.identifier }
|
|
197
195
|
}, {
|
|
198
196
|
$pull: {
|
|
199
197
|
acceptedOffers: {
|
|
@@ -206,7 +204,7 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
206
204
|
else if (Array.isArray(serialNumberNin) && serialNumberNin.length > 0) {
|
|
207
205
|
return this.orderModel.updateOne({
|
|
208
206
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
209
|
-
|
|
207
|
+
identifier: { $eq: params.identifier }
|
|
210
208
|
}, {
|
|
211
209
|
$pull: {
|
|
212
210
|
acceptedOffers: {
|
|
@@ -220,16 +218,15 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
220
218
|
return;
|
|
221
219
|
}
|
|
222
220
|
}
|
|
223
|
-
async
|
|
224
|
-
const { customer,
|
|
221
|
+
async setCustomerByIdentifier(params) {
|
|
222
|
+
const { customer, identifier, project } = params;
|
|
225
223
|
const filter = {
|
|
226
224
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
227
|
-
|
|
225
|
+
identifier: { $eq: identifier },
|
|
228
226
|
// プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
|
|
229
227
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
230
228
|
'project.id': { $eq: project.id }
|
|
231
229
|
};
|
|
232
|
-
// await this.createPlaceOrderIfNotExists({ orderNumber, project, identifier }); // 取引開始時に完全移行(2026-06-25~)
|
|
233
230
|
const setKeys = { customer };
|
|
234
231
|
const result = await this.orderModel.updateOne(filter, {
|
|
235
232
|
// $setOnInsert: setOnInsert, // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
@@ -244,29 +241,10 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
244
241
|
}
|
|
245
242
|
return result;
|
|
246
243
|
}
|
|
247
|
-
|
|
248
|
-
* 注文ドキュメントからcustomer属性を参照する
|
|
249
|
-
* customer未設定であれば、NotFound
|
|
250
|
-
*/
|
|
251
|
-
async findCustomerByOrderNumber(params) {
|
|
252
|
-
const doc = await this.orderModel.findOne({
|
|
253
|
-
orderNumber: { $eq: params.orderNumber.$eq }
|
|
254
|
-
// typeOf: { $eq: factory.transactionType.PlaceOrder } // 検証しない
|
|
255
|
-
}, { customer: 1 })
|
|
256
|
-
.lean()
|
|
257
|
-
.exec();
|
|
258
|
-
if (doc === null) {
|
|
259
|
-
throw new factory_1.factory.errors.NotFound('orderInTransaction');
|
|
260
|
-
}
|
|
261
|
-
if (typeof doc.customer?.typeOf !== 'string') {
|
|
262
|
-
throw new factory_1.factory.errors.NotFound('orderInTransaction.customer');
|
|
263
|
-
}
|
|
264
|
-
return doc.customer;
|
|
265
|
-
}
|
|
266
|
-
async deleteByOrderNumber(params) {
|
|
244
|
+
async deleteByIdentifier(params) {
|
|
267
245
|
return this.orderModel.deleteOne({
|
|
268
246
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
269
|
-
|
|
247
|
+
identifier: { $eq: params.identifier }
|
|
270
248
|
})
|
|
271
249
|
.exec();
|
|
272
250
|
}
|
|
@@ -6,7 +6,6 @@ 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
|
};
|
|
@@ -21,7 +20,7 @@ export declare function voidAcceptedOffer(params: {
|
|
|
21
20
|
* instrument.serialNumberからvoidする場合に指定
|
|
22
21
|
*/
|
|
23
22
|
authorizeActionsWithInstrument: IAuthorizeActionWithInstrument[];
|
|
24
|
-
|
|
23
|
+
placeOrderId: string;
|
|
25
24
|
}): (repos: {
|
|
26
25
|
orderInTransaction: OrderInTransactionRepo;
|
|
27
26
|
}) => Promise<void>;
|
|
@@ -10,8 +10,7 @@ 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 },
|
|
16
15
|
identifier: params.placeOrderId,
|
|
17
16
|
acceptedOffers: params.acceptedOffers
|
|
@@ -20,7 +19,7 @@ function acceptOffer(params) {
|
|
|
20
19
|
}
|
|
21
20
|
function voidAcceptedOffer(params) {
|
|
22
21
|
return async (repos) => {
|
|
23
|
-
const {
|
|
22
|
+
const { placeOrderId } = params;
|
|
24
23
|
// let reservationNumbers: string[] = [];
|
|
25
24
|
// authorizeActions.forEach((authorizeAction) => {
|
|
26
25
|
// const reserveTransactionNumberByAction = authorizeAction.object.pendingTransaction?.transactionNumber;
|
|
@@ -41,10 +40,11 @@ function voidAcceptedOffer(params) {
|
|
|
41
40
|
const serialNumbers = params.authorizeActionsWithInstrument
|
|
42
41
|
.filter(({ instrument }) => typeof instrument.transactionNumber === 'string')
|
|
43
42
|
.map(({ instrument }) => String(instrument.transactionNumber));
|
|
44
|
-
debug('removing acceptedOffers from PlaceOrder...',
|
|
43
|
+
debug('removing acceptedOffers from PlaceOrder...', placeOrderId, 'serialNumbers:', serialNumbers);
|
|
45
44
|
if (serialNumbers.length > 0) {
|
|
46
|
-
const result = await repos.orderInTransaction.
|
|
47
|
-
orderNumber,
|
|
45
|
+
const result = await repos.orderInTransaction.voidAcceptedOfferByIdentifier({
|
|
46
|
+
// orderNumber,
|
|
47
|
+
identifier: placeOrderId,
|
|
48
48
|
acceptedOffers: { serialNumber: { $in: serialNumbers } }
|
|
49
49
|
});
|
|
50
50
|
debug('acceptedOffers removed from PlaceOrder by serialNumbers.', result);
|
|
@@ -48,23 +48,35 @@ function voidTransaction(params) {
|
|
|
48
48
|
default:
|
|
49
49
|
// no op
|
|
50
50
|
}
|
|
51
|
-
// add orderInTransaction(2024-01-15~)
|
|
52
|
-
// USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
|
|
53
|
-
const orderNumberByTransaction = transaction.object.orderNumber;
|
|
54
|
-
if (typeof orderNumberByTransaction === 'string') {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
// // add orderInTransaction(2024-01-15~)
|
|
52
|
+
// // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
|
|
53
|
+
// const orderNumberByTransaction = transaction.object.orderNumber;
|
|
54
|
+
// if (typeof orderNumberByTransaction === 'string') {
|
|
55
|
+
// switch (transaction.status) {
|
|
56
|
+
// case factory.transactionStatusType.Confirmed:
|
|
57
|
+
// // 確定取引の場合、不要なオファーのみ除外
|
|
58
|
+
// await voidAcceptedOffer({
|
|
59
|
+
// // authorizeActions,
|
|
60
|
+
// authorizeActionsWithInstrument: authorizeActions,
|
|
61
|
+
// orderNumber: orderNumberByTransaction
|
|
62
|
+
// })(repos);
|
|
63
|
+
// break;
|
|
64
|
+
// default:
|
|
65
|
+
// // orderInTransaction自体を削除
|
|
66
|
+
// await repos.orderInTransaction.deleteByOrderNumber({ orderNumber: orderNumberByTransaction });
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
switch (transaction.status) {
|
|
70
|
+
case factory_1.factory.transactionStatusType.Confirmed:
|
|
71
|
+
// 確定取引の場合、不要なオファーのみ除外
|
|
72
|
+
await (0, any_1.voidAcceptedOffer)({
|
|
73
|
+
authorizeActionsWithInstrument: authorizeActions,
|
|
74
|
+
placeOrderId: params.purpose.id
|
|
75
|
+
})(repos);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
// orderInTransaction自体を削除
|
|
79
|
+
await repos.orderInTransaction.deleteByIdentifier({ identifier: params.purpose.id });
|
|
68
80
|
}
|
|
69
81
|
await Promise.all(authorizeActions.map(async (action) => {
|
|
70
82
|
await repos.authorizeOfferAction.cancelWithVoid({ typeOf: action.typeOf, id: action.id, cancelAction });
|
|
@@ -26,7 +26,7 @@ function voidTransactionByActionId(params) {
|
|
|
26
26
|
// if (transaction.agent.id !== params.agent.id) {
|
|
27
27
|
// throw new factory.errors.Forbidden('Transaction not yours');
|
|
28
28
|
// }
|
|
29
|
-
const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.purpose.id });
|
|
29
|
+
// const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.purpose.id });
|
|
30
30
|
const action = await repos.authorizeOfferAction.findById({ typeOf: factory_1.factory.actionType.AuthorizeAction, id: params.id });
|
|
31
31
|
if (action.purpose.typeOf !== transaction.typeOf || action.purpose.id !== transaction.id) {
|
|
32
32
|
throw new factory_1.factory.errors.Argument('Transaction', 'Action not found in the transaction');
|
|
@@ -34,17 +34,21 @@ function voidTransactionByActionId(params) {
|
|
|
34
34
|
// MongoDBでcompleteステータスであるにも関わらず、Chevreでは削除されている、というのが最悪の状況
|
|
35
35
|
// それだけは回避するためにMongoDBを先に変更
|
|
36
36
|
await repos.authorizeOfferAction.cancelWithVoid({ typeOf: factory_1.factory.actionType.AuthorizeAction, id: params.id, cancelAction });
|
|
37
|
-
// add orderInTransaction(2024-01-15~)
|
|
38
|
-
// USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
|
|
39
|
-
// const orderNumberByTransaction = transaction.object.orderNumber;
|
|
40
|
-
const orderNumberByTransaction = orderNumber; // transaction.objectへのアクセス回避(2024-05-30~)
|
|
41
|
-
if (typeof orderNumberByTransaction === 'string') {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
37
|
+
// // add orderInTransaction(2024-01-15~)
|
|
38
|
+
// // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
|
|
39
|
+
// // const orderNumberByTransaction = transaction.object.orderNumber;
|
|
40
|
+
// const orderNumberByTransaction = orderNumber; // transaction.objectへのアクセス回避(2024-05-30~)
|
|
41
|
+
// if (typeof orderNumberByTransaction === 'string') {
|
|
42
|
+
// await voidAcceptedOffer({
|
|
43
|
+
// // authorizeActions: [action],
|
|
44
|
+
// authorizeActionsWithInstrument: [action],
|
|
45
|
+
// orderNumber: orderNumberByTransaction
|
|
46
|
+
// })(repos);
|
|
47
|
+
// }
|
|
48
|
+
await (0, any_1.voidAcceptedOffer)({
|
|
49
|
+
authorizeActionsWithInstrument: [action],
|
|
50
|
+
placeOrderId: params.purpose.id
|
|
51
|
+
})(repos);
|
|
48
52
|
switch (action.instrument.typeOf) {
|
|
49
53
|
case factory_1.factory.assetTransactionType.COAReserveTransaction: {
|
|
50
54
|
const { reserveService } = repos;
|
|
@@ -123,11 +123,11 @@ function reAcceptOffer(params) {
|
|
|
123
123
|
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
124
124
|
id: params.purpose.id
|
|
125
125
|
}, ['project', 'agent', 'typeOf']);
|
|
126
|
-
const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: transaction.id });
|
|
127
|
-
if (typeof orderNumber !== 'string') {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
126
|
+
// const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: transaction.id });
|
|
127
|
+
// if (typeof orderNumber !== 'string') {
|
|
128
|
+
// // 事前に発行されているはず
|
|
129
|
+
// throw new factory.errors.NotFound('transaction.object.orderNumber');
|
|
130
|
+
// }
|
|
131
131
|
const coaInfo = await findCOAInfo({ id: params.object.event.id, project: { id: transaction.project.id } })(repos);
|
|
132
132
|
// 承認アクション存在検証
|
|
133
133
|
await repos.authorizeOfferAction.findById({ id: params.potentialActions.id, typeOf: factory_1.factory.actionType.AuthorizeAction }, ['id'], []);
|
|
@@ -80,11 +80,11 @@ function authorize(params) {
|
|
|
80
80
|
await repos.action.giveUp({ typeOf: failedAction.typeOf, id: failedAction.id, error });
|
|
81
81
|
throw error;
|
|
82
82
|
}
|
|
83
|
-
const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
|
|
84
|
-
if (typeof orderNumber !== 'string') {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
83
|
+
// const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
|
|
84
|
+
// if (typeof orderNumber !== 'string') {
|
|
85
|
+
// // 事前に発行されているはず(acceptCOAOfferにて)
|
|
86
|
+
// throw new factory.errors.NotFound('transaction.object.orderNumber');
|
|
87
|
+
// }
|
|
88
88
|
let result;
|
|
89
89
|
// 承認アクションを開始
|
|
90
90
|
const actionAttributes = (0, factory_1.createAuthorizeSeatReservationActionAttributes)({
|
|
@@ -117,7 +117,6 @@ function authorize(params) {
|
|
|
117
117
|
// add orderInTransaction(2024-01-15~)
|
|
118
118
|
// if (params.options.useCreateOrderOnOfferAccepted) {
|
|
119
119
|
await (0, any_1.acceptOffer)({
|
|
120
|
-
orderNumber,
|
|
121
120
|
project: transaction.project,
|
|
122
121
|
placeOrderId: params.transaction.id,
|
|
123
122
|
acceptedOffers: acceptedOffers4result
|
|
@@ -22,11 +22,11 @@ function changeOffers(params) {
|
|
|
22
22
|
if (transaction.agent.id !== params.agent.id) {
|
|
23
23
|
throw new factory_2.factory.errors.Forbidden('Transaction not yours');
|
|
24
24
|
}
|
|
25
|
-
const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
|
|
26
|
-
if (typeof orderNumber !== 'string') {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
25
|
+
// const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
|
|
26
|
+
// if (typeof orderNumber !== 'string') {
|
|
27
|
+
// // 事前に発行されているはず
|
|
28
|
+
// throw new factory.errors.NotFound('transaction.object.orderNumber');
|
|
29
|
+
// }
|
|
30
30
|
// 取引内のアクションかどうか確認
|
|
31
31
|
const authorizeAction = await repos.action.findById({ typeOf: factory_2.factory.actionType.AuthorizeAction, id: params.id });
|
|
32
32
|
if (authorizeAction.purpose.typeOf !== transaction.typeOf || authorizeAction.purpose.id !== transaction.id) {
|
|
@@ -139,20 +139,23 @@ function changeOffers(params) {
|
|
|
139
139
|
// ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
|
|
140
140
|
await repos.action.reStart({ id: authorizeAction.id, typeOf: authorizeAction.typeOf });
|
|
141
141
|
try {
|
|
142
|
-
// まずvoidAcceptedOffer
|
|
143
|
-
// const orderNumberByTransaction = transaction.object.orderNumber;
|
|
144
|
-
const orderNumberByTransaction = orderNumber; // transaction.objectへのアクセス回避(2024-05-30~)
|
|
145
|
-
if (typeof orderNumberByTransaction === 'string') {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
142
|
+
// // まずvoidAcceptedOffer
|
|
143
|
+
// // const orderNumberByTransaction = transaction.object.orderNumber;
|
|
144
|
+
// const orderNumberByTransaction = orderNumber; // transaction.objectへのアクセス回避(2024-05-30~)
|
|
145
|
+
// if (typeof orderNumberByTransaction === 'string') {
|
|
146
|
+
// await voidAcceptedOffer({
|
|
147
|
+
// // authorizeActions: [authorizeAction],
|
|
148
|
+
// authorizeActionsWithInstrument: [authorizeAction],
|
|
149
|
+
// orderNumber: orderNumberByTransaction
|
|
150
|
+
// })(repos);
|
|
151
|
+
// }
|
|
152
|
+
await (0, any_1.voidAcceptedOffer)({
|
|
153
|
+
authorizeActionsWithInstrument: [authorizeAction],
|
|
154
|
+
placeOrderId: params.transaction.id
|
|
155
|
+
})(repos);
|
|
152
156
|
// add orderInTransaction(2024-01-15~)
|
|
153
157
|
// if (params.options.useCreateOrderOnOfferAccepted) {
|
|
154
158
|
await (0, any_1.acceptOffer)({
|
|
155
|
-
orderNumber,
|
|
156
159
|
project: transaction.project,
|
|
157
160
|
placeOrderId: params.transaction.id,
|
|
158
161
|
acceptedOffers: acceptedOffers4result
|
|
@@ -89,8 +89,9 @@ function createPlacingOrderFromExistingTransaction(params) {
|
|
|
89
89
|
.map(({ instrument }) => String(instrument.transactionNumber));
|
|
90
90
|
try {
|
|
91
91
|
// すでにtypeOf: Orderに変更済の場合acceptedOffersは空になるが、そもそもorderedItemはその後上書きされないので、空のまま処理して問題なし
|
|
92
|
-
acceptedOffers = (await repos.orderInTransaction.
|
|
93
|
-
orderNumber,
|
|
92
|
+
acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
|
|
93
|
+
// orderNumber,
|
|
94
|
+
identifier: placeOrderTransactionWithResult.id,
|
|
94
95
|
project: { id: params.project.id }
|
|
95
96
|
}))
|
|
96
97
|
.filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
2
2
|
declare function voidAcceptedOfferIfNecessary(params: {
|
|
3
|
-
|
|
4
|
-
orderNumber: string;
|
|
5
|
-
};
|
|
3
|
+
placeOrderId: string;
|
|
6
4
|
serialNumbers: string[];
|
|
7
5
|
}): (repos: {
|
|
8
6
|
orderInTransaction: OrderInTransactionRepo;
|
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.voidAcceptedOfferIfNecessary = voidAcceptedOfferIfNecessary;
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
// import type { TransactionRepo } from '../../../repo/transaction';
|
|
9
|
-
// import { factory } from '../../../factory';
|
|
10
|
-
const debug = (0, debug_1.default)('chevre-domain:service:order');
|
|
11
|
-
// type IPlaceOrderTransaction = Pick<
|
|
12
|
-
// factory.transaction.placeOrder.ITransaction,
|
|
13
|
-
// 'id' | 'project' | 'typeOf' | 'result' | 'object' | 'seller'
|
|
14
|
-
// >;
|
|
15
4
|
function voidAcceptedOfferIfNecessary(params) {
|
|
16
5
|
return async (repos) => {
|
|
17
6
|
if (Array.isArray(params.serialNumbers) && params.serialNumbers.length > 0) {
|
|
18
7
|
// 取引に保管された承認アクション以外のアクションについて、オファーを除外する
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
// const voidAcceptedOfferBySerialNumberResult =
|
|
9
|
+
await repos.orderInTransaction.voidAcceptedOfferByIdentifier({
|
|
10
|
+
identifier: params.placeOrderId,
|
|
22
11
|
acceptedOffers: { serialNumber: { $nin: params.serialNumbers } }
|
|
23
12
|
});
|
|
24
|
-
debug('voidAcceptedOfferBySerialNumber processed.', params.object.orderNumber, 'voidAcceptedOfferBySerialNumberResult:', voidAcceptedOfferBySerialNumberResult);
|
|
25
13
|
}
|
|
26
14
|
};
|
|
27
15
|
}
|
|
@@ -61,11 +61,11 @@ function placeOrder(params) {
|
|
|
61
61
|
try {
|
|
62
62
|
// 冗長なオファーを除外する(念のため)
|
|
63
63
|
await (0, voidAcceptedOfferIfNecessary_1.voidAcceptedOfferIfNecessary)({
|
|
64
|
-
object: { orderNumber: order.orderNumber },
|
|
65
|
-
|
|
64
|
+
// object: { orderNumber: order.orderNumber },
|
|
65
|
+
placeOrderId: placeOrderTransaction.id,
|
|
66
66
|
serialNumbers
|
|
67
67
|
})(repos);
|
|
68
|
-
await repos.orderInTransaction.
|
|
68
|
+
await repos.orderInTransaction.placeOrderByIdentifier({ identifier: placeOrderTransaction.id }, order);
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
|
71
71
|
try {
|
|
@@ -39,10 +39,6 @@ interface IConfirmOptions {
|
|
|
39
39
|
* 注文における最大CreditCardIF決済方法数
|
|
40
40
|
*/
|
|
41
41
|
maxNumCreditCardPaymentMethod: number;
|
|
42
|
-
/**
|
|
43
|
-
* 取引ドキュメントのresult.order,result,numAcceptedOffersを保管しないオプション(2026-06-15~)
|
|
44
|
-
*/
|
|
45
|
-
disableResultOrder: boolean;
|
|
46
42
|
}
|
|
47
43
|
type IConfirmParams = PlaceOrderFactory.IConfirmParams;
|
|
48
44
|
interface IConfirmResult {
|
|
@@ -23,8 +23,8 @@ function processTransactionNotInProgress(params) {
|
|
|
23
23
|
return async (repos) => {
|
|
24
24
|
const { transaction, orderNumber } = params;
|
|
25
25
|
if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
26
|
-
const resultCustomer = await repos.orderInTransaction.
|
|
27
|
-
|
|
26
|
+
const resultCustomer = await repos.orderInTransaction.findCustomerByOrderIdentifier({
|
|
27
|
+
identifier: transaction.id
|
|
28
28
|
});
|
|
29
29
|
// if (resultCustomer === undefined) {
|
|
30
30
|
// throw new factory.errors.Internal('resultCustomer undefined'); // impossible process
|
|
@@ -108,8 +108,9 @@ function confirm(params, options) {
|
|
|
108
108
|
// authorizeProductOfferActions,
|
|
109
109
|
serialNumbers } = dissolveAuthorizeActions(completedAuthorizeActions);
|
|
110
110
|
// orderInTransactionから検索する(2024-03-04~)
|
|
111
|
-
const acceptedOffers = (await repos.orderInTransaction.
|
|
112
|
-
orderNumber,
|
|
111
|
+
const acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
|
|
112
|
+
// orderNumber,
|
|
113
|
+
identifier: transaction.id,
|
|
113
114
|
project: { id: transaction.project.id }
|
|
114
115
|
}))
|
|
115
116
|
.filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
|
|
@@ -126,7 +127,7 @@ function confirm(params, options) {
|
|
|
126
127
|
}
|
|
127
128
|
// retrieve customer from orderInTransaction(2024-06-24~)
|
|
128
129
|
// let customer: factory.order.ICustomer = createCustomer({ transaction });
|
|
129
|
-
const customer = await repos.orderInTransaction.
|
|
130
|
+
const customer = await repos.orderInTransaction.findCustomerByOrderIdentifier({ identifier: transaction.id });
|
|
130
131
|
const seller = (0, factory_2.createSeller)({ transaction });
|
|
131
132
|
const { paymentMethods, placingOrder, result, eventId, reservationIds } = createResult({
|
|
132
133
|
...params,
|
|
@@ -8,15 +8,6 @@ const factory_1 = require("../../../factory");
|
|
|
8
8
|
*/
|
|
9
9
|
function issueOrderNumberIfNotExist(params) {
|
|
10
10
|
return async (repos) => {
|
|
11
|
-
// // issueForceオプションあるいは、廃止予定の発行オプションの場合、注文番号を新たに発行する
|
|
12
|
-
// const issueOrderNumber = options?.issueForce === true || USE_LEGACY_ISSUE_ORDER_NUMBER;
|
|
13
|
-
// if (!issueOrderNumber) {
|
|
14
|
-
// // 注文ドキュメントを参照(2026-06-24~)
|
|
15
|
-
// return repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
16
|
-
// identifier: params.id,
|
|
17
|
-
// project: { id: params.project.id }
|
|
18
|
-
// })
|
|
19
|
-
// }
|
|
20
11
|
// 1. 最初のチェック
|
|
21
12
|
let orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
|
|
22
13
|
// すでに発行済であれば何もしない
|
|
@@ -28,9 +28,9 @@ function fixCustomer(params) {
|
|
|
28
28
|
let customer;
|
|
29
29
|
if (transaction.typeOf === factory_1.factory.transactionType.PlaceOrder) {
|
|
30
30
|
// orderInTransaction.customer?.typeOfは取引開始時にセットされている前提で再実装(2026-06-24~)
|
|
31
|
-
const
|
|
31
|
+
const customerByTransaction = await repos.orderInTransaction.findCustomerByOrderIdentifier({
|
|
32
32
|
identifier: params.id,
|
|
33
|
-
project: { id: transaction.project.id }
|
|
33
|
+
// project: { id: transaction.project.id }
|
|
34
34
|
});
|
|
35
35
|
// // いったんtransaction.object.customer?.typeOfは取引開始時にセットされている前提
|
|
36
36
|
// const customerByTransaction = transaction.object.customer;
|
|
@@ -73,11 +73,11 @@ function updateAgent(params) {
|
|
|
73
73
|
const { customer, transaction } = await fixCustomer(params)(repos);
|
|
74
74
|
// also save in orderInTransaction(2024-06-20~)
|
|
75
75
|
if (customer !== undefined) {
|
|
76
|
-
// 注文ドキュメントを参照(2026-06-24~)
|
|
77
|
-
const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}, { onlyPlaceOrder: true });
|
|
76
|
+
// // 注文ドキュメントを参照(2026-06-24~)
|
|
77
|
+
// const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
78
|
+
// identifier: params.id,
|
|
79
|
+
// project: { id: transaction.project.id },
|
|
80
|
+
// }, { onlyPlaceOrder: true });
|
|
81
81
|
const customerName = (typeof customer.name === 'string' && customer.name !== '')
|
|
82
82
|
? customer.name
|
|
83
83
|
: (typeof customer.givenName === 'string' && typeof customer.familyName === 'string'
|
|
@@ -89,8 +89,7 @@ function updateAgent(params) {
|
|
|
89
89
|
identifier: (Array.isArray(customer.identifier)) ? customer.identifier : [],
|
|
90
90
|
...(typeof customerName === 'string') ? { name: customerName } : undefined
|
|
91
91
|
};
|
|
92
|
-
await repos.orderInTransaction.
|
|
93
|
-
orderNumber,
|
|
92
|
+
await repos.orderInTransaction.setCustomerByIdentifier({
|
|
94
93
|
project: transaction.project,
|
|
95
94
|
identifier: params.id,
|
|
96
95
|
customer: customerInOrder
|
package/package.json
CHANGED