@chevre/domain 25.0.0-alpha.9 → 25.1.0-alpha.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/lib/chevre/repo/message.d.ts +7 -15
- package/lib/chevre/repo/message.js +37 -74
- package/lib/chevre/repo/mongoose/schemas/message.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/order.js +2 -110
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +35 -9
- package/lib/chevre/repo/mongoose/schemas/setting.js +3 -2
- package/lib/chevre/repo/mongoose/schemas/transaction.js +51 -50
- package/lib/chevre/repo/order.d.ts +1 -7
- package/lib/chevre/repo/order.js +56 -26
- package/lib/chevre/repo/orderInTransaction.d.ts +41 -22
- package/lib/chevre/repo/orderInTransaction.js +108 -79
- package/lib/chevre/repo/passport.d.ts +5 -2
- package/lib/chevre/repo/setting/rateLimit.d.ts +18 -0
- package/lib/chevre/repo/setting/rateLimit.js +48 -0
- package/lib/chevre/repo/setting/waiter.d.ts +17 -0
- package/lib/chevre/repo/setting/waiter.js +39 -0
- package/lib/chevre/repo/setting.d.ts +12 -11
- package/lib/chevre/repo/setting.js +6 -18
- package/lib/chevre/repo/task.d.ts +1 -1
- package/lib/chevre/repo/transaction/placeOrder.d.ts +1 -6
- package/lib/chevre/repo/transaction/placeOrder.js +37 -26
- package/lib/chevre/repo/transaction.d.ts +1 -1
- package/lib/chevre/repo/transaction.js +2 -2
- package/lib/chevre/repository.d.ts +10 -0
- package/lib/chevre/repository.js +22 -0
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +0 -2
- package/lib/chevre/service/offer/any.d.ts +1 -3
- package/lib/chevre/service/offer/any.js +7 -8
- 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 -8
- 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 +6 -7
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +20 -17
- package/lib/chevre/service/order/deleteOrder.d.ts +6 -10
- package/lib/chevre/service/order/deleteOrder.js +7 -48
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +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/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
- 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 +6 -6
- 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/task/acceptCOAOffer.js +8 -10
- package/lib/chevre/service/task/authorizePayment.js +2 -6
- package/lib/chevre/service/task/deleteTransaction.js +2 -10
- package/lib/chevre/service/task/publishPaymentUrl.js +6 -9
- package/lib/chevre/service/taskHandler.js +0 -1
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +8 -16
- package/lib/chevre/service/transaction/deleteTransaction.js +46 -145
- 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 -2
- package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.d.ts +3 -2
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -5
- package/lib/chevre/service/transaction/placeOrder/confirm.js +29 -24
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +2 -3
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +45 -54
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +0 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +2 -3
- package/lib/chevre/service/transaction/placeOrder/issueOrderNumberIfNotExist.d.ts +5 -0
- package/lib/chevre/service/transaction/placeOrder/issueOrderNumberIfNotExist.js +37 -23
- package/lib/chevre/service/transaction/placeOrder/start/factory.d.ts +20 -4
- package/lib/chevre/service/transaction/placeOrder/start/factory.js +20 -7
- package/lib/chevre/service/transaction/placeOrder/start.d.ts +9 -4
- package/lib/chevre/service/transaction/placeOrder/start.js +18 -1
- package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +0 -4
- package/lib/chevre/service/transaction/placeOrder/updateAgent.js +19 -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.d.ts +0 -4
- package/lib/chevre/service/transaction.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
- package/lib/chevre/service/task/deletePerson.d.ts +0 -6
- package/lib/chevre/service/task/deletePerson.js +0 -465
|
@@ -19,16 +19,17 @@ const debug = (0, debug_1.default)('chevre-domain:service:transaction');
|
|
|
19
19
|
/**
|
|
20
20
|
* 進行中でない取引を処理する
|
|
21
21
|
*/
|
|
22
|
-
function processTransactionNotInProgress(
|
|
22
|
+
function processTransactionNotInProgress(params) {
|
|
23
23
|
return async (repos) => {
|
|
24
|
+
const { transaction, orderNumber } = params;
|
|
24
25
|
if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
25
|
-
const resultCustomer = await repos.orderInTransaction.
|
|
26
|
-
|
|
26
|
+
const resultCustomer = await repos.orderInTransaction.findCustomerByOrderIdentifier({
|
|
27
|
+
identifier: transaction.id
|
|
27
28
|
});
|
|
28
29
|
// if (resultCustomer === undefined) {
|
|
29
30
|
// throw new factory.errors.Internal('resultCustomer undefined'); // impossible process
|
|
30
31
|
// }
|
|
31
|
-
const { confirmationNumber
|
|
32
|
+
const { confirmationNumber } = transaction.object;
|
|
32
33
|
// Confirmedの取引であればobjectには必ず存在するはず
|
|
33
34
|
if (typeof confirmationNumber !== 'string' || typeof orderNumber !== 'string'
|
|
34
35
|
|| confirmationNumber === '' || orderNumber === '') {
|
|
@@ -62,30 +63,30 @@ function confirm(params, options) {
|
|
|
62
63
|
object: { orderDate: params.result.order.orderDate }
|
|
63
64
|
})(repos);
|
|
64
65
|
const transaction = await repos.placeOrder.findPlaceOrderById({ typeOf: factory_1.factory.transactionType.PlaceOrder, id: params.id }, ['typeOf', 'project', 'status', 'agent', 'seller', 'object', 'result']);
|
|
65
|
-
|
|
66
|
+
// 注文ドキュメントから注文番号を参照(取引開始時に発行済の前提)(2026-06-26~)
|
|
67
|
+
const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
68
|
+
identifier: params.id,
|
|
69
|
+
project: { id: transaction.project.id }
|
|
70
|
+
}, { onlyPlaceOrder: false } // すでに取引確定済かもしれないのでfalse
|
|
71
|
+
);
|
|
72
|
+
const confirmResult = await processTransactionNotInProgress({ transaction, orderNumber })(repos);
|
|
66
73
|
if (confirmResult !== undefined) {
|
|
67
74
|
return confirmResult;
|
|
68
75
|
}
|
|
69
76
|
if (typeof params.agent?.id === 'string' && transaction.agent.id !== params.agent.id) {
|
|
70
77
|
throw new factory_1.factory.errors.Forbidden('Transaction not yours');
|
|
71
78
|
}
|
|
72
|
-
// 注文番号は興行オファー承認時に発行済のはず(2026-06-16~)
|
|
73
|
-
const orderNumber = transaction.object.orderNumber;
|
|
74
|
-
if (typeof orderNumber !== 'string' || orderNumber === '') {
|
|
75
|
-
|
|
76
|
-
}
|
|
79
|
+
// // 注文番号は興行オファー承認時に発行済のはず(2026-06-16~)
|
|
80
|
+
// const orderNumber = transaction.object.orderNumber;
|
|
81
|
+
// if (typeof orderNumber !== 'string' || orderNumber === '') {
|
|
82
|
+
// throw new factory.errors.Argument('transactionId', 'orderNumber not issued');
|
|
83
|
+
// }
|
|
77
84
|
// 取引に対する全ての承認アクションをマージ
|
|
78
85
|
const completedAuthorizeActions = await searchAuthorizeActions(params)(repos);
|
|
79
86
|
let acceptPayActions = [];
|
|
80
87
|
if (typeof transaction.object.paymentMethods?.paymentMethodId === 'string') {
|
|
81
88
|
acceptPayActions = await searchAcceptPayActions(params)(repos);
|
|
82
89
|
}
|
|
83
|
-
// 注文番号は興行オファー承認時に発行済のはずなので、ここは不要(承認オファーなしの注文は存在しえない)(2026-06-16~)
|
|
84
|
-
// const orderNumber = await issueOrderNumberIfNotExist({
|
|
85
|
-
// project: { id: transaction.project.id },
|
|
86
|
-
// id: transaction.id,
|
|
87
|
-
// object: { orderDate: params.result.order.orderDate }
|
|
88
|
-
// })(repos);
|
|
89
90
|
// 必要あらば注文コード発行(2024-02-05~)
|
|
90
91
|
let code;
|
|
91
92
|
const publishCodeExpiresInSeconds = options.publishCodeExpiresInSeconds;
|
|
@@ -107,8 +108,9 @@ function confirm(params, options) {
|
|
|
107
108
|
// authorizeProductOfferActions,
|
|
108
109
|
serialNumbers } = dissolveAuthorizeActions(completedAuthorizeActions);
|
|
109
110
|
// orderInTransactionから検索する(2024-03-04~)
|
|
110
|
-
const acceptedOffers = (await repos.orderInTransaction.
|
|
111
|
-
orderNumber,
|
|
111
|
+
const acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
|
|
112
|
+
// orderNumber,
|
|
113
|
+
identifier: transaction.id,
|
|
112
114
|
project: { id: transaction.project.id }
|
|
113
115
|
}))
|
|
114
116
|
.filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
|
|
@@ -125,7 +127,7 @@ function confirm(params, options) {
|
|
|
125
127
|
}
|
|
126
128
|
// retrieve customer from orderInTransaction(2024-06-24~)
|
|
127
129
|
// let customer: factory.order.ICustomer = createCustomer({ transaction });
|
|
128
|
-
const customer = await repos.orderInTransaction.
|
|
130
|
+
const customer = await repos.orderInTransaction.findCustomerByOrderIdentifier({ identifier: transaction.id });
|
|
129
131
|
const seller = (0, factory_2.createSeller)({ transaction });
|
|
130
132
|
const { paymentMethods, placingOrder, result, eventId, reservationIds } = createResult({
|
|
131
133
|
...params,
|
|
@@ -175,7 +177,10 @@ function confirm(params, options) {
|
|
|
175
177
|
await repos.placeOrder.confirmPlaceOrder({
|
|
176
178
|
typeOf: transaction.typeOf,
|
|
177
179
|
id: transaction.id,
|
|
178
|
-
object: {
|
|
180
|
+
object: {
|
|
181
|
+
orderDate: params.result.order.orderDate,
|
|
182
|
+
orderNumber
|
|
183
|
+
},
|
|
179
184
|
result: result,
|
|
180
185
|
potentialActions: potentialActions
|
|
181
186
|
});
|
|
@@ -374,10 +379,10 @@ function createResult(params, options) {
|
|
|
374
379
|
result: {
|
|
375
380
|
authorizeActions, // 追加(2024-01-17~)
|
|
376
381
|
...(typeof params.code === 'string') ? { code: params.code } : undefined,
|
|
377
|
-
...((!options.disableResultOrder) && { order: orderAsResult }), //
|
|
378
|
-
...((!options.disableResultOrder) && {
|
|
379
|
-
|
|
380
|
-
}) //
|
|
382
|
+
// ...((!options.disableResultOrder) && { order: orderAsResult }), // 完全廃止(2026-06-26~)
|
|
383
|
+
// ...((!options.disableResultOrder) && {
|
|
384
|
+
// numAcceptedOffers: params.acceptedOffers.length,
|
|
385
|
+
// }) // 完全廃止(2026-06-26~)
|
|
381
386
|
},
|
|
382
387
|
...(typeof eventId === 'string') ? { eventId } : undefined,
|
|
383
388
|
...(Array.isArray(reservationIds)) ? { reservationIds } : undefined
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { factory } from '../../../../factory';
|
|
2
2
|
import type { ISetting } from '../../../../repo/setting';
|
|
3
|
-
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.
|
|
3
|
+
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.DeleteTransaction> | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | factory.task.IAttributes<factory.taskName.VoidReserveTransaction>;
|
|
4
4
|
/**
|
|
5
5
|
* 取引のタスクを作成する
|
|
6
6
|
*/
|
|
7
7
|
export declare function createTasks(params: {
|
|
8
8
|
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
|
|
9
9
|
runsAt: Date;
|
|
10
|
-
|
|
11
|
-
}, setting: Pick<ISetting, 'onTransactionStatusChanged' | 'storage'> | null): IPlaceOrderPotentialTask[];
|
|
10
|
+
}, setting: Pick<ISetting, 'storage'> | null): IPlaceOrderPotentialTask[];
|
|
12
11
|
export {};
|
|
@@ -9,53 +9,52 @@ const factory_1 = require("../../../../factory");
|
|
|
9
9
|
/**
|
|
10
10
|
* 取引のタスクを作成する
|
|
11
11
|
*/
|
|
12
|
-
function createTasks(params, setting
|
|
13
|
-
// settings: Settings
|
|
14
|
-
) {
|
|
12
|
+
function createTasks(params, setting) {
|
|
15
13
|
const taskAttributes = [];
|
|
16
14
|
const transaction = params.transaction;
|
|
17
15
|
const taskRunsAt = params.runsAt;
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
16
|
+
// 取引通知は廃止(2026-06-29~)
|
|
17
|
+
// const informTransaction = setting?.onTransactionStatusChanged?.informTransaction;
|
|
18
|
+
// const transactionWebhookUrls = (Array.isArray(informTransaction)) ? informTransaction : [];
|
|
19
|
+
// const triggerWebhookTaskAttributes: factory.task.IAttributes<factory.taskName.TriggerWebhook>[] = [];
|
|
20
|
+
// transactionWebhookUrls.forEach(({ recipient }) => {
|
|
21
|
+
// if (typeof recipient?.url === 'string') {
|
|
22
|
+
// const informObject: factory.notification.transaction.IPlaceOrderAsNotification = {
|
|
23
|
+
// id: transaction.id,
|
|
24
|
+
// typeOf: transaction.typeOf,
|
|
25
|
+
// project: transaction.project,
|
|
26
|
+
// seller: transaction.seller,
|
|
27
|
+
// startDate: transaction.startDate,
|
|
28
|
+
// status: transaction.status,
|
|
29
|
+
// ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
|
|
30
|
+
// };
|
|
31
|
+
// const data: factory.task.triggerWebhook.IInformAnyResourceAction = {
|
|
32
|
+
// object: informObject,
|
|
33
|
+
// recipient: {
|
|
34
|
+
// id: (typeof recipient?.id === 'string') ? recipient.id : '',
|
|
35
|
+
// name: recipient?.name,
|
|
36
|
+
// typeOf: factory.creativeWorkType.WebApplication
|
|
37
|
+
// // url: recipient.url // discontinue(2025-02-13~)
|
|
38
|
+
// },
|
|
39
|
+
// target: {
|
|
40
|
+
// httpMethod: 'POST',
|
|
41
|
+
// encodingType: factory.encodingFormat.Application.json,
|
|
42
|
+
// typeOf: 'EntryPoint',
|
|
43
|
+
// urlTemplate: recipient.url
|
|
44
|
+
// }
|
|
45
|
+
// };
|
|
46
|
+
// triggerWebhookTaskAttributes.push({
|
|
47
|
+
// project: transaction.project,
|
|
48
|
+
// name: factory.taskName.TriggerWebhook,
|
|
49
|
+
// status: factory.taskStatus.Ready,
|
|
50
|
+
// runsAt: taskRunsAt,
|
|
51
|
+
// remainingNumberOfTries: 3,
|
|
52
|
+
// numberOfTried: 0,
|
|
53
|
+
// executionResults: [],
|
|
54
|
+
// data
|
|
55
|
+
// });
|
|
56
|
+
// }
|
|
57
|
+
// });
|
|
59
58
|
const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
|
|
60
59
|
const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
|
|
61
60
|
if (typeof confirmedStoragePeriodInDays !== 'number') {
|
|
@@ -140,7 +139,7 @@ function createTasks(params, setting
|
|
|
140
139
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
141
140
|
}
|
|
142
141
|
};
|
|
143
|
-
taskAttributes.push(
|
|
142
|
+
taskAttributes.push(deleteTransactionTask);
|
|
144
143
|
switch (transaction.status) {
|
|
145
144
|
case factory_1.factory.transactionStatusType.Confirmed: {
|
|
146
145
|
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
@@ -182,15 +181,7 @@ function createTasks(params, setting
|
|
|
182
181
|
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
183
182
|
break;
|
|
184
183
|
case factory_1.factory.transactionStatusType.Expired:
|
|
185
|
-
|
|
186
|
-
if (params.optimizeRedundantTasks === true) {
|
|
187
|
-
if (typeof params.transaction.object.orderNumber === 'string') {
|
|
188
|
-
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
193
|
-
}
|
|
184
|
+
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
194
185
|
break;
|
|
195
186
|
default:
|
|
196
187
|
throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
@@ -16,9 +16,5 @@ declare function exportTasksById(params: {
|
|
|
16
16
|
* タスク実行日時バッファ
|
|
17
17
|
*/
|
|
18
18
|
runsTasksAfterInSeconds?: number;
|
|
19
|
-
/**
|
|
20
|
-
* support optimizeRedundantTasks(2025-03-11~)
|
|
21
|
-
*/
|
|
22
|
-
optimizeRedundantTasks: boolean;
|
|
23
19
|
}): ITaskAndTransactionOperation<void>;
|
|
24
20
|
export { IExportTasksByIdRepos, exportTasksById };
|
|
@@ -26,11 +26,10 @@ function exportTasksById(params) {
|
|
|
26
26
|
.toDate();
|
|
27
27
|
}
|
|
28
28
|
// search settings
|
|
29
|
-
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['
|
|
29
|
+
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
30
30
|
const taskAttributes = (0, factory_2.createTasks)({
|
|
31
31
|
transaction,
|
|
32
|
-
runsAt: taskRunsAt
|
|
33
|
-
optimizeRedundantTasks: params.optimizeRedundantTasks === true
|
|
32
|
+
runsAt: taskRunsAt
|
|
34
33
|
}, setting
|
|
35
34
|
// settings
|
|
36
35
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OrderInTransactionRepo, IOrderInTransaction } from '../../../repo/orderInTransaction';
|
|
1
2
|
import type { OrderNumberRepo } from '../../../repo/orderNumber';
|
|
2
3
|
import type { ProjectRepo } from '../../../repo/project';
|
|
3
4
|
import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
@@ -15,9 +16,13 @@ declare function issueOrderNumberIfNotExist(params: {
|
|
|
15
16
|
object: {
|
|
16
17
|
orderDate: Date;
|
|
17
18
|
};
|
|
19
|
+
creatingOrderInTransaction: Pick<IOrderInTransaction, 'broker' | 'seller' | 'customer'>;
|
|
20
|
+
}, options: {
|
|
21
|
+
saveOrderNumberInPlaceOrderInProgress: boolean;
|
|
18
22
|
}): (repos: {
|
|
19
23
|
project: ProjectRepo;
|
|
20
24
|
placeOrder: PlaceOrderRepo;
|
|
25
|
+
orderInTransaction: OrderInTransactionRepo;
|
|
21
26
|
orderNumber: OrderNumberRepo;
|
|
22
27
|
}) => Promise<string>;
|
|
23
28
|
export { issueOrderNumberIfNotExist };
|
|
@@ -5,40 +5,54 @@ const factory_1 = require("../../../factory");
|
|
|
5
5
|
/**
|
|
6
6
|
* 未発行であれば、注文番号を発行して取引に保管する
|
|
7
7
|
*/
|
|
8
|
-
function issueOrderNumberIfNotExist(params) {
|
|
8
|
+
function issueOrderNumberIfNotExist(params, options) {
|
|
9
9
|
return async (repos) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
10
|
+
const { saveOrderNumberInPlaceOrderInProgress } = options;
|
|
11
|
+
// // 1. 最初のチェック
|
|
12
|
+
// let orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
|
|
13
|
+
// // すでに発行済であれば何もしない
|
|
14
|
+
// if (typeof orderNumber === 'string') {
|
|
15
|
+
// return orderNumber;
|
|
16
|
+
// }
|
|
17
|
+
// 新注文番号発行
|
|
17
18
|
const { alternateName } = await repos.project.findAlternateNameById({ id: params.project.id });
|
|
18
19
|
if (typeof alternateName !== 'string') {
|
|
19
20
|
throw new factory_1.factory.errors.NotFound('project.alternateName');
|
|
20
21
|
}
|
|
21
|
-
// 3. 番号発行
|
|
22
22
|
const issuedOrderNumber = await repos.orderNumber.issueOrderNumber({
|
|
23
23
|
project: { alternateName },
|
|
24
24
|
orderDate: params.object.orderDate
|
|
25
25
|
});
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
orderNumber: issuedOrderNumber
|
|
26
|
+
// 注文ドキュメント作成
|
|
27
|
+
await repos.orderInTransaction.createPlaceOrderIfNotExists({
|
|
28
|
+
...params.creatingOrderInTransaction,
|
|
29
|
+
orderNumber: issuedOrderNumber,
|
|
30
|
+
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
31
|
+
identifier: params.id,
|
|
30
32
|
});
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
// 注文ドキュメント(存在するはず)から注文番号を参照
|
|
34
|
+
const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
35
|
+
identifier: params.id,
|
|
36
|
+
project: { id: params.project.id }
|
|
37
|
+
}, { onlyPlaceOrder: true });
|
|
38
|
+
if (saveOrderNumberInPlaceOrderInProgress) {
|
|
39
|
+
// 取引に保管を試みる
|
|
40
|
+
await repos.placeOrder.saveOrderNumberIfNotExist({
|
|
41
|
+
id: params.id,
|
|
42
|
+
orderNumber
|
|
43
|
+
});
|
|
41
44
|
}
|
|
45
|
+
// // 5. 書き込めたなら、自分が発行した番号が「真実」
|
|
46
|
+
// if (modifiedCount === 1) {
|
|
47
|
+
// return issuedOrderNumber;
|
|
48
|
+
// }
|
|
49
|
+
// // 6. 競合が発生した場合(他者が先に書き込んだ場合)
|
|
50
|
+
// // DBにある「正解」を再取得して返す
|
|
51
|
+
// const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
|
|
52
|
+
// if (typeof orderNumber !== 'string') {
|
|
53
|
+
// // ここを通るのは、他者が保存した直後に取引がキャンセル/削除された等の極めて稀なケース
|
|
54
|
+
// throw new factory.errors.Internal('OrderNumber conflict: failed to retrieve existing number');
|
|
55
|
+
// }
|
|
42
56
|
return orderNumber;
|
|
43
57
|
};
|
|
44
58
|
}
|
|
@@ -6,13 +6,29 @@ type IVerifiedPassport = factory.waiter.passport.IPassport & {
|
|
|
6
6
|
*/
|
|
7
7
|
identifier: string;
|
|
8
8
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type ICustomerInObject = Pick<factory.order.ICustomer, 'id' | 'identifier' | 'typeOf'>;
|
|
10
|
+
interface IStartPlaceOrderParams {
|
|
11
|
+
project: Pick<factory.project.IProject, 'id' | 'typeOf'>;
|
|
12
|
+
agent: factory.transaction.placeOrder.IAgent;
|
|
13
|
+
seller: {
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
object: {
|
|
11
17
|
/**
|
|
12
18
|
* api経由で取引が開始されれば必ず存在するはず
|
|
13
19
|
*/
|
|
14
20
|
clientUser: factory.transaction.placeOrder.IClientUserBeforeStart;
|
|
21
|
+
/**
|
|
22
|
+
* 注文ドキュメントに保管するcustomer
|
|
23
|
+
*/
|
|
24
|
+
customer?: ICustomerInObject;
|
|
25
|
+
passport?: factory.transaction.IPassportBeforeStart;
|
|
26
|
+
name?: never;
|
|
15
27
|
};
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
/**
|
|
29
|
+
* 注文ドキュメントに保管する代理人
|
|
30
|
+
*/
|
|
31
|
+
broker?: factory.order.IBroker;
|
|
32
|
+
}
|
|
33
|
+
declare function createStartParams(params: IStartPlaceOrderParams, expiresInSeconds: number, passport: IVerifiedPassport | undefined, seller: Pick<factory.seller.ISeller, 'id' | 'name' | 'typeOf' | 'project'>, customerType?: string): factory.transaction.placeOrder.IStartParams;
|
|
18
34
|
export { AGENT_IDENTIFIER_NAME_PASSPORT, createStartParams, IStartPlaceOrderParams };
|
|
@@ -5,6 +5,7 @@ exports.createStartParams = createStartParams;
|
|
|
5
5
|
const factory_1 = require("../../../../factory");
|
|
6
6
|
const AGENT_IDENTIFIER_NAME_PASSPORT = 'passport';
|
|
7
7
|
exports.AGENT_IDENTIFIER_NAME_PASSPORT = AGENT_IDENTIFIER_NAME_PASSPORT;
|
|
8
|
+
;
|
|
8
9
|
function createStartParams(params, expiresInSeconds, passport, seller, customerType) {
|
|
9
10
|
// const { broker } = params;
|
|
10
11
|
// let clientUser: Omit<factory.clientUser.IClientUser, 'scope' | 'scopes'> | undefined;
|
|
@@ -20,7 +21,7 @@ function createStartParams(params, expiresInSeconds, passport, seller, customerT
|
|
|
20
21
|
// ...(typeof clientUser?.client_id === 'string') ? { clientUser } : undefined, // discontinue(2026-06-10~)
|
|
21
22
|
// ...(typeof params.object?.name === 'string') ? { name: params.object?.name } : undefined, // discontinue(2026-06-11~)
|
|
22
23
|
// ...(typeof broker?.typeOf === 'string') ? { broker: broker } : undefined, // discontinue(2026-06-22~)
|
|
23
|
-
...(typeof params.object.customer?.typeOf === 'string') ? { customer: params.object.customer } : undefined,
|
|
24
|
+
// ...(!minimizeStartPlaceOrderParams && typeof params.object.customer?.typeOf === 'string') ? { customer: params.object.customer } : undefined, // discontinue(2026-06-26~)
|
|
24
25
|
...(typeof customerType === 'string') ? { customerType } : undefined
|
|
25
26
|
};
|
|
26
27
|
if (typeof seller.id !== 'string') {
|
|
@@ -39,16 +40,28 @@ function createStartParams(params, expiresInSeconds, passport, seller, customerT
|
|
|
39
40
|
// ...(memeberOfPayload !== undefined) ? { memeberOfPayload } : undefined, // discontinue(2026-06-10~)
|
|
40
41
|
identifier: agentIdentifier
|
|
41
42
|
};
|
|
43
|
+
const sellerOfPlaceOrder = {
|
|
44
|
+
id: seller.id,
|
|
45
|
+
name: { ja: String(seller.name.ja) },
|
|
46
|
+
typeOf: seller.typeOf
|
|
47
|
+
};
|
|
42
48
|
return {
|
|
43
49
|
project: { typeOf: seller.project.typeOf, id: seller.project.id },
|
|
44
50
|
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
45
51
|
agent,
|
|
46
|
-
seller:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
seller: sellerOfPlaceOrder, // sellerを最小化(2026-06-26~)
|
|
53
|
+
// seller: (minimizeStartPlaceOrderParams)
|
|
54
|
+
// ? {
|
|
55
|
+
// id: seller.id,
|
|
56
|
+
// name: { ja: String(seller.name.ja) },
|
|
57
|
+
// typeOf: seller.typeOf
|
|
58
|
+
// }
|
|
59
|
+
// : {
|
|
60
|
+
// id: seller.id,
|
|
61
|
+
// name: seller.name,
|
|
62
|
+
// typeOf: seller.typeOf,
|
|
63
|
+
// additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
|
|
64
|
+
// },
|
|
52
65
|
object: transactionObject,
|
|
53
66
|
expiresInSeconds,
|
|
54
67
|
...(typeof instrument?.id === 'string') ? { instrument } : undefined
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { IssuerRepo } from '../../../repo/issuer';
|
|
2
2
|
import type { MemberRepo } from '../../../repo/member';
|
|
3
3
|
import type { MemberProgramRepo } from '../../../repo/memberProgram';
|
|
4
|
+
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
5
|
+
import type { OrderNumberRepo } from '../../../repo/orderNumber';
|
|
4
6
|
import type { PassportRepo } from '../../../repo/passport';
|
|
7
|
+
import type { ProjectRepo } from '../../../repo/project';
|
|
5
8
|
import type { ProjectMakesOfferRepo } from '../../../repo/projectMakesOffer';
|
|
6
9
|
import type { SellerRepo } from '../../../repo/seller';
|
|
7
10
|
import type { IStartedPlaceOrder, PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
@@ -14,13 +17,15 @@ interface IStartOperationRepos {
|
|
|
14
17
|
projectMakesOffer: ProjectMakesOfferRepo;
|
|
15
18
|
seller: SellerRepo;
|
|
16
19
|
placeOrder: PlaceOrderRepo;
|
|
20
|
+
orderInTransaction: OrderInTransactionRepo;
|
|
21
|
+
project: ProjectRepo;
|
|
22
|
+
orderNumber: OrderNumberRepo;
|
|
17
23
|
}
|
|
18
24
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
19
|
-
interface IStartOptions {
|
|
20
|
-
lockPassport: boolean;
|
|
21
|
-
}
|
|
22
25
|
/**
|
|
23
26
|
* 取引開始
|
|
24
27
|
*/
|
|
25
|
-
declare function start(params: IStartPlaceOrderParams, options:
|
|
28
|
+
declare function start(params: IStartPlaceOrderParams, options: {
|
|
29
|
+
saveOrderNumberInPlaceOrderInProgress: boolean;
|
|
30
|
+
}): IStartOperation<IStartedPlaceOrder>;
|
|
26
31
|
export { start, IStartPlaceOrderParams };
|
|
@@ -4,6 +4,7 @@ exports.start = start;
|
|
|
4
4
|
const factory_1 = require("../../../factory");
|
|
5
5
|
const factory_2 = require("./start/factory");
|
|
6
6
|
const validateStartRequest_1 = require("./start/validateStartRequest");
|
|
7
|
+
const issueOrderNumberIfNotExist_1 = require("./issueOrderNumberIfNotExist");
|
|
7
8
|
/**
|
|
8
9
|
* 取引開始
|
|
9
10
|
*/
|
|
@@ -25,7 +26,7 @@ function start(params, options) {
|
|
|
25
26
|
const startParams = (0, factory_2.createStartParams)(params, expiresInSeconds, passport, seller, customerType);
|
|
26
27
|
let transaction;
|
|
27
28
|
// lock passport(2024-07-05~)
|
|
28
|
-
if (
|
|
29
|
+
if (passport !== undefined) {
|
|
29
30
|
try {
|
|
30
31
|
await repos.passport.lock(passport);
|
|
31
32
|
}
|
|
@@ -51,6 +52,22 @@ function start(params, options) {
|
|
|
51
52
|
if (transaction === undefined) {
|
|
52
53
|
transaction = await repos.placeOrder.startPlaceOrder(startParams);
|
|
53
54
|
}
|
|
55
|
+
await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
|
|
56
|
+
project: { id: params.project.id },
|
|
57
|
+
id: transaction.id,
|
|
58
|
+
object: { orderDate: new Date() },
|
|
59
|
+
// support createOrderDocument(2026-06-23~)
|
|
60
|
+
creatingOrderInTransaction: {
|
|
61
|
+
seller: {
|
|
62
|
+
id: seller.id,
|
|
63
|
+
name: (typeof seller.name === 'string') ? seller.name : String(seller.name?.ja),
|
|
64
|
+
typeOf: seller.typeOf,
|
|
65
|
+
additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
|
|
66
|
+
},
|
|
67
|
+
...((typeof params.object.customer?.typeOf === 'string') && { customer: params.object.customer }),
|
|
68
|
+
...((typeof params.broker?.typeOf === 'string') && { broker: params.broker })
|
|
69
|
+
}
|
|
70
|
+
}, options)(repos);
|
|
54
71
|
return transaction;
|
|
55
72
|
};
|
|
56
73
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { factory } from '../../../factory';
|
|
2
2
|
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
3
|
-
import type { OrderNumberRepo } from '../../../repo/orderNumber';
|
|
4
|
-
import type { ProjectRepo } from '../../../repo/project';
|
|
5
3
|
import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
6
4
|
/**
|
|
7
5
|
* 取引人プロフィール更新
|
|
@@ -17,7 +15,5 @@ export declare function updateAgent(params: {
|
|
|
17
15
|
};
|
|
18
16
|
}): (repos: {
|
|
19
17
|
orderInTransaction: OrderInTransactionRepo;
|
|
20
|
-
orderNumber: OrderNumberRepo;
|
|
21
|
-
project: ProjectRepo;
|
|
22
18
|
placeOrder: PlaceOrderRepo;
|
|
23
19
|
}) => Promise<void>;
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateAgent = updateAgent;
|
|
4
4
|
const google_libphonenumber_1 = require("google-libphonenumber");
|
|
5
5
|
const factory_1 = require("../../../factory");
|
|
6
|
-
const issueOrderNumberIfNotExist_1 = require("./issueOrderNumberIfNotExist");
|
|
7
|
-
// export type ITransactionOperation<T> = (repos: { transaction: TransactionRepo }) => Promise<T>;
|
|
8
6
|
function fixCustomer(params) {
|
|
9
7
|
return async (repos) => {
|
|
10
8
|
let formattedTelephone;
|
|
@@ -20,7 +18,7 @@ function fixCustomer(params) {
|
|
|
20
18
|
throw new factory_1.factory.errors.Argument('telephone', (error instanceof Error) ? error.message : String(error));
|
|
21
19
|
}
|
|
22
20
|
const transaction = await repos.placeOrder.findPlaceOrderInProgressById({
|
|
23
|
-
typeOf:
|
|
21
|
+
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
24
22
|
id: params.id
|
|
25
23
|
}, ['agent', 'object', 'typeOf', 'project']);
|
|
26
24
|
if (transaction.agent.id !== params.agent.id) {
|
|
@@ -29,20 +27,20 @@ function fixCustomer(params) {
|
|
|
29
27
|
// 注文取引の場合、object.customerにも適用
|
|
30
28
|
let customer;
|
|
31
29
|
if (transaction.typeOf === factory_1.factory.transactionType.PlaceOrder) {
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
|
|
30
|
+
// orderInTransaction.customer?.typeOfは取引開始時にセットされている前提で再実装(2026-06-24~)
|
|
31
|
+
const customerByTransaction = await repos.orderInTransaction.findCustomerByOrderIdentifier({
|
|
32
|
+
identifier: params.id,
|
|
33
|
+
// project: { id: transaction.project.id }
|
|
34
|
+
});
|
|
35
|
+
// // いったんtransaction.object.customer?.typeOfは取引開始時にセットされている前提
|
|
36
|
+
// const customerByTransaction = transaction.object.customer;
|
|
37
|
+
if (typeof customerByTransaction?.typeOf === 'string') {
|
|
35
38
|
customer = {
|
|
36
|
-
typeOf:
|
|
37
|
-
id:
|
|
38
|
-
...(Array.isArray(
|
|
39
|
-
? { identifier:
|
|
39
|
+
typeOf: customerByTransaction.typeOf,
|
|
40
|
+
id: customerByTransaction.id,
|
|
41
|
+
...(Array.isArray(customerByTransaction.identifier))
|
|
42
|
+
? { identifier: customerByTransaction.identifier }
|
|
40
43
|
: /* istanbul ignore next */ undefined,
|
|
41
|
-
// discontinue(2024-05-16~)
|
|
42
|
-
// ...(transaction.object.customer.typeOf === factory.personType.Person
|
|
43
|
-
// && typeof transaction.object.customer.memberOf?.typeOf === 'string')
|
|
44
|
-
// ? { memberOf: transaction.object.customer.memberOf }
|
|
45
|
-
// : undefined,
|
|
46
44
|
...(Array.isArray(params.agent.additionalProperty))
|
|
47
45
|
? { additionalProperty: params.agent.additionalProperty }
|
|
48
46
|
: /* istanbul ignore next */ undefined,
|
|
@@ -75,11 +73,11 @@ function updateAgent(params) {
|
|
|
75
73
|
const { customer, transaction } = await fixCustomer(params)(repos);
|
|
76
74
|
// also save in orderInTransaction(2024-06-20~)
|
|
77
75
|
if (customer !== undefined) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
76
|
+
// // 注文ドキュメントを参照(2026-06-24~)
|
|
77
|
+
// const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
|
|
78
|
+
// identifier: params.id,
|
|
79
|
+
// project: { id: transaction.project.id },
|
|
80
|
+
// }, { onlyPlaceOrder: true });
|
|
83
81
|
const customerName = (typeof customer.name === 'string' && customer.name !== '')
|
|
84
82
|
? customer.name
|
|
85
83
|
: (typeof customer.givenName === 'string' && typeof customer.familyName === 'string'
|
|
@@ -91,8 +89,7 @@ function updateAgent(params) {
|
|
|
91
89
|
identifier: (Array.isArray(customer.identifier)) ? customer.identifier : [],
|
|
92
90
|
...(typeof customerName === 'string') ? { name: customerName } : undefined
|
|
93
91
|
};
|
|
94
|
-
await repos.orderInTransaction.
|
|
95
|
-
orderNumber,
|
|
92
|
+
await repos.orderInTransaction.setCustomerByIdentifier({
|
|
96
93
|
project: transaction.project,
|
|
97
94
|
identifier: params.id,
|
|
98
95
|
customer: customerInOrder
|