@chevre/domain 21.20.0-alpha.2 → 21.20.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/src/chevre/onAssetTransactionStatusChanged.ts +36 -0
- package/example/src/chevre/retryTasks.ts +39 -0
- package/example/src/chevre/searchOrders.ts +13 -15
- package/example/src/chevre/searchSlicedAcceptedOffersByOrderNumber.ts +28 -0
- package/example/src/chevre/sendOrder.ts +37 -0
- package/example/src/chevre/transaction/processAcceptOffer.ts +48 -0
- package/example/src/chevre/transaction/processPlaceOrder.ts +82 -53
- package/lib/chevre/repo/acceptedOffer.d.ts +21 -1
- package/lib/chevre/repo/acceptedOffer.js +32 -2
- package/lib/chevre/repo/action.d.ts +13 -7
- package/lib/chevre/repo/action.js +33 -11
- package/lib/chevre/repo/mongoose/schemas/order.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/order.js +20 -11
- package/lib/chevre/repo/order.js +28 -9
- package/lib/chevre/repo/orderInTransaction.d.ts +27 -0
- package/lib/chevre/repo/orderInTransaction.js +77 -0
- package/lib/chevre/repo/task.d.ts +0 -2
- package/lib/chevre/repo/task.js +56 -46
- package/lib/chevre/repo/transaction.d.ts +1 -1
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/lib/chevre/service/assetTransaction/pay.d.ts +0 -10
- package/lib/chevre/service/assetTransaction/pay.js +4 -4
- package/lib/chevre/service/code.js +1 -1
- package/lib/chevre/service/delivery.js +2 -2
- package/lib/chevre/service/event/createEvent.js +1 -1
- package/lib/chevre/service/event.js +2 -2
- package/lib/chevre/service/moneyTransfer.js +1 -1
- package/lib/chevre/service/notification.js +2 -5
- package/lib/chevre/service/offer/any.d.ts +29 -0
- package/lib/chevre/service/offer/any.js +55 -0
- package/lib/chevre/service/offer/event/authorize.d.ts +7 -0
- package/lib/chevre/service/offer/event/authorize.js +11 -0
- package/lib/chevre/service/offer/event/cancel.d.ts +2 -0
- package/lib/chevre/service/offer/event/cancel.js +12 -1
- package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
- package/lib/chevre/service/offer/event/voidTransaction.js +12 -5
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +48 -0
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +133 -0
- package/lib/chevre/service/offer/eventServiceByCOA/cancel.d.ts +39 -0
- package/lib/chevre/service/offer/eventServiceByCOA/cancel.js +58 -0
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.d.ts +25 -0
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +156 -0
- package/lib/chevre/service/offer/eventServiceByCOA.d.ts +4 -89
- package/lib/chevre/service/offer/eventServiceByCOA.js +7 -292
- package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +6 -1
- package/lib/chevre/service/offer/moneyTransfer/authorize.js +2 -1
- package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +1 -1
- package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +1 -1
- package/lib/chevre/service/offer/product.js +1 -1
- package/lib/chevre/service/order/confirmPayTransaction.js +3 -3
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +11 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +113 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +18 -19
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +38 -25
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +11 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +45 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +37 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +86 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +51 -36
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +3 -1
- package/lib/chevre/service/order/onOrderStatusChanged.js +5 -1
- package/lib/chevre/service/order/placeOrder.d.ts +2 -0
- package/lib/chevre/service/order/placeOrder.js +28 -29
- package/lib/chevre/service/order/returnOrder.js +25 -16
- package/lib/chevre/service/order/sendOrder.d.ts +5 -0
- package/lib/chevre/service/order/sendOrder.js +68 -30
- package/lib/chevre/service/payment/any.d.ts +6 -8
- package/lib/chevre/service/payment/any.js +46 -10
- package/lib/chevre/service/payment/creditCard.d.ts +9 -8
- package/lib/chevre/service/payment/creditCard.js +102 -133
- package/lib/chevre/service/payment/faceToFace.d.ts +0 -4
- package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +0 -2
- package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +1 -0
- package/lib/chevre/service/payment/movieTicket/validation.d.ts +0 -2
- package/lib/chevre/service/payment/movieTicket.d.ts +0 -6
- package/lib/chevre/service/payment/movieTicket.js +1 -1
- package/lib/chevre/service/payment/paymentCard.d.ts +0 -2
- package/lib/chevre/service/payment/paymentCard.js +6 -6
- package/lib/chevre/service/payment.js +1 -1
- package/lib/chevre/service/product.js +1 -1
- package/lib/chevre/service/reserve/cancelReservation.js +2 -2
- package/lib/chevre/service/reserve/confirmReservation.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +4 -4
- package/lib/chevre/service/reserve/useReservation.d.ts +1 -2
- package/lib/chevre/service/reserve/useReservation.js +4 -4
- package/lib/chevre/service/reserve/verifyToken4reservation.js +2 -0
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -1
- package/lib/chevre/service/task/confirmReserveTransaction.js +42 -3
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -7
- package/lib/chevre/service/task/placeOrder.js +9 -10
- package/lib/chevre/service/task/returnOrder.js +0 -3
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task/sendOrder.js +8 -4
- package/lib/chevre/service/task/voidPayTransaction.js +2 -2
- package/lib/chevre/service/task/voidReserveTransaction.js +8 -12
- package/lib/chevre/service/transaction/deleteTransaction.js +1 -1
- package/lib/chevre/service/transaction/moneyTransfer.js +1 -5
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +18 -13
- package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
- package/lib/chevre/service/transaction/returnOrder/preStart.d.ts +32 -0
- package/lib/chevre/service/transaction/returnOrder/preStart.js +632 -0
- package/lib/chevre/service/transaction/returnOrder.d.ts +8 -6
- package/lib/chevre/service/transaction/returnOrder.js +4 -616
- package/lib/chevre/settings.d.ts +3 -1
- package/lib/chevre/settings.js +7 -2
- package/package.json +3 -3
|
@@ -14,14 +14,16 @@ exports.onOrderProcessing = void 0;
|
|
|
14
14
|
* 注文処理時処理
|
|
15
15
|
*/
|
|
16
16
|
const createDebug = require("debug");
|
|
17
|
+
const util = require("util");
|
|
17
18
|
const factory = require("../../../factory");
|
|
18
19
|
const order_1 = require("../../../factory/order");
|
|
20
|
+
const settings_1 = require("../../../settings");
|
|
19
21
|
const factory_1 = require("./onOrderProcessing/factory");
|
|
20
22
|
const debug = createDebug('chevre-domain:service:order');
|
|
21
23
|
const USE_CONFIRM_REGISTER_SERVICE_TRANSACTION = process.env.USE_CONFIRM_REGISTER_SERVICE_TRANSACTION === '1';
|
|
22
24
|
function onOrderProcessing(params) {
|
|
23
25
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c
|
|
26
|
+
var _a, _b, _c;
|
|
25
27
|
debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
|
|
26
28
|
let tasks = [];
|
|
27
29
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
|
|
@@ -53,13 +55,15 @@ function onOrderProcessing(params) {
|
|
|
53
55
|
case factory.orderStatus.OrderProcessing:
|
|
54
56
|
// 冗長なconfirmReserveTransactionタスク作成を回避(2023-08-25~)
|
|
55
57
|
yield createConfirmReserveTransactionTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (settings_1.USE_SEND_ORDER_ON_ORDER_PROCESSING) {
|
|
59
|
+
// 冗長なsendOrderタスク作成を回避(2023-08-25~)
|
|
60
|
+
// await createSendOrderTransactionTaskIfNotExist({
|
|
61
|
+
// object: params.order,
|
|
62
|
+
// potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
|
|
63
|
+
// })(repos);
|
|
64
|
+
}
|
|
61
65
|
yield createGivePointAwardTaskIfNotExist({
|
|
62
|
-
potentialActions: (
|
|
66
|
+
potentialActions: (_c = (_b = (_a = params.placeOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.potentialActions
|
|
63
67
|
})(repos);
|
|
64
68
|
break;
|
|
65
69
|
default:
|
|
@@ -67,14 +71,10 @@ function onOrderProcessing(params) {
|
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
exports.onOrderProcessing = onOrderProcessing;
|
|
70
|
-
// const COA_TASK_DELAY_IN_SECONDS = 0;
|
|
71
74
|
function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder) {
|
|
72
75
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
73
76
|
const taskRunsAt = new Date();
|
|
74
77
|
const taskRunsAt4coa = new Date();
|
|
75
|
-
// const taskRunsAt4coa = moment(order.orderDate)
|
|
76
|
-
// .add(COA_TASK_DELAY_IN_SECONDS, 'seconds')
|
|
77
|
-
// .toDate();
|
|
78
78
|
const confirmObjects = [
|
|
79
79
|
...(0, factory_1.createConfirmReservationActionObject4ChevreByOrder)({ order }),
|
|
80
80
|
...(0, factory_1.createConfirmReservationActionObject4COAByOrder)({ order })
|
|
@@ -93,7 +93,9 @@ function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder) {
|
|
|
93
93
|
: factory.service.webAPI.Identifier.Chevre
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
+
const taskIdentifier = util.format('%s:%s:%s:%s:%s:%s', data.project.id, factory.taskName.ConfirmReserveTransaction, data.purpose.typeOf, data.purpose.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
96
97
|
const confirmReserveTransactionTask = {
|
|
98
|
+
identifier: taskIdentifier,
|
|
97
99
|
project: order.project,
|
|
98
100
|
name: factory.taskName.ConfirmReserveTransaction,
|
|
99
101
|
status: factory.taskStatus.Ready,
|
|
@@ -103,7 +105,8 @@ function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder) {
|
|
|
103
105
|
executionResults: [],
|
|
104
106
|
data
|
|
105
107
|
};
|
|
106
|
-
|
|
108
|
+
// await repos.task.createConfirmReserveTransactionTaskIfNotExist(confirmReserveTransactionTask, { emitImmediately: true });
|
|
109
|
+
yield repos.task.createIfNotExistByIdentifier(confirmReserveTransactionTask, { emitImmediately: true });
|
|
107
110
|
})));
|
|
108
111
|
});
|
|
109
112
|
}
|
|
@@ -159,30 +162,42 @@ function createConfirmRegisterServiceTransactionTasks(order, simpleOrder) {
|
|
|
159
162
|
}
|
|
160
163
|
});
|
|
161
164
|
}
|
|
162
|
-
function createSendOrderTransactionTaskIfNotExist(params
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
165
|
+
// function createSendOrderTransactionTaskIfNotExist(params: {
|
|
166
|
+
// object: factory.order.IOrder | IExternalOrder;
|
|
167
|
+
// potentialActions?: factory.action.trade.order.IPotentialActions;
|
|
168
|
+
// }) {
|
|
169
|
+
// return async (repos: {
|
|
170
|
+
// task: TaskRepo;
|
|
171
|
+
// }): Promise<void> => {
|
|
172
|
+
// const now = new Date();
|
|
173
|
+
// const sendOrderByTransaction = params.potentialActions?.sendOrder;
|
|
174
|
+
// if (sendOrderByTransaction !== undefined) {
|
|
175
|
+
// const sendOrderTaskData: factory.task.IData<factory.taskName.SendOrder> = {
|
|
176
|
+
// project: sendOrderByTransaction.project,
|
|
177
|
+
// object: {
|
|
178
|
+
// ...sendOrderByTransaction.object,
|
|
179
|
+
// confirmationNumber: params.object.confirmationNumber,
|
|
180
|
+
// previousOrderStatus: factory.orderStatus.OrderProcessing
|
|
181
|
+
// }
|
|
182
|
+
// };
|
|
183
|
+
// const taskIdentifier: string =
|
|
184
|
+
// tslint:disable-next-line:max-line-length
|
|
185
|
+
// `${sendOrderTaskData.project.id}:${factory.taskName.SendOrder}:${sendOrderTaskData.object.typeOf}:${sendOrderTaskData.object.orderNumber}`;
|
|
186
|
+
// const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
|
|
187
|
+
// identifier: taskIdentifier,
|
|
188
|
+
// project: sendOrderByTransaction.project,
|
|
189
|
+
// name: factory.taskName.SendOrder,
|
|
190
|
+
// status: factory.taskStatus.Ready,
|
|
191
|
+
// runsAt: now, // なるはやで実行
|
|
192
|
+
// remainingNumberOfTries: 10,
|
|
193
|
+
// numberOfTried: 0,
|
|
194
|
+
// executionResults: [],
|
|
195
|
+
// data: sendOrderTaskData
|
|
196
|
+
// };
|
|
197
|
+
// await repos.task.createIfNotExistByIdentifier(sendOrderTask, { emitImmediately: true });
|
|
198
|
+
// }
|
|
199
|
+
// };
|
|
200
|
+
// }
|
|
186
201
|
function createGivePointAwardTaskIfNotExist(params) {
|
|
187
202
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
188
203
|
var _a;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { onOrderCancelled } from './onOrderStatusChanged/onOrderCancelled';
|
|
5
5
|
import { onOrderDelivered } from './onOrderStatusChanged/onOrderDelivered';
|
|
6
|
+
import { onOrderDeliveredPartially } from './onOrderStatusChanged/onOrderDeliveredPartially';
|
|
7
|
+
import { onOrderInTransit } from './onOrderStatusChanged/onOrderInTransit';
|
|
6
8
|
import { onOrderPaymentDue } from './onOrderStatusChanged/onOrderPaymentDue';
|
|
7
9
|
import { IExternalOrder, onOrderProcessing } from './onOrderStatusChanged/onOrderProcessing';
|
|
8
10
|
import { onOrderReturned } from './onOrderStatusChanged/onOrderReturned';
|
|
9
|
-
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderPaymentDue, onOrderProcessing, onOrderReturned };
|
|
11
|
+
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderDeliveredPartially, onOrderInTransit, onOrderPaymentDue, onOrderProcessing, onOrderReturned };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
3
|
+
exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderInTransit = exports.onOrderDeliveredPartially = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文ステータス変更時処理
|
|
6
6
|
*/
|
|
@@ -8,6 +8,10 @@ const onOrderCancelled_1 = require("./onOrderStatusChanged/onOrderCancelled");
|
|
|
8
8
|
Object.defineProperty(exports, "onOrderCancelled", { enumerable: true, get: function () { return onOrderCancelled_1.onOrderCancelled; } });
|
|
9
9
|
const onOrderDelivered_1 = require("./onOrderStatusChanged/onOrderDelivered");
|
|
10
10
|
Object.defineProperty(exports, "onOrderDelivered", { enumerable: true, get: function () { return onOrderDelivered_1.onOrderDelivered; } });
|
|
11
|
+
const onOrderDeliveredPartially_1 = require("./onOrderStatusChanged/onOrderDeliveredPartially");
|
|
12
|
+
Object.defineProperty(exports, "onOrderDeliveredPartially", { enumerable: true, get: function () { return onOrderDeliveredPartially_1.onOrderDeliveredPartially; } });
|
|
13
|
+
const onOrderInTransit_1 = require("./onOrderStatusChanged/onOrderInTransit");
|
|
14
|
+
Object.defineProperty(exports, "onOrderInTransit", { enumerable: true, get: function () { return onOrderInTransit_1.onOrderInTransit; } });
|
|
11
15
|
const onOrderPaymentDue_1 = require("./onOrderStatusChanged/onOrderPaymentDue");
|
|
12
16
|
Object.defineProperty(exports, "onOrderPaymentDue", { enumerable: true, get: function () { return onOrderPaymentDue_1.onOrderPaymentDue; } });
|
|
13
17
|
const onOrderProcessing_1 = require("./onOrderStatusChanged/onOrderProcessing");
|
|
@@ -2,6 +2,7 @@ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOf
|
|
|
2
2
|
import type { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
|
|
3
3
|
import type { MongoRepository as ActionRepo } from '../../repo/action';
|
|
4
4
|
import type { MongoRepository as OrderRepo } from '../../repo/order';
|
|
5
|
+
import type { MongoRepository as OrderInTransactionRepo } from '../../repo/orderInTransaction';
|
|
5
6
|
import type { MongoRepository as TaskRepo } from '../../repo/task';
|
|
6
7
|
import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
7
8
|
import { IExternalOrder } from './onOrderStatusChanged';
|
|
@@ -39,6 +40,7 @@ declare function placeOrder(params: {
|
|
|
39
40
|
accountingReport: AccountingReportRepo;
|
|
40
41
|
action: ActionRepo;
|
|
41
42
|
order: OrderRepo;
|
|
43
|
+
orderInTransaction: OrderInTransactionRepo;
|
|
42
44
|
task: TaskRepo;
|
|
43
45
|
transaction: TransactionRepo;
|
|
44
46
|
}) => Promise<{
|
|
@@ -159,7 +159,7 @@ function placeOrderWithoutTransaction(params) {
|
|
|
159
159
|
}
|
|
160
160
|
throw error;
|
|
161
161
|
}
|
|
162
|
-
yield repos.action.
|
|
162
|
+
yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
|
|
163
163
|
// 経理レポートを保管は外部注文の場合保留(2023-12-08~)
|
|
164
164
|
// await createAccountingReportIfNotExist(order)({ accountingReport: repos.accountingReport });
|
|
165
165
|
});
|
|
@@ -168,7 +168,6 @@ exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
|
|
|
168
168
|
/**
|
|
169
169
|
* 注文を作成する
|
|
170
170
|
*/
|
|
171
|
-
// tslint:disable-next-line:max-func-body-length
|
|
172
171
|
function placeOrder(params) {
|
|
173
172
|
// tslint:disable-next-line:max-func-body-length
|
|
174
173
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -182,6 +181,10 @@ function placeOrder(params) {
|
|
|
182
181
|
confirmationNumber: params.object.confirmationNumber,
|
|
183
182
|
orderNumber: params.object.orderNumber
|
|
184
183
|
})({ transaction: repos.transaction });
|
|
184
|
+
// USE_ORDER_PAYMENT_DUE_ON_PLACED設定を廃止したので、必ずOrderPaymentDueのはず(2024-01-10~)
|
|
185
|
+
if (order.orderStatus !== factory.orderStatus.OrderPaymentDue) {
|
|
186
|
+
throw new factory.errors.ServiceUnavailable(`orderStatus must be ${factory.orderStatus.OrderPaymentDue}`);
|
|
187
|
+
}
|
|
185
188
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(order, { noProfile: true });
|
|
186
189
|
const simpleOrder = {
|
|
187
190
|
typeOf: order.typeOf,
|
|
@@ -224,6 +227,8 @@ function placeOrder(params) {
|
|
|
224
227
|
if (completedActions.length === 0) {
|
|
225
228
|
const action = yield repos.action.start(orderActionAttributes);
|
|
226
229
|
try {
|
|
230
|
+
// orderInTransactionを考慮(2024-01-14~)
|
|
231
|
+
yield repos.orderInTransaction.placeOrder(order);
|
|
227
232
|
yield repos.order.createIfNotExist(order);
|
|
228
233
|
}
|
|
229
234
|
catch (error) {
|
|
@@ -235,7 +240,7 @@ function placeOrder(params) {
|
|
|
235
240
|
}
|
|
236
241
|
throw error;
|
|
237
242
|
}
|
|
238
|
-
yield repos.action.
|
|
243
|
+
yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
|
|
239
244
|
}
|
|
240
245
|
if (params.useOnOrderStatusChanged) {
|
|
241
246
|
// 経理レポートを保管
|
|
@@ -259,27 +264,26 @@ function placeOrder(params) {
|
|
|
259
264
|
})({
|
|
260
265
|
task: repos.task
|
|
261
266
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// OrderPaymentDue
|
|
265
|
-
//
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
});
|
|
267
|
+
// } else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
|
|
268
|
+
// // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
|
|
269
|
+
// // OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
|
|
270
|
+
// await onOrderPaymentDue({
|
|
271
|
+
// order: {
|
|
272
|
+
// paymentMethods: order.paymentMethods,
|
|
273
|
+
// project: order.project,
|
|
274
|
+
// orderNumber: order.orderNumber,
|
|
275
|
+
// confirmationNumber: order.confirmationNumber,
|
|
276
|
+
// customer: order.customer,
|
|
277
|
+
// orderDate: order.orderDate,
|
|
278
|
+
// seller: order.seller,
|
|
279
|
+
// typeOf: order.typeOf,
|
|
280
|
+
// price: order.price,
|
|
281
|
+
// priceCurrency: order.priceCurrency,
|
|
282
|
+
// orderStatus: factory.orderStatus.OrderPaymentDue
|
|
283
|
+
// }
|
|
284
|
+
// })({
|
|
285
|
+
// task: repos.task
|
|
286
|
+
// });
|
|
283
287
|
}
|
|
284
288
|
else {
|
|
285
289
|
throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
|
|
@@ -295,11 +299,6 @@ function placeOrder(params) {
|
|
|
295
299
|
})(repos);
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
|
-
// onOrderStatusChangedへ移行(2023-08-17~)
|
|
299
|
-
// await onPlaceOrder({
|
|
300
|
-
// object: order,
|
|
301
|
-
// potentialActions: params.potentialActions
|
|
302
|
-
// })(repos);
|
|
303
302
|
return { order };
|
|
304
303
|
});
|
|
305
304
|
}
|
|
@@ -26,15 +26,24 @@ function returnOrder(params) {
|
|
|
26
26
|
? params.object.dateReturned
|
|
27
27
|
: new Date();
|
|
28
28
|
const returner = params.agent;
|
|
29
|
-
|
|
29
|
+
const order = yield repos.order.findByOrderNumber({
|
|
30
30
|
orderNumber,
|
|
31
31
|
project: { id: params.project.id },
|
|
32
32
|
inclusion: [
|
|
33
33
|
'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
|
|
34
|
-
'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate'
|
|
34
|
+
'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate', 'orderStatus'
|
|
35
35
|
],
|
|
36
36
|
exclusion: []
|
|
37
37
|
});
|
|
38
|
+
// 注文ステータス検証(2024-01-10~)
|
|
39
|
+
switch (order.orderStatus) {
|
|
40
|
+
case factory.orderStatus.OrderDelivered:
|
|
41
|
+
case factory.orderStatus.OrderReturned:
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
// OrderDeliveredへの処理が進行中と考えられるので、ひとまず失敗させてリトライに期待
|
|
45
|
+
throw new factory.errors.Argument('object.orderNumber', `orderStatus not returnable: ${order.orderStatus}`);
|
|
46
|
+
}
|
|
38
47
|
// 返品取引検索
|
|
39
48
|
const returnOrderTransactions = yield repos.transaction.search({
|
|
40
49
|
limit: 1,
|
|
@@ -72,7 +81,7 @@ function returnOrder(params) {
|
|
|
72
81
|
typeOf: factory.actionType.ReturnAction
|
|
73
82
|
};
|
|
74
83
|
let returnedOwnershipInfos = [];
|
|
75
|
-
|
|
84
|
+
let returnedOrder;
|
|
76
85
|
const action = yield repos.action.start(returnOrderActionAttributes);
|
|
77
86
|
try {
|
|
78
87
|
returnedOwnershipInfos = yield processReturnOrder(order, dateReturned)({
|
|
@@ -80,7 +89,7 @@ function returnOrder(params) {
|
|
|
80
89
|
ownershipInfo: repos.ownershipInfo
|
|
81
90
|
});
|
|
82
91
|
// 注文ステータス変更
|
|
83
|
-
|
|
92
|
+
returnedOrder = yield repos.order.returnOrder({
|
|
84
93
|
project: { id: order.project.id },
|
|
85
94
|
orderNumber,
|
|
86
95
|
dateReturned,
|
|
@@ -98,21 +107,21 @@ function returnOrder(params) {
|
|
|
98
107
|
throw error;
|
|
99
108
|
}
|
|
100
109
|
const result = returnedOwnershipInfos;
|
|
101
|
-
yield repos.action.
|
|
110
|
+
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result });
|
|
102
111
|
if (params.useOnOrderStatusChanged) {
|
|
103
112
|
yield (0, onOrderStatusChanged_1.onOrderReturned)({
|
|
104
113
|
order: {
|
|
105
|
-
project:
|
|
106
|
-
typeOf:
|
|
107
|
-
orderNumber:
|
|
108
|
-
dateReturned:
|
|
109
|
-
id:
|
|
110
|
-
customer:
|
|
111
|
-
returner:
|
|
112
|
-
seller:
|
|
113
|
-
price:
|
|
114
|
-
priceCurrency:
|
|
115
|
-
orderDate:
|
|
114
|
+
project: returnedOrder.project,
|
|
115
|
+
typeOf: returnedOrder.typeOf,
|
|
116
|
+
orderNumber: returnedOrder.orderNumber,
|
|
117
|
+
dateReturned: returnedOrder.dateReturned,
|
|
118
|
+
id: returnedOrder.id,
|
|
119
|
+
customer: returnedOrder.customer,
|
|
120
|
+
returner: returnedOrder.returner,
|
|
121
|
+
seller: returnedOrder.seller,
|
|
122
|
+
price: returnedOrder.price,
|
|
123
|
+
priceCurrency: returnedOrder.priceCurrency,
|
|
124
|
+
orderDate: returnedOrder.orderDate,
|
|
116
125
|
orderStatus: factory.orderStatus.OrderReturned
|
|
117
126
|
},
|
|
118
127
|
returnOrderTransaction
|
|
@@ -24,6 +24,11 @@ declare function sendOrder(params: {
|
|
|
24
24
|
object: {
|
|
25
25
|
confirmationNumber: string;
|
|
26
26
|
orderNumber: string;
|
|
27
|
+
previousOrderStatus: factory.orderStatus.OrderProcessing | factory.orderStatus.OrderInTransit;
|
|
28
|
+
acceptedOffers: {
|
|
29
|
+
limit: number;
|
|
30
|
+
page: number;
|
|
31
|
+
};
|
|
27
32
|
};
|
|
28
33
|
useOnOrderStatusChanged: boolean;
|
|
29
34
|
}): ISendOperation<void>;
|
|
@@ -10,21 +10,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sendOrder = void 0;
|
|
13
|
+
const createDebug = require("debug");
|
|
13
14
|
const order_1 = require("../../factory/order");
|
|
14
15
|
const factory_1 = require("../delivery/factory");
|
|
15
16
|
const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
|
|
16
17
|
const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
|
|
17
18
|
const factory = require("../../factory");
|
|
19
|
+
const debug = createDebug('chevre-domain:service:order');
|
|
18
20
|
/**
|
|
19
21
|
* 注文を配送する
|
|
20
22
|
*/
|
|
21
23
|
function sendOrder(params) {
|
|
22
24
|
// tslint:disable-next-line:max-func-body-length
|
|
23
25
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a;
|
|
26
|
+
var _a, _b, _c;
|
|
25
27
|
if (typeof params.useOnOrderStatusChanged !== 'boolean') {
|
|
26
28
|
throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
|
|
27
29
|
}
|
|
30
|
+
if (typeof ((_a = params.object.acceptedOffers) === null || _a === void 0 ? void 0 : _a.limit) !== 'number') {
|
|
31
|
+
throw new factory.errors.Argument('object.acceptedOffers.limit', 'must be number');
|
|
32
|
+
}
|
|
33
|
+
if (typeof ((_b = params.object.acceptedOffers) === null || _b === void 0 ? void 0 : _b.page) !== 'number') {
|
|
34
|
+
throw new factory.errors.Argument('object.acceptedOffers.page', 'must be number');
|
|
35
|
+
}
|
|
36
|
+
if (params.object.acceptedOffers.limit <= 0) {
|
|
37
|
+
throw new factory.errors.Argument('object.acceptedOffers.limit', 'must be greater than 1');
|
|
38
|
+
}
|
|
39
|
+
if (params.object.acceptedOffers.page <= 0) {
|
|
40
|
+
throw new factory.errors.Argument('object.acceptedOffers.page', 'must be greater than 1');
|
|
41
|
+
}
|
|
28
42
|
try {
|
|
29
43
|
const orderNumber = params.object.orderNumber;
|
|
30
44
|
const confirmationNumber = params.object.confirmationNumber;
|
|
@@ -62,9 +76,11 @@ function sendOrder(params) {
|
|
|
62
76
|
priceCurrency: order.priceCurrency,
|
|
63
77
|
orderDate: order.orderDate
|
|
64
78
|
};
|
|
79
|
+
const { limit, page } = params.object.acceptedOffers;
|
|
80
|
+
const sendOrderObject = Object.assign(Object.assign({}, simpleOrder), { acceptedOffers: { limit, page } });
|
|
65
81
|
const sendOrderActionAttributes = {
|
|
66
|
-
agent: (typeof ((
|
|
67
|
-
object:
|
|
82
|
+
agent: (typeof ((_c = params.agent) === null || _c === void 0 ? void 0 : _c.typeOf) === 'string') ? params.agent : order.project,
|
|
83
|
+
object: sendOrderObject,
|
|
68
84
|
potentialActions: {
|
|
69
85
|
// sendEmailMessage: undefined
|
|
70
86
|
},
|
|
@@ -74,23 +90,34 @@ function sendOrder(params) {
|
|
|
74
90
|
};
|
|
75
91
|
const action = yield repos.action.start(sendOrderActionAttributes);
|
|
76
92
|
let ownershipInfos;
|
|
93
|
+
let allOffersDelivered = false;
|
|
77
94
|
try {
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
// const acceptedOffers = await repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
|
|
96
|
+
// orderNumber: { $eq: order.orderNumber },
|
|
97
|
+
// project: { id: { $eq: order.project.id } }
|
|
98
|
+
// });
|
|
99
|
+
const { acceptedOffers, numAcceptedOffers } = yield repos.acceptedOffer.searchSlicedAcceptedOffersByOrderNumber({
|
|
100
|
+
$slice: [limit * (page - 1), limit],
|
|
101
|
+
orderNumber: { $eq: order.orderNumber },
|
|
102
|
+
project: { id: { $eq: order.project.id } }
|
|
84
103
|
});
|
|
104
|
+
debug('delivering...', order.orderNumber, acceptedOffers.map((offer) => `${offer.itemOffered.id}`), params.object.acceptedOffers);
|
|
105
|
+
// 所有権作成
|
|
106
|
+
ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({ order: Object.assign(Object.assign({}, order), { acceptedOffers }) });
|
|
85
107
|
ownershipInfos = yield Promise.all(ownershipInfos.map((ownershipInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
86
108
|
return repos.ownershipInfo.createIfNotExistByIdentifier(ownershipInfo);
|
|
87
109
|
})));
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
const deliveredCount = limit * page;
|
|
111
|
+
debug(deliveredCount, 'delivered.', order.orderNumber, params.object.acceptedOffers);
|
|
112
|
+
if (deliveredCount >= numAcceptedOffers) {
|
|
113
|
+
order = yield repos.order.changeStatus({
|
|
114
|
+
project: { id: order.project.id },
|
|
115
|
+
orderNumber,
|
|
116
|
+
orderStatus: factory.orderStatus.OrderDelivered,
|
|
117
|
+
previousOrderStatus: params.object.previousOrderStatus
|
|
118
|
+
});
|
|
119
|
+
allOffersDelivered = true;
|
|
120
|
+
}
|
|
94
121
|
}
|
|
95
122
|
catch (error) {
|
|
96
123
|
try {
|
|
@@ -102,22 +129,33 @@ function sendOrder(params) {
|
|
|
102
129
|
throw error;
|
|
103
130
|
}
|
|
104
131
|
const result = ownershipInfos;
|
|
105
|
-
yield repos.action.
|
|
132
|
+
yield repos.action.completeWithVoid({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
|
|
133
|
+
debug('allOffersDelivered?:', allOffersDelivered, order.orderNumber);
|
|
106
134
|
if (params.useOnOrderStatusChanged) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
135
|
+
if (allOffersDelivered) {
|
|
136
|
+
yield (0, onOrderStatusChanged_1.onOrderDelivered)({
|
|
137
|
+
order: {
|
|
138
|
+
id: order.id,
|
|
139
|
+
customer: order.customer,
|
|
140
|
+
orderDate: order.orderDate,
|
|
141
|
+
orderNumber: order.orderNumber,
|
|
142
|
+
project: order.project,
|
|
143
|
+
typeOf: order.typeOf,
|
|
144
|
+
orderStatus: factory.orderStatus.OrderDelivered
|
|
145
|
+
},
|
|
146
|
+
placeOrderTransaction
|
|
147
|
+
})({
|
|
148
|
+
task: repos.task
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
yield (0, onOrderStatusChanged_1.onOrderDeliveredPartially)({
|
|
153
|
+
order: Object.assign(Object.assign({}, order), { acceptedOffers: params.object.acceptedOffers, orderStatus: params.object.previousOrderStatus })
|
|
154
|
+
// placeOrderTransaction
|
|
155
|
+
})({
|
|
156
|
+
task: repos.task
|
|
157
|
+
});
|
|
158
|
+
}
|
|
121
159
|
}
|
|
122
160
|
}
|
|
123
161
|
catch (error) {
|
|
@@ -10,7 +10,6 @@ import type { MongoRepository as PaymentServiceRepo } from '../../repo/paymentSe
|
|
|
10
10
|
import type { MongoRepository as PaymentServiceProviderRepo } from '../../repo/paymentServiceProvider';
|
|
11
11
|
import type { CognitoRepository as PersonRepo } from '../../repo/person';
|
|
12
12
|
import type { MongoRepository as ProductRepo } from '../../repo/product';
|
|
13
|
-
import type { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
14
13
|
import type { MongoRepository as PaymentAcceptedRepo } from '../../repo/sellerPaymentAccepted';
|
|
15
14
|
import type { MongoRepository as TaskRepo } from '../../repo/task';
|
|
16
15
|
import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
@@ -18,7 +17,6 @@ import type { RedisRepository as TransactionNumberRepo } from '../../repo/transa
|
|
|
18
17
|
import * as PayTransactionService from '../assetTransaction/pay';
|
|
19
18
|
import { onPaymentStatusChanged } from './any/onPaymentStatusChanged';
|
|
20
19
|
import { person2username } from './any/person2username';
|
|
21
|
-
type IAuthorizePaymentAction = factory.action.authorize.paymentMethod.any.IAction;
|
|
22
20
|
/**
|
|
23
21
|
* 決済承認中止
|
|
24
22
|
* タスクから決済承認を取り消す
|
|
@@ -30,7 +28,6 @@ declare function voidPayTransaction(params: factory.task.IData<factory.taskName.
|
|
|
30
28
|
paymentAccepted: PaymentAcceptedRepo;
|
|
31
29
|
paymentService: PaymentServiceRepo;
|
|
32
30
|
paymentServiceProvider: PaymentServiceProviderRepo;
|
|
33
|
-
project: ProjectRepo;
|
|
34
31
|
task: TaskRepo;
|
|
35
32
|
transaction: TransactionRepo;
|
|
36
33
|
}) => Promise<void>;
|
|
@@ -41,7 +38,6 @@ declare function invalidatePaymentUrl(params: factory.task.IData<factory.taskNam
|
|
|
41
38
|
paymentAccepted: PaymentAcceptedRepo;
|
|
42
39
|
paymentService: PaymentServiceRepo;
|
|
43
40
|
paymentServiceProvider: PaymentServiceProviderRepo;
|
|
44
|
-
project: ProjectRepo;
|
|
45
41
|
task: TaskRepo;
|
|
46
42
|
transaction: TransactionRepo;
|
|
47
43
|
}) => Promise<void>;
|
|
@@ -53,7 +49,6 @@ declare function processVoidPayTransaction(params: factory.task.IData<factory.ta
|
|
|
53
49
|
action: ActionRepo;
|
|
54
50
|
accountingReport: AccountingReportRepo;
|
|
55
51
|
assetTransaction: AssetTransactionRepo;
|
|
56
|
-
project: ProjectRepo;
|
|
57
52
|
task: TaskRepo;
|
|
58
53
|
transaction: TransactionRepo;
|
|
59
54
|
}) => Promise<void>;
|
|
@@ -67,7 +62,6 @@ interface IAuthorizeRepos {
|
|
|
67
62
|
paymentServiceProvider: PaymentServiceProviderRepo;
|
|
68
63
|
person: PersonRepo;
|
|
69
64
|
product: ProductRepo;
|
|
70
|
-
project: ProjectRepo;
|
|
71
65
|
task: TaskRepo;
|
|
72
66
|
transaction: TransactionRepo;
|
|
73
67
|
transactionNumber: TransactionNumberRepo;
|
|
@@ -79,7 +73,6 @@ interface IPublishPaymentUrlRepos {
|
|
|
79
73
|
paymentService: PaymentServiceRepo;
|
|
80
74
|
paymentServiceProvider: PaymentServiceProviderRepo;
|
|
81
75
|
person: PersonRepo;
|
|
82
|
-
project: ProjectRepo;
|
|
83
76
|
transaction: TransactionRepo;
|
|
84
77
|
transactionNumber: TransactionNumberRepo;
|
|
85
78
|
}
|
|
@@ -122,5 +115,10 @@ declare function authorize(params: {
|
|
|
122
115
|
useCheckByIdentifierIfNotYet: boolean;
|
|
123
116
|
useSearchTrade4accountId: boolean;
|
|
124
117
|
};
|
|
125
|
-
}): IAuthorizeOperation<
|
|
118
|
+
}): IAuthorizeOperation<{
|
|
119
|
+
/**
|
|
120
|
+
* 承認アクションID
|
|
121
|
+
*/
|
|
122
|
+
id: string;
|
|
123
|
+
}>;
|
|
126
124
|
export { onPaymentStatusChanged, authorize, invalidatePaymentUrl, voidPayTransaction, person2username, processVoidPayTransaction, publishPaymentUrl };
|