@chevre/domain 21.37.0-alpha.12 → 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 +87 -0
- package/lib/chevre/repo/task.d.ts +9 -0
- package/lib/chevre/repo/task.js +23 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +4 -4
- 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 +4 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -135
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
13
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
14
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
15
|
+
|
|
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();
|
|
41
|
+
if (order.orderStatus !== chevre.factory.orderStatus.OrderProcessing) {
|
|
42
|
+
console.log('nothing to do', order.orderStatus, order.orderNumber);
|
|
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);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log(i, 'orders checked');
|
|
76
|
+
console.log(updateCount, 'orders updated');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main()
|
|
80
|
+
.then()
|
|
81
|
+
.catch(console.error);
|
|
82
|
+
|
|
83
|
+
main()
|
|
84
|
+
.then(() => {
|
|
85
|
+
console.log('success!');
|
|
86
|
+
})
|
|
87
|
+
.catch(console.error);
|
|
@@ -75,6 +75,7 @@ export declare class MongoRepository {
|
|
|
75
75
|
};
|
|
76
76
|
}): Promise<{
|
|
77
77
|
id: string;
|
|
78
|
+
status: factory.taskStatus;
|
|
78
79
|
} | undefined>;
|
|
79
80
|
/**
|
|
80
81
|
* タスク識別子から冪等作成する
|
|
@@ -127,6 +128,14 @@ export declare class MongoRepository {
|
|
|
127
128
|
retry(params: {
|
|
128
129
|
intervalInMinutes: number;
|
|
129
130
|
}): Promise<UpdateWriteOpResult>;
|
|
131
|
+
/**
|
|
132
|
+
* 実行中止済タスクを強制的にリトライ
|
|
133
|
+
* 中止済タスクでなければ何もしない
|
|
134
|
+
*/
|
|
135
|
+
retryForciblyIfAborted(params: {
|
|
136
|
+
id: string;
|
|
137
|
+
remainingNumberOfTries: number;
|
|
138
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
130
139
|
abortOne(params: {
|
|
131
140
|
intervalInMinutes: number;
|
|
132
141
|
}): Promise<factory.task.ITask<factory.taskName> | null>;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -201,12 +201,13 @@ class MongoRepository {
|
|
|
201
201
|
'project.id': { $eq: params.project.id },
|
|
202
202
|
name: { $eq: params.name },
|
|
203
203
|
identifier: { $exists: true, $eq: params.identifier }
|
|
204
|
-
}, { _id: 1 })
|
|
204
|
+
}, { _id: 1, status: 1 })
|
|
205
205
|
.exec();
|
|
206
206
|
if (doc === null) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
const { id, status } = doc.toObject();
|
|
210
|
+
return { id, status };
|
|
210
211
|
});
|
|
211
212
|
}
|
|
212
213
|
/**
|
|
@@ -514,6 +515,26 @@ class MongoRepository {
|
|
|
514
515
|
.exec();
|
|
515
516
|
});
|
|
516
517
|
}
|
|
518
|
+
/**
|
|
519
|
+
* 実行中止済タスクを強制的にリトライ
|
|
520
|
+
* 中止済タスクでなければ何もしない
|
|
521
|
+
*/
|
|
522
|
+
retryForciblyIfAborted(params) {
|
|
523
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
return this.taskModel.updateOne({
|
|
525
|
+
_id: { $eq: params.id },
|
|
526
|
+
status: { $eq: factory.taskStatus.Aborted }
|
|
527
|
+
}, {
|
|
528
|
+
$set: {
|
|
529
|
+
status: factory.taskStatus.Ready
|
|
530
|
+
},
|
|
531
|
+
$inc: {
|
|
532
|
+
remainingNumberOfTries: params.remainingNumberOfTries
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
.exec();
|
|
536
|
+
});
|
|
537
|
+
}
|
|
517
538
|
abortOne(params) {
|
|
518
539
|
return __awaiter(this, void 0, void 0, function* () {
|
|
519
540
|
const lastTriedAtShoudBeLessThan = moment()
|
|
@@ -5,15 +5,15 @@ type IProcessingOrder = factory.order.IOrder & {
|
|
|
5
5
|
};
|
|
6
6
|
declare function createInformTasks(order: IProcessingOrder): factory.task.IAttributes<factory.taskName.TriggerWebhook>[];
|
|
7
7
|
declare function createConfirmReservationActionObject4ChevreByOrder(params: {
|
|
8
|
-
order: factory.order.IOrder & {
|
|
8
|
+
order: Pick<factory.order.IOrder, 'confirmationNumber' | 'orderNumber'> & {
|
|
9
9
|
serialNumbers: string[];
|
|
10
10
|
};
|
|
11
11
|
}): factory.action.interact.confirm.reservation.IObject<factory.service.webAPI.Identifier.Chevre>[];
|
|
12
12
|
declare function createConfirmReservationActionObject4COAByOrder(params: {
|
|
13
|
-
order:
|
|
13
|
+
order: {
|
|
14
14
|
serialNumbers: string[];
|
|
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,4 +13,4 @@ declare function onOrderProcessing(params: {
|
|
|
14
13
|
}): (repos: {
|
|
15
14
|
task: TaskRepo;
|
|
16
15
|
}) => Promise<void>;
|
|
17
|
-
export { IExternalOrder, onOrderProcessing };
|
|
16
|
+
export { IExternalOrder, onOrderProcessing, processOrder };
|
|
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.onOrderProcessing = void 0;
|
|
12
|
+
exports.processOrder = exports.onOrderProcessing = void 0;
|
|
13
13
|
/**
|
|
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* () {
|
|
@@ -27,20 +28,6 @@ function onOrderProcessing(params) {
|
|
|
27
28
|
let tasks = [];
|
|
28
29
|
const sendEmailMessageByOrderPotentialActions = (_f = (_e = (_d = (_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) === null || _d === void 0 ? void 0 : _d.sendOrder) === null || _e === void 0 ? void 0 : _e.potentialActions) === null || _f === void 0 ? void 0 : _f.sendEmailMessage;
|
|
29
30
|
const sendEmailMessageByOnOrderProcessing = (_k = (_j = (_h = (_g = params.placeOrderTransaction) === null || _g === void 0 ? void 0 : _g.potentialActions) === null || _h === void 0 ? void 0 : _h.order) === null || _j === void 0 ? void 0 : _j.onOrderProcessing) === null || _k === void 0 ? void 0 : _k.sendEmailMessage;
|
|
30
|
-
// const maskedCustomer = createMaskedCustomer(params.order, { noProfile: true });
|
|
31
|
-
const simpleOrder = {
|
|
32
|
-
typeOf: params.order.typeOf,
|
|
33
|
-
// seller: {
|
|
34
|
-
// id: params.order.seller.id,
|
|
35
|
-
// typeOf: params.order.seller.typeOf,
|
|
36
|
-
// name: params.order.seller.name
|
|
37
|
-
// }, // 廃止(2024-03-06~)
|
|
38
|
-
// customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
|
|
39
|
-
orderNumber: params.order.orderNumber,
|
|
40
|
-
// price: params.order.price,
|
|
41
|
-
// priceCurrency: params.order.priceCurrency,
|
|
42
|
-
orderDate: params.order.orderDate
|
|
43
|
-
};
|
|
44
31
|
switch (params.order.orderStatus) {
|
|
45
32
|
case factory.orderStatus.OrderProcessing:
|
|
46
33
|
tasks = [
|
|
@@ -54,21 +41,7 @@ function onOrderProcessing(params) {
|
|
|
54
41
|
yield repos.task.saveMany(tasks, { emitImmediately: true });
|
|
55
42
|
switch (params.order.orderStatus) {
|
|
56
43
|
case factory.orderStatus.OrderProcessing:
|
|
57
|
-
|
|
58
|
-
yield createConfirmMoneyTransferTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
59
|
-
}
|
|
60
|
-
else if (params.order.itemOfferedTypeOf === factory.reservationType.BusReservation
|
|
61
|
-
|| params.order.itemOfferedTypeOf === factory.reservationType.EventReservation) {
|
|
62
|
-
// 冗長なconfirmReserveTransactionタスク作成を回避(2023-08-25~)
|
|
63
|
-
yield createConfirmReserveTransactionTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
64
|
-
}
|
|
65
|
-
else if (params.order.itemOfferedTypeOf === factory.permit.PermitType.Permit) {
|
|
66
|
-
yield createConfirmRegisterServiceTasksIfNotExist(params.order, simpleOrder)(repos);
|
|
67
|
-
}
|
|
68
|
-
// 完全廃止(2024-03-12~)
|
|
69
|
-
// await createGivePointAwardTaskIfNotExist({
|
|
70
|
-
// potentialActions: params.placeOrderTransaction?.potentialActions?.order?.potentialActions
|
|
71
|
-
// })(repos);
|
|
44
|
+
yield (0, processOrder_1.processOrder)({ order: params.order, options: { force: false } })(repos);
|
|
72
45
|
// OrderProcessingにおけるEメール送信に対応(2024-01-17~)
|
|
73
46
|
yield (0, createSendEmailMessageTaskIfNotExist_1.createSendEmailMessageTaskIfNotExist)({
|
|
74
47
|
sendEmailMessage: [
|
|
@@ -83,107 +56,3 @@ function onOrderProcessing(params) {
|
|
|
83
56
|
});
|
|
84
57
|
}
|
|
85
58
|
exports.onOrderProcessing = onOrderProcessing;
|
|
86
|
-
function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder) {
|
|
87
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const taskRunsAt = new Date();
|
|
89
|
-
const taskRunsAt4coa = new Date();
|
|
90
|
-
let confirmObjects;
|
|
91
|
-
if (order.offeredThroughIdentifier === factory.service.webAPI.Identifier.COA) {
|
|
92
|
-
confirmObjects = (0, factory_1.createConfirmReservationActionObject4COAByOrder)({ order });
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
confirmObjects = (0, factory_1.createConfirmReservationActionObject4ChevreByOrder)({ order });
|
|
96
|
-
}
|
|
97
|
-
yield Promise.all(confirmObjects.map((confirmObject) => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const data = {
|
|
99
|
-
project: order.project,
|
|
100
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
101
|
-
object: confirmObject,
|
|
102
|
-
agent: order.project,
|
|
103
|
-
purpose: simpleOrder
|
|
104
|
-
// instrument廃止(2024-03-13~)
|
|
105
|
-
// instrument: {
|
|
106
|
-
// typeOf: 'WebAPI',
|
|
107
|
-
// identifier: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction)
|
|
108
|
-
// ? factory.service.webAPI.Identifier.COA
|
|
109
|
-
// : factory.service.webAPI.Identifier.Chevre
|
|
110
|
-
// }
|
|
111
|
-
};
|
|
112
|
-
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);
|
|
113
|
-
const confirmReserveTransactionTask = {
|
|
114
|
-
identifier: taskIdentifier,
|
|
115
|
-
project: order.project,
|
|
116
|
-
name: factory.taskName.ConfirmReserveTransaction,
|
|
117
|
-
status: factory.taskStatus.Ready,
|
|
118
|
-
runsAt: (confirmObject.typeOf === factory.assetTransactionType.COAReserveTransaction) ? taskRunsAt4coa : taskRunsAt,
|
|
119
|
-
remainingNumberOfTries: 10,
|
|
120
|
-
numberOfTried: 0,
|
|
121
|
-
executionResults: [],
|
|
122
|
-
data
|
|
123
|
-
};
|
|
124
|
-
yield repos.task.createIfNotExistByIdentifier(confirmReserveTransactionTask, { emitImmediately: true });
|
|
125
|
-
})));
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function createConfirmMoneyTransferTasksIfNotExist(order, simpleOrder) {
|
|
129
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const taskRunsAt = new Date();
|
|
131
|
-
yield Promise.all(order.serialNumbers.map((moneyTransferTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
const data = {
|
|
133
|
-
project: order.project,
|
|
134
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
135
|
-
object: {
|
|
136
|
-
// pendingTransaction: { id: '' }, // 空文字であれば、transactionNumberで処理される
|
|
137
|
-
transactionNumber: moneyTransferTransactionNumber,
|
|
138
|
-
typeOf: factory.assetTransactionType.MoneyTransfer
|
|
139
|
-
},
|
|
140
|
-
agent: order.project,
|
|
141
|
-
purpose: simpleOrder
|
|
142
|
-
};
|
|
143
|
-
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);
|
|
144
|
-
const confirmMoneyTransferTransactionTask = {
|
|
145
|
-
identifier: taskIdentifier,
|
|
146
|
-
project: order.project,
|
|
147
|
-
name: factory.taskName.ConfirmMoneyTransfer,
|
|
148
|
-
status: factory.taskStatus.Ready,
|
|
149
|
-
runsAt: taskRunsAt,
|
|
150
|
-
remainingNumberOfTries: 10,
|
|
151
|
-
numberOfTried: 0,
|
|
152
|
-
executionResults: [],
|
|
153
|
-
data
|
|
154
|
-
};
|
|
155
|
-
yield repos.task.createIfNotExistByIdentifier(confirmMoneyTransferTransactionTask, { emitImmediately: true });
|
|
156
|
-
})));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function createConfirmRegisterServiceTasksIfNotExist(order, simpleOrder) {
|
|
160
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const taskRunsAt = new Date();
|
|
162
|
-
yield Promise.all(order.serialNumbers.map((registerServiceTransactionNumber) => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
const data = {
|
|
164
|
-
project: order.project,
|
|
165
|
-
typeOf: factory.actionType.ConfirmAction,
|
|
166
|
-
object: {
|
|
167
|
-
endDate: order.orderDate,
|
|
168
|
-
transactionNumber: registerServiceTransactionNumber,
|
|
169
|
-
typeOf: factory.assetTransactionType.RegisterService
|
|
170
|
-
},
|
|
171
|
-
agent: order.project,
|
|
172
|
-
purpose: simpleOrder
|
|
173
|
-
};
|
|
174
|
-
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);
|
|
175
|
-
const confirmRegisterServiceTask = {
|
|
176
|
-
identifier: taskIdentifier,
|
|
177
|
-
project: order.project,
|
|
178
|
-
name: factory.taskName.ConfirmRegisterService,
|
|
179
|
-
status: factory.taskStatus.Ready,
|
|
180
|
-
runsAt: taskRunsAt,
|
|
181
|
-
remainingNumberOfTries: 10,
|
|
182
|
-
numberOfTried: 0,
|
|
183
|
-
executionResults: [],
|
|
184
|
-
data
|
|
185
|
-
};
|
|
186
|
-
yield repos.task.createIfNotExistByIdentifier(confirmRegisterServiceTask, { emitImmediately: true });
|
|
187
|
-
})));
|
|
188
|
-
});
|
|
189
|
-
}
|
|
@@ -6,6 +6,6 @@ import { onOrderDelivered } from './onOrderStatusChanged/onOrderDelivered';
|
|
|
6
6
|
import { onOrderDeliveredPartially } from './onOrderStatusChanged/onOrderDeliveredPartially';
|
|
7
7
|
import { onOrderInTransit } from './onOrderStatusChanged/onOrderInTransit';
|
|
8
8
|
import { onOrderPaymentDue } from './onOrderStatusChanged/onOrderPaymentDue';
|
|
9
|
-
import { IExternalOrder, onOrderProcessing } from './onOrderStatusChanged/onOrderProcessing';
|
|
9
|
+
import { IExternalOrder, onOrderProcessing, processOrder } from './onOrderStatusChanged/onOrderProcessing';
|
|
10
10
|
import { onOrderReturned } from './onOrderStatusChanged/onOrderReturned';
|
|
11
|
-
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderDeliveredPartially, onOrderInTransit, onOrderPaymentDue, onOrderProcessing, onOrderReturned };
|
|
11
|
+
export { IExternalOrder, onOrderCancelled, onOrderDelivered, onOrderDeliveredPartially, onOrderInTransit, onOrderPaymentDue, onOrderProcessing, onOrderReturned, processOrder };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderInTransit = exports.onOrderDeliveredPartially = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
3
|
+
exports.processOrder = exports.onOrderReturned = exports.onOrderProcessing = exports.onOrderPaymentDue = exports.onOrderInTransit = exports.onOrderDeliveredPartially = exports.onOrderDelivered = exports.onOrderCancelled = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文ステータス変更時処理
|
|
6
6
|
*/
|
|
@@ -16,5 +16,6 @@ const onOrderPaymentDue_1 = require("./onOrderStatusChanged/onOrderPaymentDue");
|
|
|
16
16
|
Object.defineProperty(exports, "onOrderPaymentDue", { enumerable: true, get: function () { return onOrderPaymentDue_1.onOrderPaymentDue; } });
|
|
17
17
|
const onOrderProcessing_1 = require("./onOrderStatusChanged/onOrderProcessing");
|
|
18
18
|
Object.defineProperty(exports, "onOrderProcessing", { enumerable: true, get: function () { return onOrderProcessing_1.onOrderProcessing; } });
|
|
19
|
+
Object.defineProperty(exports, "processOrder", { enumerable: true, get: function () { return onOrderProcessing_1.processOrder; } });
|
|
19
20
|
const onOrderReturned_1 = require("./onOrderStatusChanged/onOrderReturned");
|
|
20
21
|
Object.defineProperty(exports, "onOrderReturned", { enumerable: true, get: function () { return onOrderReturned_1.onOrderReturned; } });
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import { confirmPayTransaction } from './order/confirmPayTransaction';
|
|
5
5
|
import { deleteOrder } from './order/deleteOrder';
|
|
6
6
|
import { onAssetTransactionStatusChanged, paymentDue2Processing } from './order/onAssetTransactionStatusChanged';
|
|
7
|
-
import { onOrderProcessing } from './order/onOrderStatusChanged';
|
|
7
|
+
import { onOrderProcessing, processOrder } from './order/onOrderStatusChanged';
|
|
8
8
|
import { onOrderUpdated } from './order/onOrderUpdated';
|
|
9
9
|
import { payOrder } from './order/payOrder';
|
|
10
10
|
import { placeOrder } from './order/placeOrder';
|
|
11
11
|
import { placeOrderWithoutTransaction } from './order/placeOrderWithoutTransaction';
|
|
12
12
|
import { sendOrder } from './order/sendOrder';
|
|
13
|
-
export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderProcessing, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
|
|
13
|
+
export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderProcessing, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, processOrder, sendOrder };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.paymentDue2Processing = exports.onOrderUpdated = exports.onOrderProcessing = exports.onAssetTransactionStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
|
|
3
|
+
exports.sendOrder = exports.processOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.paymentDue2Processing = exports.onOrderUpdated = exports.onOrderProcessing = exports.onAssetTransactionStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文サービス
|
|
6
6
|
*/
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "onAssetTransactionStatusChanged", { enumerable:
|
|
|
13
13
|
Object.defineProperty(exports, "paymentDue2Processing", { enumerable: true, get: function () { return onAssetTransactionStatusChanged_1.paymentDue2Processing; } });
|
|
14
14
|
const onOrderStatusChanged_1 = require("./order/onOrderStatusChanged");
|
|
15
15
|
Object.defineProperty(exports, "onOrderProcessing", { enumerable: true, get: function () { return onOrderStatusChanged_1.onOrderProcessing; } });
|
|
16
|
+
Object.defineProperty(exports, "processOrder", { enumerable: true, get: function () { return onOrderStatusChanged_1.processOrder; } });
|
|
16
17
|
const onOrderUpdated_1 = require("./order/onOrderUpdated");
|
|
17
18
|
Object.defineProperty(exports, "onOrderUpdated", { enumerable: true, get: function () { return onOrderUpdated_1.onOrderUpdated; } });
|
|
18
19
|
const payOrder_1 = require("./order/payOrder");
|
package/package.json
CHANGED