@chevre/domain 21.8.0-alpha.2 → 21.8.0-alpha.3
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/searchTasks.ts +31 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +6 -0
- package/lib/chevre/repo/task.d.ts +1 -0
- package/lib/chevre/repo/task.js +21 -0
- package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -3
- package/lib/chevre/service/order/onOrderStatusChanged/factory.js +25 -86
- package/lib/chevre/service/order/onOrderStatusChanged.js +35 -1
- package/lib/chevre/service/order/placeOrder.js +13 -10
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
|
|
10
|
+
|
|
11
|
+
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const tasks = await taskRepo.taskModel.find(
|
|
14
|
+
{
|
|
15
|
+
'project.id': { $eq: project.id },
|
|
16
|
+
name: { $eq: chevre.factory.taskName.SendOrder },
|
|
17
|
+
'data.object.orderNumber': {
|
|
18
|
+
$exists: true,
|
|
19
|
+
$eq: 'xxx'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
.limit(1)
|
|
24
|
+
.exec();
|
|
25
|
+
console.log('tasks found', tasks);
|
|
26
|
+
console.log(tasks.length, 'tasks found');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
main()
|
|
30
|
+
.then()
|
|
31
|
+
.catch(console.error);
|
|
@@ -83,6 +83,12 @@ schema.index({ 'data.object.itemOffered.membershipFor.id': 1, runsAt: -1 }, {
|
|
|
83
83
|
'data.object.itemOffered.membershipFor.id': { $exists: true }
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
|
+
schema.index({ 'data.object.orderNumber': 1, runsAt: -1 }, {
|
|
87
|
+
name: 'searchByDataObjectOrderNumber',
|
|
88
|
+
partialFilterExpression: {
|
|
89
|
+
'data.object.orderNumber': { $exists: true }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
86
92
|
schema.index({ 'data.object.transactionNumber': 1, runsAt: -1 }, {
|
|
87
93
|
name: 'searchByDataObjectTransactionNumber',
|
|
88
94
|
partialFilterExpression: {
|
|
@@ -35,6 +35,7 @@ export declare class MongoRepository {
|
|
|
35
35
|
* 取引削除タスク冪等作成
|
|
36
36
|
*/
|
|
37
37
|
createDeleteTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.DeleteTransaction>, options: IOptionOnCreate): Promise<void>;
|
|
38
|
+
createSendOrderTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.SendOrder>, options: IOptionOnCreate): Promise<void>;
|
|
38
39
|
executeById(params: {
|
|
39
40
|
id: string;
|
|
40
41
|
executor: {
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -230,6 +230,27 @@ class MongoRepository {
|
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
|
+
createSendOrderTaskIfNotExist(params, options) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
const createdTask = yield this.taskModel.findOneAndUpdate({
|
|
236
|
+
'project.id': { $eq: params.project.id },
|
|
237
|
+
name: { $eq: params.name },
|
|
238
|
+
'data.object.orderNumber': {
|
|
239
|
+
$exists: true,
|
|
240
|
+
$eq: String(params.data.object.orderNumber)
|
|
241
|
+
}
|
|
242
|
+
}, { $setOnInsert: params }, { new: true, upsert: true })
|
|
243
|
+
.select({ _id: 1 })
|
|
244
|
+
.exec();
|
|
245
|
+
if (options.emitImmediately) {
|
|
246
|
+
task_2.taskEventEmitter.emitTaskStatusChanged({
|
|
247
|
+
id: createdTask.id,
|
|
248
|
+
name: params.name,
|
|
249
|
+
status: factory.taskStatus.Ready
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
233
254
|
executeById(params) {
|
|
234
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
235
256
|
const doc = yield this.taskModel.findOneAndUpdate({
|
|
@@ -21,9 +21,6 @@ export declare function createConfirmRegisterServiceActionObjectByOrder(params:
|
|
|
21
21
|
order: factory.order.IOrder;
|
|
22
22
|
}): factory.action.interact.confirm.registerService.IObject[];
|
|
23
23
|
export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
|
|
24
|
-
/**
|
|
25
|
-
* 注文作成後のアクション
|
|
26
|
-
*/
|
|
27
24
|
export declare function createOnPlaceOrderTasksByTransaction(params: {
|
|
28
25
|
object: factory.order.IOrder | IExternalOrder;
|
|
29
26
|
potentialActions?: factory.action.trade.order.IPotentialActions;
|
|
@@ -262,71 +262,6 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
|
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
|
|
265
|
-
/**
|
|
266
|
-
* 注文作成後のアクション
|
|
267
|
-
*/
|
|
268
|
-
// export function onPlaceOrder(params: {
|
|
269
|
-
// object: factory.order.IOrder | IExternalOrder;
|
|
270
|
-
// potentialActions?: factory.action.trade.order.IPotentialActions;
|
|
271
|
-
// }) {
|
|
272
|
-
// return async (repos: {
|
|
273
|
-
// task: TaskRepo;
|
|
274
|
-
// }) => {
|
|
275
|
-
// const potentialActions = params.potentialActions;
|
|
276
|
-
// const now = new Date();
|
|
277
|
-
// // potentialActionsのためのタスクを生成
|
|
278
|
-
// const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
|
|
279
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
280
|
-
// /* istanbul ignore else */
|
|
281
|
-
// if (potentialActions !== undefined) {
|
|
282
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
283
|
-
// /* istanbul ignore else */
|
|
284
|
-
// if (potentialActions.sendOrder !== undefined) {
|
|
285
|
-
// const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
|
|
286
|
-
// project: potentialActions.sendOrder.project,
|
|
287
|
-
// name: factory.taskName.SendOrder,
|
|
288
|
-
// status: factory.taskStatus.Ready,
|
|
289
|
-
// runsAt: now, // なるはやで実行
|
|
290
|
-
// remainingNumberOfTries: 10,
|
|
291
|
-
// numberOfTried: 0,
|
|
292
|
-
// executionResults: [],
|
|
293
|
-
// // data: potentialActions.sendOrder
|
|
294
|
-
// data: {
|
|
295
|
-
// project: potentialActions.sendOrder.project,
|
|
296
|
-
// object: {
|
|
297
|
-
// ...potentialActions.sendOrder.object,
|
|
298
|
-
// confirmationNumber: params.object.confirmationNumber
|
|
299
|
-
// },
|
|
300
|
-
// ...(potentialActions.sendOrder.potentialActions !== undefined)
|
|
301
|
-
// ? { potentialActions: potentialActions.sendOrder.potentialActions }
|
|
302
|
-
// : undefined
|
|
303
|
-
// }
|
|
304
|
-
// };
|
|
305
|
-
// taskAttributes.push(sendOrderTask);
|
|
306
|
-
// }
|
|
307
|
-
// // ポイント付与
|
|
308
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
309
|
-
// /* istanbul ignore else */
|
|
310
|
-
// if (Array.isArray(potentialActions.givePointAward)) {
|
|
311
|
-
// taskAttributes.push(...potentialActions.givePointAward.map(
|
|
312
|
-
// (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
|
|
313
|
-
// return {
|
|
314
|
-
// project: a.project,
|
|
315
|
-
// name: factory.taskName.GivePointAward,
|
|
316
|
-
// status: factory.taskStatus.Ready,
|
|
317
|
-
// runsAt: now, // なるはやで実行
|
|
318
|
-
// remainingNumberOfTries: 10,
|
|
319
|
-
// numberOfTried: 0,
|
|
320
|
-
// executionResults: [],
|
|
321
|
-
// data: a
|
|
322
|
-
// };
|
|
323
|
-
// }));
|
|
324
|
-
// }
|
|
325
|
-
// }
|
|
326
|
-
// // タスク保管
|
|
327
|
-
// await repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
328
|
-
// };
|
|
329
|
-
// }
|
|
330
265
|
function createOnPlaceOrderTasksByTransaction(params) {
|
|
331
266
|
const potentialActions = params.potentialActions;
|
|
332
267
|
const now = new Date();
|
|
@@ -335,29 +270,33 @@ function createOnPlaceOrderTasksByTransaction(params) {
|
|
|
335
270
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
336
271
|
/* istanbul ignore else */
|
|
337
272
|
if (potentialActions !== undefined) {
|
|
273
|
+
// 冗長なsendOrderタスク作成を回避(createSendOrderTransactionTaskIfNotExistへ移行)(2023-08-24~)
|
|
338
274
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
339
275
|
/* istanbul ignore else */
|
|
340
|
-
if (potentialActions.sendOrder !== undefined) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
276
|
+
// if (potentialActions.sendOrder !== undefined) {
|
|
277
|
+
// const sendOrderTaskData: factory.task.IData<factory.taskName.SendOrder> = {
|
|
278
|
+
// project: potentialActions.sendOrder.project,
|
|
279
|
+
// object: {
|
|
280
|
+
// ...potentialActions.sendOrder.object,
|
|
281
|
+
// confirmationNumber: params.object.confirmationNumber
|
|
282
|
+
// }
|
|
283
|
+
// // 廃止(2023-08-21~)
|
|
284
|
+
// // ...(potentialActions.sendOrder.potentialActions !== undefined)
|
|
285
|
+
// // ? { potentialActions: potentialActions.sendOrder.potentialActions }
|
|
286
|
+
// // : undefined
|
|
287
|
+
// };
|
|
288
|
+
// const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
|
|
289
|
+
// project: potentialActions.sendOrder.project,
|
|
290
|
+
// name: factory.taskName.SendOrder,
|
|
291
|
+
// status: factory.taskStatus.Ready,
|
|
292
|
+
// runsAt: now, // なるはやで実行
|
|
293
|
+
// remainingNumberOfTries: 10,
|
|
294
|
+
// numberOfTried: 0,
|
|
295
|
+
// executionResults: [],
|
|
296
|
+
// data: sendOrderTaskData
|
|
297
|
+
// };
|
|
298
|
+
// taskAttributes.push(sendOrderTask);
|
|
299
|
+
// }
|
|
361
300
|
// ポイント付与
|
|
362
301
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
363
302
|
/* istanbul ignore else */
|
|
@@ -24,7 +24,7 @@ const TOKEN_EXPIRES_IN = 604800;
|
|
|
24
24
|
function onOrderStatusChanged(params) {
|
|
25
25
|
// tslint:disable-next-line:max-func-body-length
|
|
26
26
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
28
28
|
let tasks = [];
|
|
29
29
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
|
|
30
30
|
const simpleOrder = {
|
|
@@ -115,6 +115,16 @@ function onOrderStatusChanged(params) {
|
|
|
115
115
|
default:
|
|
116
116
|
}
|
|
117
117
|
yield repos.task.saveMany(tasks, { emitImmediately: true });
|
|
118
|
+
switch (params.order.orderStatus) {
|
|
119
|
+
case factory.orderStatus.OrderProcessing:
|
|
120
|
+
// 冗長なsendOrderタスク作成を回避(2023-08-24~)
|
|
121
|
+
yield createSendOrderTransactionTaskIfNotExist({
|
|
122
|
+
object: params.order,
|
|
123
|
+
potentialActions: (_q = (_p = (_o = params.placeOrderTransaction) === null || _o === void 0 ? void 0 : _o.potentialActions) === null || _p === void 0 ? void 0 : _p.order) === null || _q === void 0 ? void 0 : _q.potentialActions
|
|
124
|
+
})(repos);
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
}
|
|
118
128
|
});
|
|
119
129
|
}
|
|
120
130
|
exports.onOrderStatusChanged = onOrderStatusChanged;
|
|
@@ -285,6 +295,30 @@ function createConfirmRegisterServiceTransactionTasks(order, simpleOrder) {
|
|
|
285
295
|
}
|
|
286
296
|
});
|
|
287
297
|
}
|
|
298
|
+
function createSendOrderTransactionTaskIfNotExist(params) {
|
|
299
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
var _a;
|
|
301
|
+
const now = new Date();
|
|
302
|
+
const sendOrderByTransaction = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.sendOrder;
|
|
303
|
+
if (sendOrderByTransaction !== undefined) {
|
|
304
|
+
const sendOrderTaskData = {
|
|
305
|
+
project: sendOrderByTransaction.project,
|
|
306
|
+
object: Object.assign(Object.assign({}, sendOrderByTransaction.object), { confirmationNumber: params.object.confirmationNumber })
|
|
307
|
+
};
|
|
308
|
+
const sendOrderTask = {
|
|
309
|
+
project: sendOrderByTransaction.project,
|
|
310
|
+
name: factory.taskName.SendOrder,
|
|
311
|
+
status: factory.taskStatus.Ready,
|
|
312
|
+
runsAt: now,
|
|
313
|
+
remainingNumberOfTries: 10,
|
|
314
|
+
numberOfTried: 0,
|
|
315
|
+
executionResults: [],
|
|
316
|
+
data: sendOrderTaskData
|
|
317
|
+
};
|
|
318
|
+
yield repos.task.createSendOrderTaskIfNotExist(sendOrderTask, { emitImmediately: true });
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
288
322
|
const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
|
|
289
323
|
function createReturnReserveTransactionTasks(order, simpleOrder) {
|
|
290
324
|
var _a, _b;
|
|
@@ -232,6 +232,7 @@ function placeOrder(params) {
|
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
234
|
else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
|
|
235
|
+
// OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
|
|
235
236
|
// OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
|
|
236
237
|
yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
|
|
237
238
|
order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderPaymentDue }),
|
|
@@ -240,16 +241,18 @@ function placeOrder(params) {
|
|
|
240
241
|
registerActionInProgress: repos.registerActionInProgress,
|
|
241
242
|
task: repos.task
|
|
242
243
|
});
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
244
|
+
// paymentMethods.length: 0の場合を考慮(2023-08-24~)
|
|
245
|
+
if (order.paymentMethods.length === 0) {
|
|
246
|
+
// paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpayOrderを実行する必要がある
|
|
247
|
+
yield (0, payOrder_1.payOrder)({
|
|
248
|
+
project: { id: order.project.id },
|
|
249
|
+
object: {
|
|
250
|
+
confirmationNumber: order.confirmationNumber,
|
|
251
|
+
orderNumber: order.orderNumber
|
|
252
|
+
},
|
|
253
|
+
useOnOrderStatusChanged: params.useOnOrderStatusChanged
|
|
254
|
+
})(repos);
|
|
255
|
+
}
|
|
253
256
|
}
|
|
254
257
|
else {
|
|
255
258
|
throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
|
package/package.json
CHANGED