@chevre/domain 21.37.0-alpha.13 → 21.37.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/src/chevre/processOrder.ts +62 -37
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.d.ts +16 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +168 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +3 -16
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +3 -159
- package/package.json +1 -1
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
2
3
|
import * as mongoose from 'mongoose';
|
|
3
4
|
|
|
4
5
|
import { chevre } from '../../../lib/index';
|
|
5
6
|
|
|
6
7
|
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
const orderNumbers = [
|
|
8
|
-
'SSK0-2157757-5763702',
|
|
9
|
-
'SSK3-0756604-4738180'
|
|
10
|
-
];
|
|
11
8
|
|
|
12
9
|
async function main() {
|
|
13
10
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
@@ -16,45 +13,73 @@ async function main() {
|
|
|
16
13
|
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
17
14
|
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const cursor = orderRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'project.id': { $eq: project.id },
|
|
19
|
+
// orderNumber: { $eq: 'SSK9-4896645-5698154' },
|
|
20
|
+
orderDate: {
|
|
21
|
+
$lte: moment('2024-07-03T18:00:00Z')
|
|
22
|
+
.toDate(),
|
|
23
|
+
$gte: moment('2024-06-30T18:00:00Z')
|
|
24
|
+
.toDate()
|
|
25
|
+
},
|
|
26
|
+
orderStatus: { $eq: chevre.factory.orderStatus.OrderProcessing }
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
confirmationNumber: 1,
|
|
30
|
+
orderDate: 1, orderNumber: 1,
|
|
31
|
+
project: 1, typeOf: 1, orderStatus: 1
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
console.log('orders found');
|
|
35
|
+
|
|
36
|
+
let i = 0;
|
|
37
|
+
let updateCount = 0;
|
|
38
|
+
await cursor.eachAsync(async (doc) => {
|
|
39
|
+
i += 1;
|
|
40
|
+
const order: Pick<chevre.factory.order.IOrder, 'confirmationNumber' | 'orderDate' | 'orderNumber' | 'project' | 'typeOf' | 'orderStatus'> = doc.toObject();
|
|
26
41
|
if (order.orderStatus !== chevre.factory.orderStatus.OrderProcessing) {
|
|
27
42
|
console.log('nothing to do', order.orderStatus, order.orderNumber);
|
|
28
|
-
|
|
43
|
+
} else {
|
|
44
|
+
const { orderNumber } = order;
|
|
45
|
+
|
|
46
|
+
const itemOfferedTypeOfs = <chevre.factory.order.IItemOffered['typeOf'][]>await acceptedOfferRepo.distinctValues(
|
|
47
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
48
|
+
'acceptedOffers.itemOffered.typeOf'
|
|
49
|
+
);
|
|
50
|
+
const serialNumbers = await acceptedOfferRepo.distinctValues(
|
|
51
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
52
|
+
'acceptedOffers.serialNumber'
|
|
53
|
+
);
|
|
54
|
+
const offeredThroughIdentifier = (<chevre.factory.service.webAPI.Identifier[]>await acceptedOfferRepo.distinctValues(
|
|
55
|
+
{ orderNumber: { $in: [orderNumber] } },
|
|
56
|
+
'acceptedOffers.offeredThrough.identifier'
|
|
57
|
+
)).shift();
|
|
58
|
+
|
|
59
|
+
console.log('processing order', order, itemOfferedTypeOfs, serialNumbers, offeredThroughIdentifier);
|
|
60
|
+
await (await chevre.service.order.createService()).processOrder({
|
|
61
|
+
order: {
|
|
62
|
+
...order,
|
|
63
|
+
itemOfferedTypeOf: itemOfferedTypeOfs[0], // 1つしかない前提
|
|
64
|
+
serialNumbers,
|
|
65
|
+
offeredThroughIdentifier
|
|
66
|
+
},
|
|
67
|
+
options: { force: true }
|
|
68
|
+
})({ task: taskRepo });
|
|
69
|
+
console.log('order processed', order.orderNumber);
|
|
70
|
+
updateCount += 1;
|
|
71
|
+
console.log('updated.', order.project.id, order.orderNumber, order.orderDate, i);
|
|
29
72
|
}
|
|
73
|
+
});
|
|
30
74
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'acceptedOffers.itemOffered.typeOf'
|
|
34
|
-
);
|
|
35
|
-
const serialNumbers = await acceptedOfferRepo.distinctValues(
|
|
36
|
-
{ orderNumber: { $in: [orderNumber] } },
|
|
37
|
-
'acceptedOffers.serialNumber'
|
|
38
|
-
);
|
|
39
|
-
const offeredThroughIdentifier = (<chevre.factory.service.webAPI.Identifier[]>await acceptedOfferRepo.distinctValues(
|
|
40
|
-
{ orderNumber: { $in: [orderNumber] } },
|
|
41
|
-
'acceptedOffers.offeredThrough.identifier'
|
|
42
|
-
)).shift();
|
|
43
|
-
|
|
44
|
-
console.log('processing order', order, itemOfferedTypeOfs, serialNumbers, offeredThroughIdentifier);
|
|
45
|
-
(await chevre.service.order.createService()).processOrder({
|
|
46
|
-
order: {
|
|
47
|
-
...order,
|
|
48
|
-
itemOfferedTypeOf: itemOfferedTypeOfs[0], // 1つしかない前提
|
|
49
|
-
serialNumbers,
|
|
50
|
-
offeredThroughIdentifier
|
|
51
|
-
},
|
|
52
|
-
options: { force: true }
|
|
53
|
-
})({ task: taskRepo });
|
|
54
|
-
console.log('order processed', order.orderNumber);
|
|
55
|
-
}
|
|
75
|
+
console.log(i, 'orders checked');
|
|
76
|
+
console.log(updateCount, 'orders updated');
|
|
56
77
|
}
|
|
57
78
|
|
|
79
|
+
main()
|
|
80
|
+
.then()
|
|
81
|
+
.catch(console.error);
|
|
82
|
+
|
|
58
83
|
main()
|
|
59
84
|
.then(() => {
|
|
60
85
|
console.log('success!');
|
|
@@ -15,5 +15,5 @@ declare function createConfirmReservationActionObject4COAByOrder(params: {
|
|
|
15
15
|
};
|
|
16
16
|
}): factory.task.confirmReserveTransaction.IObject4COAOptimized[];
|
|
17
17
|
type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
|
|
18
|
-
declare function createCheckResourceTask(order: IProcessingOrder): factory.task.checkResource.IAttributes;
|
|
19
|
-
export { IExternalOrder, createInformTasks, createCheckResourceTask, createConfirmReservationActionObject4ChevreByOrder, createConfirmReservationActionObject4COAByOrder };
|
|
18
|
+
declare function createCheckResourceTask(order: Pick<IProcessingOrder, 'orderNumber' | 'project' | 'typeOf'>): factory.task.checkResource.IAttributes;
|
|
19
|
+
export { IExternalOrder, IProcessingOrder, createInformTasks, createCheckResourceTask, createConfirmReservationActionObject4ChevreByOrder, createConfirmReservationActionObject4COAByOrder };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MongoRepository as TaskRepo } from '../../../../repo/task';
|
|
2
|
+
import * as factory from '../../../../factory';
|
|
3
|
+
import { IProcessingOrder } from './factory';
|
|
4
|
+
declare function processOrder(params: {
|
|
5
|
+
order: Pick<IProcessingOrder, 'confirmationNumber' | 'orderDate' | 'orderNumber' | 'project' | 'typeOf'> & {
|
|
6
|
+
itemOfferedTypeOf: factory.order.IItemOffered['typeOf'];
|
|
7
|
+
serialNumbers: string[];
|
|
8
|
+
offeredThroughIdentifier?: factory.service.webAPI.Identifier;
|
|
9
|
+
};
|
|
10
|
+
options: {
|
|
11
|
+
force: boolean;
|
|
12
|
+
};
|
|
13
|
+
}): (repos: {
|
|
14
|
+
task: TaskRepo;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
export { processOrder };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.processOrder = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 注文処理時処理
|
|
15
|
+
*/
|
|
16
|
+
const createDebug = require("debug");
|
|
17
|
+
const util = require("util");
|
|
18
|
+
const factory = require("../../../../factory");
|
|
19
|
+
const factory_1 = require("./factory");
|
|
20
|
+
const debug = createDebug('chevre-domain:service:order');
|
|
21
|
+
function processOrder(params) {
|
|
22
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const simpleOrder = {
|
|
24
|
+
typeOf: params.order.typeOf,
|
|
25
|
+
// seller: {
|
|
26
|
+
// id: params.order.seller.id,
|
|
27
|
+
// typeOf: params.order.seller.typeOf,
|
|
28
|
+
// name: params.order.seller.name
|
|
29
|
+
// }, // 廃止(2024-03-06~)
|
|
30
|
+
// customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
|
|
31
|
+
orderNumber: params.order.orderNumber,
|
|
32
|
+
// price: params.order.price,
|
|
33
|
+
// priceCurrency: params.order.priceCurrency,
|
|
34
|
+
orderDate: params.order.orderDate
|
|
35
|
+
};
|
|
36
|
+
if (params.order.itemOfferedTypeOf === factory.actionType.MoneyTransfer) {
|
|
37
|
+
yield createConfirmMoneyTransferTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
38
|
+
}
|
|
39
|
+
else if (params.order.itemOfferedTypeOf === factory.reservationType.BusReservation
|
|
40
|
+
|| params.order.itemOfferedTypeOf === factory.reservationType.EventReservation) {
|
|
41
|
+
// 冗長なconfirmReserveTransactionタスク作成を回避(2023-08-25~)
|
|
42
|
+
yield createConfirmReserveTransactionTasksIfNotExist(params.order, simpleOrder, params.options)(repos);
|
|
43
|
+
}
|
|
44
|
+
else if (params.order.itemOfferedTypeOf === factory.permit.PermitType.Permit) {
|
|
45
|
+
yield createConfirmRegisterServiceTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.processOrder = processOrder;
|
|
50
|
+
const NUM_TRY_CONFIRM_RESERVE_TRANSACTION = 20;
|
|
51
|
+
function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder, options) {
|
|
52
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const taskRunsAt = new Date();
|
|
54
|
+
const taskRunsAt4coa = new Date();
|
|
55
|
+
let confirmObjects;
|
|
56
|
+
if (order.offeredThroughIdentifier === factory.service.webAPI.Identifier.COA) {
|
|
57
|
+
confirmObjects = (0, factory_1.createConfirmReservationActionObject4COAByOrder)({ order });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
confirmObjects = (0, factory_1.createConfirmReservationActionObject4ChevreByOrder)({ order });
|
|
61
|
+
}
|
|
62
|
+
yield Promise.all(confirmObjects.map((confirmObject) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const data = {
|
|
64
|
+
project: order.project,
|
|
65
|
+
typeOf: factory.actionType.ConfirmAction,
|
|
66
|
+
object: confirmObject,
|
|
67
|
+
agent: order.project,
|
|
68
|
+
purpose: simpleOrder
|
|
69
|
+
// instrument廃止(2024-03-13~)
|
|
70
|
+
// instrument: {
|
|
71
|
+
// typeOf: 'WebAPI',
|
|
72
|
+
// identifier: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction)
|
|
73
|
+
// ? factory.service.webAPI.Identifier.COA
|
|
74
|
+
// : factory.service.webAPI.Identifier.Chevre
|
|
75
|
+
// }
|
|
76
|
+
};
|
|
77
|
+
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);
|
|
78
|
+
const confirmReserveTransactionTask = {
|
|
79
|
+
identifier: taskIdentifier,
|
|
80
|
+
project: order.project,
|
|
81
|
+
name: factory.taskName.ConfirmReserveTransaction,
|
|
82
|
+
status: factory.taskStatus.Ready,
|
|
83
|
+
runsAt: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction) ? taskRunsAt4coa : taskRunsAt,
|
|
84
|
+
remainingNumberOfTries: NUM_TRY_CONFIRM_RESERVE_TRANSACTION,
|
|
85
|
+
numberOfTried: 0,
|
|
86
|
+
executionResults: [],
|
|
87
|
+
data
|
|
88
|
+
};
|
|
89
|
+
yield repos.task.createIfNotExistByIdentifier(confirmReserveTransactionTask, { emitImmediately: true });
|
|
90
|
+
if (options.force === true) {
|
|
91
|
+
const existingTask = yield repos.task.findByIdentifier({
|
|
92
|
+
identifier: taskIdentifier,
|
|
93
|
+
name: confirmReserveTransactionTask.name,
|
|
94
|
+
project: { id: confirmReserveTransactionTask.project.id }
|
|
95
|
+
});
|
|
96
|
+
if (typeof (existingTask === null || existingTask === void 0 ? void 0 : existingTask.id) === 'string') {
|
|
97
|
+
const retryResult = yield repos.task.retryForciblyIfAborted({
|
|
98
|
+
id: existingTask.id,
|
|
99
|
+
remainingNumberOfTries: NUM_TRY_CONFIRM_RESERVE_TRANSACTION
|
|
100
|
+
});
|
|
101
|
+
debug('retryResult:', retryResult, 'taskIdentifier:', taskIdentifier);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function createConfirmMoneyTransferTasksIfNotExist(order, simpleOrder) {
|
|
108
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const taskRunsAt = new Date();
|
|
110
|
+
yield Promise.all(order.serialNumbers.map((moneyTransferTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const data = {
|
|
112
|
+
project: order.project,
|
|
113
|
+
typeOf: factory.actionType.ConfirmAction,
|
|
114
|
+
object: {
|
|
115
|
+
// pendingTransaction: { id: '' }, // 空文字であれば、transactionNumberで処理される
|
|
116
|
+
transactionNumber: moneyTransferTransactionNumber,
|
|
117
|
+
typeOf: factory.assetTransactionType.MoneyTransfer
|
|
118
|
+
},
|
|
119
|
+
agent: order.project,
|
|
120
|
+
purpose: simpleOrder
|
|
121
|
+
};
|
|
122
|
+
const taskIdentifier = util.format('%s:%s:%s:%s:%s:%s', data.project.id, factory.taskName.ConfirmMoneyTransfer, data.purpose.typeOf, simpleOrder.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
123
|
+
const confirmMoneyTransferTransactionTask = {
|
|
124
|
+
identifier: taskIdentifier,
|
|
125
|
+
project: order.project,
|
|
126
|
+
name: factory.taskName.ConfirmMoneyTransfer,
|
|
127
|
+
status: factory.taskStatus.Ready,
|
|
128
|
+
runsAt: taskRunsAt,
|
|
129
|
+
remainingNumberOfTries: 10,
|
|
130
|
+
numberOfTried: 0,
|
|
131
|
+
executionResults: [],
|
|
132
|
+
data
|
|
133
|
+
};
|
|
134
|
+
yield repos.task.createIfNotExistByIdentifier(confirmMoneyTransferTransactionTask, { emitImmediately: true });
|
|
135
|
+
})));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function createConfirmRegisterServiceTasksIfNotExist(order, simpleOrder) {
|
|
139
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const taskRunsAt = new Date();
|
|
141
|
+
yield Promise.all(order.serialNumbers.map((registerServiceTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const data = {
|
|
143
|
+
project: order.project,
|
|
144
|
+
typeOf: factory.actionType.ConfirmAction,
|
|
145
|
+
object: {
|
|
146
|
+
endDate: order.orderDate,
|
|
147
|
+
transactionNumber: registerServiceTransactionNumber,
|
|
148
|
+
typeOf: factory.assetTransactionType.RegisterService
|
|
149
|
+
},
|
|
150
|
+
agent: order.project,
|
|
151
|
+
purpose: simpleOrder
|
|
152
|
+
};
|
|
153
|
+
const taskIdentifier = util.format('%s:%s:%s:%s:%s:%s', data.project.id, factory.taskName.ConfirmRegisterService, data.purpose.typeOf, simpleOrder.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
154
|
+
const confirmRegisterServiceTask = {
|
|
155
|
+
identifier: taskIdentifier,
|
|
156
|
+
project: order.project,
|
|
157
|
+
name: factory.taskName.ConfirmRegisterService,
|
|
158
|
+
status: factory.taskStatus.Ready,
|
|
159
|
+
runsAt: taskRunsAt,
|
|
160
|
+
remainingNumberOfTries: 10,
|
|
161
|
+
numberOfTried: 0,
|
|
162
|
+
executionResults: [],
|
|
163
|
+
data
|
|
164
|
+
};
|
|
165
|
+
yield repos.task.createIfNotExistByIdentifier(confirmRegisterServiceTask, { emitImmediately: true });
|
|
166
|
+
})));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
2
2
|
import * as factory from '../../../factory';
|
|
3
|
-
import { IExternalOrder } from './onOrderProcessing/factory';
|
|
3
|
+
import { IExternalOrder, IProcessingOrder } from './onOrderProcessing/factory';
|
|
4
|
+
import { processOrder } from './onOrderProcessing/processOrder';
|
|
4
5
|
type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'typeOf' | 'potentialActions'>;
|
|
5
6
|
declare function onOrderProcessing(params: {
|
|
6
|
-
order:
|
|
7
|
-
orderStatus: factory.orderStatus.OrderProcessing;
|
|
8
|
-
numAcceptedOffers: number;
|
|
7
|
+
order: IProcessingOrder & {
|
|
9
8
|
itemOfferedTypeOf: factory.order.IItemOffered['typeOf'];
|
|
10
9
|
serialNumbers: string[];
|
|
11
10
|
offeredThroughIdentifier?: factory.service.webAPI.Identifier;
|
|
@@ -14,16 +13,4 @@ declare function onOrderProcessing(params: {
|
|
|
14
13
|
}): (repos: {
|
|
15
14
|
task: TaskRepo;
|
|
16
15
|
}) => Promise<void>;
|
|
17
|
-
declare function processOrder(params: {
|
|
18
|
-
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'orderDate' | 'orderNumber' | 'project' | 'typeOf'> & {
|
|
19
|
-
itemOfferedTypeOf: factory.order.IItemOffered['typeOf'];
|
|
20
|
-
serialNumbers: string[];
|
|
21
|
-
offeredThroughIdentifier?: factory.service.webAPI.Identifier;
|
|
22
|
-
};
|
|
23
|
-
options: {
|
|
24
|
-
force: boolean;
|
|
25
|
-
};
|
|
26
|
-
}): (repos: {
|
|
27
|
-
task: TaskRepo;
|
|
28
|
-
}) => Promise<void>;
|
|
29
16
|
export { IExternalOrder, onOrderProcessing, processOrder };
|
|
@@ -14,11 +14,12 @@ exports.processOrder = exports.onOrderProcessing = void 0;
|
|
|
14
14
|
* 注文処理時処理
|
|
15
15
|
*/
|
|
16
16
|
const createDebug = require("debug");
|
|
17
|
-
const util = require("util");
|
|
18
17
|
const factory = require("../../../factory");
|
|
19
18
|
const settings_1 = require("../../../settings");
|
|
20
19
|
const createSendEmailMessageTaskIfNotExist_1 = require("./onOrderProcessing/createSendEmailMessageTaskIfNotExist");
|
|
21
20
|
const factory_1 = require("./onOrderProcessing/factory");
|
|
21
|
+
const processOrder_1 = require("./onOrderProcessing/processOrder");
|
|
22
|
+
Object.defineProperty(exports, "processOrder", { enumerable: true, get: function () { return processOrder_1.processOrder; } });
|
|
22
23
|
const debug = createDebug('chevre-domain:service:order');
|
|
23
24
|
function onOrderProcessing(params) {
|
|
24
25
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,20 +41,7 @@ function onOrderProcessing(params) {
|
|
|
40
41
|
yield repos.task.saveMany(tasks, { emitImmediately: true });
|
|
41
42
|
switch (params.order.orderStatus) {
|
|
42
43
|
case factory.orderStatus.OrderProcessing:
|
|
43
|
-
yield processOrder({ order: params.order, options: { force: false } })(repos);
|
|
44
|
-
// if (params.order.itemOfferedTypeOf === factory.actionType.MoneyTransfer) {
|
|
45
|
-
// await createConfirmMoneyTransferTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
46
|
-
// } else if (params.order.itemOfferedTypeOf === factory.reservationType.BusReservation
|
|
47
|
-
// || params.order.itemOfferedTypeOf === factory.reservationType.EventReservation) {
|
|
48
|
-
// // 冗長なconfirmReserveTransactionタスク作成を回避(2023-08-25~)
|
|
49
|
-
// await createConfirmReserveTransactionTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
50
|
-
// } else if (params.order.itemOfferedTypeOf === factory.permit.PermitType.Permit) {
|
|
51
|
-
// await createConfirmRegisterServiceTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
52
|
-
// }
|
|
53
|
-
// 完全廃止(2024-03-12~)
|
|
54
|
-
// await createGivePointAwardTaskIfNotExist({
|
|
55
|
-
// potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
|
|
56
|
-
// })(repos);
|
|
44
|
+
yield (0, processOrder_1.processOrder)({ order: params.order, options: { force: false } })(repos);
|
|
57
45
|
// OrderProcessingにおけるEメール送信に対応(2024-01-17~)
|
|
58
46
|
yield (0, createSendEmailMessageTaskIfNotExist_1.createSendEmailMessageTaskIfNotExist)({
|
|
59
47
|
sendEmailMessage: [
|
|
@@ -68,147 +56,3 @@ function onOrderProcessing(params) {
|
|
|
68
56
|
});
|
|
69
57
|
}
|
|
70
58
|
exports.onOrderProcessing = onOrderProcessing;
|
|
71
|
-
function processOrder(params) {
|
|
72
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const simpleOrder = {
|
|
74
|
-
typeOf: params.order.typeOf,
|
|
75
|
-
// seller: {
|
|
76
|
-
// id: params.order.seller.id,
|
|
77
|
-
// typeOf: params.order.seller.typeOf,
|
|
78
|
-
// name: params.order.seller.name
|
|
79
|
-
// }, // 廃止(2024-03-06~)
|
|
80
|
-
// customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
|
|
81
|
-
orderNumber: params.order.orderNumber,
|
|
82
|
-
// price: params.order.price,
|
|
83
|
-
// priceCurrency: params.order.priceCurrency,
|
|
84
|
-
orderDate: params.order.orderDate
|
|
85
|
-
};
|
|
86
|
-
if (params.order.itemOfferedTypeOf === factory.actionType.MoneyTransfer) {
|
|
87
|
-
yield createConfirmMoneyTransferTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
88
|
-
}
|
|
89
|
-
else if (params.order.itemOfferedTypeOf === factory.reservationType.BusReservation
|
|
90
|
-
|| params.order.itemOfferedTypeOf === factory.reservationType.EventReservation) {
|
|
91
|
-
// 冗長なconfirmReserveTransactionタスク作成を回避(2023-08-25~)
|
|
92
|
-
yield createConfirmReserveTransactionTasksIfNotExist(params.order, simpleOrder, params.options)(repos);
|
|
93
|
-
}
|
|
94
|
-
else if (params.order.itemOfferedTypeOf === factory.permit.PermitType.Permit) {
|
|
95
|
-
yield createConfirmRegisterServiceTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
exports.processOrder = processOrder;
|
|
100
|
-
function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder, options) {
|
|
101
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const taskRunsAt = new Date();
|
|
103
|
-
const taskRunsAt4coa = new Date();
|
|
104
|
-
let confirmObjects;
|
|
105
|
-
if (order.offeredThroughIdentifier === factory.service.webAPI.Identifier.COA) {
|
|
106
|
-
confirmObjects = (0, factory_1.createConfirmReservationActionObject4COAByOrder)({ order });
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
confirmObjects = (0, factory_1.createConfirmReservationActionObject4ChevreByOrder)({ order });
|
|
110
|
-
}
|
|
111
|
-
yield Promise.all(confirmObjects.map((confirmObject) => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const data = {
|
|
113
|
-
project: order.project,
|
|
114
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
115
|
-
object: confirmObject,
|
|
116
|
-
agent: order.project,
|
|
117
|
-
purpose: simpleOrder
|
|
118
|
-
// instrument廃止(2024-03-13~)
|
|
119
|
-
// instrument: {
|
|
120
|
-
// typeOf: 'WebAPI',
|
|
121
|
-
// identifier: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction)
|
|
122
|
-
// ? factory.service.webAPI.Identifier.COA
|
|
123
|
-
// : factory.service.webAPI.Identifier.Chevre
|
|
124
|
-
// }
|
|
125
|
-
};
|
|
126
|
-
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);
|
|
127
|
-
const confirmReserveTransactionTask = {
|
|
128
|
-
identifier: taskIdentifier,
|
|
129
|
-
project: order.project,
|
|
130
|
-
name: factory.taskName.ConfirmReserveTransaction,
|
|
131
|
-
status: factory.taskStatus.Ready,
|
|
132
|
-
runsAt: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction) ? taskRunsAt4coa : taskRunsAt,
|
|
133
|
-
remainingNumberOfTries: 10,
|
|
134
|
-
numberOfTried: 0,
|
|
135
|
-
executionResults: [],
|
|
136
|
-
data
|
|
137
|
-
};
|
|
138
|
-
yield repos.task.createIfNotExistByIdentifier(confirmReserveTransactionTask, { emitImmediately: true });
|
|
139
|
-
if (options.force === true) {
|
|
140
|
-
const existingTask = yield repos.task.findByIdentifier({
|
|
141
|
-
identifier: taskIdentifier,
|
|
142
|
-
name: confirmReserveTransactionTask.name,
|
|
143
|
-
project: { id: confirmReserveTransactionTask.project.id }
|
|
144
|
-
});
|
|
145
|
-
if (typeof (existingTask === null || existingTask === void 0 ? void 0 : existingTask.id) === 'string') {
|
|
146
|
-
const retryResult = yield repos.task.retryForciblyIfAborted({ id: existingTask.id, remainingNumberOfTries: 3 });
|
|
147
|
-
debug('retryResult:', retryResult, 'taskIdentifier:', taskIdentifier);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
})));
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function createConfirmMoneyTransferTasksIfNotExist(order, simpleOrder) {
|
|
154
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const taskRunsAt = new Date();
|
|
156
|
-
yield Promise.all(order.serialNumbers.map((moneyTransferTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const data = {
|
|
158
|
-
project: order.project,
|
|
159
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
160
|
-
object: {
|
|
161
|
-
// pendingTransaction: { id: '' }, // 空文字であれば、transactionNumberで処理される
|
|
162
|
-
transactionNumber: moneyTransferTransactionNumber,
|
|
163
|
-
typeOf: factory.assetTransactionType.MoneyTransfer
|
|
164
|
-
},
|
|
165
|
-
agent: order.project,
|
|
166
|
-
purpose: simpleOrder
|
|
167
|
-
};
|
|
168
|
-
const taskIdentifier = util.format('%s:%s:%s:%s:%s:%s', data.project.id, factory.taskName.ConfirmMoneyTransfer, data.purpose.typeOf, simpleOrder.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
169
|
-
const confirmMoneyTransferTransactionTask = {
|
|
170
|
-
identifier: taskIdentifier,
|
|
171
|
-
project: order.project,
|
|
172
|
-
name: factory.taskName.ConfirmMoneyTransfer,
|
|
173
|
-
status: factory.taskStatus.Ready,
|
|
174
|
-
runsAt: taskRunsAt,
|
|
175
|
-
remainingNumberOfTries: 10,
|
|
176
|
-
numberOfTried: 0,
|
|
177
|
-
executionResults: [],
|
|
178
|
-
data
|
|
179
|
-
};
|
|
180
|
-
yield repos.task.createIfNotExistByIdentifier(confirmMoneyTransferTransactionTask, { emitImmediately: true });
|
|
181
|
-
})));
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function createConfirmRegisterServiceTasksIfNotExist(order, simpleOrder) {
|
|
185
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
const taskRunsAt = new Date();
|
|
187
|
-
yield Promise.all(order.serialNumbers.map((registerServiceTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const data = {
|
|
189
|
-
project: order.project,
|
|
190
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
191
|
-
object: {
|
|
192
|
-
endDate: order.orderDate,
|
|
193
|
-
transactionNumber: registerServiceTransactionNumber,
|
|
194
|
-
typeOf: factory.assetTransactionType.RegisterService
|
|
195
|
-
},
|
|
196
|
-
agent: order.project,
|
|
197
|
-
purpose: simpleOrder
|
|
198
|
-
};
|
|
199
|
-
const taskIdentifier = util.format('%s:%s:%s:%s:%s:%s', data.project.id, factory.taskName.ConfirmRegisterService, data.purpose.typeOf, simpleOrder.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
200
|
-
const confirmRegisterServiceTask = {
|
|
201
|
-
identifier: taskIdentifier,
|
|
202
|
-
project: order.project,
|
|
203
|
-
name: factory.taskName.ConfirmRegisterService,
|
|
204
|
-
status: factory.taskStatus.Ready,
|
|
205
|
-
runsAt: taskRunsAt,
|
|
206
|
-
remainingNumberOfTries: 10,
|
|
207
|
-
numberOfTried: 0,
|
|
208
|
-
executionResults: [],
|
|
209
|
-
data
|
|
210
|
-
};
|
|
211
|
-
yield repos.task.createIfNotExistByIdentifier(confirmRegisterServiceTask, { emitImmediately: true });
|
|
212
|
-
})));
|
|
213
|
-
});
|
|
214
|
-
}
|
package/package.json
CHANGED