@chevre/domain 21.8.0-alpha.1 → 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/confirmPayTransaction.d.ts +26 -0
- package/lib/chevre/service/order/confirmPayTransaction.js +109 -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.d.ts +3 -1
- package/lib/chevre/service/order/placeOrder.js +24 -8
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +4 -3
- package/lib/chevre/service/task/confirmPayTransaction.js +13 -101
- package/lib/chevre/service/task/returnOrder.js +2 -2
- 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({
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as factory from '../../factory';
|
|
2
|
+
import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
|
|
3
|
+
import { MongoRepository as ActionRepo } from '../../repo/action';
|
|
4
|
+
import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
|
|
5
|
+
import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
6
|
+
import { MongoRepository as EventRepo } from '../../repo/event';
|
|
7
|
+
import { MongoRepository as OrderRepo } from '../../repo/order';
|
|
8
|
+
import { MongoRepository as ProductRepo } from '../../repo/product';
|
|
9
|
+
import { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
10
|
+
import { MongoRepository as SellerRepo } from '../../repo/seller';
|
|
11
|
+
import { MongoRepository as TaskRepo } from '../../repo/task';
|
|
12
|
+
import { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
13
|
+
declare function confirmPayTransaction(data: factory.task.IData<factory.taskName.ConfirmPayTransaction>): (repos: {
|
|
14
|
+
action: ActionRepo;
|
|
15
|
+
assetTransaction: AssetTransactionRepo;
|
|
16
|
+
order: OrderRepo;
|
|
17
|
+
accountingReport: AccountingReportRepo;
|
|
18
|
+
event: EventRepo;
|
|
19
|
+
product: ProductRepo;
|
|
20
|
+
project: ProjectRepo;
|
|
21
|
+
seller: SellerRepo;
|
|
22
|
+
task: TaskRepo;
|
|
23
|
+
transaction: TransactionRepo;
|
|
24
|
+
registerServiceInProgress: RegisterServiceInProgressRepo;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
export { confirmPayTransaction };
|
|
@@ -0,0 +1,109 @@
|
|
|
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.confirmPayTransaction = void 0;
|
|
13
|
+
const factory = require("../../factory");
|
|
14
|
+
const PayTransactionService = require("../assetTransaction/pay");
|
|
15
|
+
const payOrder_1 = require("../order/payOrder");
|
|
16
|
+
function confirmPayTransaction(data) {
|
|
17
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// アクション開始
|
|
19
|
+
const action = yield repos.action.start(data);
|
|
20
|
+
try {
|
|
21
|
+
for (const confirmingTransaction of data.object) {
|
|
22
|
+
yield PayTransactionService.confirm({
|
|
23
|
+
transactionNumber: confirmingTransaction.transactionNumber,
|
|
24
|
+
potentialActions: {
|
|
25
|
+
pay: {
|
|
26
|
+
purpose: {
|
|
27
|
+
typeOf: data.purpose.typeOf,
|
|
28
|
+
confirmationNumber: data.purpose.confirmationNumber,
|
|
29
|
+
orderNumber: data.purpose.orderNumber
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})({
|
|
34
|
+
action: repos.action,
|
|
35
|
+
accountingReport: repos.accountingReport,
|
|
36
|
+
assetTransaction: repos.assetTransaction,
|
|
37
|
+
event: repos.event,
|
|
38
|
+
order: repos.order,
|
|
39
|
+
product: repos.product,
|
|
40
|
+
project: repos.project,
|
|
41
|
+
seller: repos.seller,
|
|
42
|
+
task: repos.task
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// actionにエラー結果を追加
|
|
48
|
+
try {
|
|
49
|
+
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
50
|
+
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
|
|
51
|
+
}
|
|
52
|
+
catch (__) {
|
|
53
|
+
// 失敗したら仕方ない
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
// アクション完了
|
|
58
|
+
const actionResult = {};
|
|
59
|
+
yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
60
|
+
// processOrder連携(2023-08-23~)
|
|
61
|
+
yield onConfirmed(data)({
|
|
62
|
+
assetTransaction: repos.assetTransaction,
|
|
63
|
+
order: repos.order,
|
|
64
|
+
registerActionInProgress: repos.registerServiceInProgress,
|
|
65
|
+
task: repos.task,
|
|
66
|
+
transaction: repos.transaction
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.confirmPayTransaction = confirmPayTransaction;
|
|
71
|
+
function onConfirmed(params) {
|
|
72
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (params.processOrder === true) {
|
|
74
|
+
// 注文のpaymentMethodIdを取得
|
|
75
|
+
const order = yield repos.order.findByOrderNumber({
|
|
76
|
+
orderNumber: params.purpose.orderNumber,
|
|
77
|
+
project: { id: params.project.id },
|
|
78
|
+
inclusion: ['paymentMethods'],
|
|
79
|
+
exclusion: []
|
|
80
|
+
});
|
|
81
|
+
// PayTransactionのステータス検証
|
|
82
|
+
let allPayTransactionConfirmed = false;
|
|
83
|
+
const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
|
|
84
|
+
.map((invoice) => invoice.paymentMethodId);
|
|
85
|
+
if (paymentMethodIds.length > 0) {
|
|
86
|
+
const referencedPayTransactions = yield repos.assetTransaction.search({
|
|
87
|
+
project: { id: { $eq: params.project.id } },
|
|
88
|
+
typeOf: factory.assetTransactionType.Pay,
|
|
89
|
+
transactionNumber: { $in: paymentMethodIds }
|
|
90
|
+
}, ['status']);
|
|
91
|
+
allPayTransactionConfirmed =
|
|
92
|
+
referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
allPayTransactionConfirmed = true;
|
|
96
|
+
}
|
|
97
|
+
if (allPayTransactionConfirmed) {
|
|
98
|
+
yield (0, payOrder_1.payOrder)({
|
|
99
|
+
project: { id: params.project.id },
|
|
100
|
+
object: {
|
|
101
|
+
confirmationNumber: params.purpose.confirmationNumber,
|
|
102
|
+
orderNumber: params.purpose.orderNumber
|
|
103
|
+
},
|
|
104
|
+
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
105
|
+
})(repos);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -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;
|
|
@@ -42,5 +42,7 @@ declare function placeOrder(params: {
|
|
|
42
42
|
registerActionInProgress: RegisterServiceInProgressRepo;
|
|
43
43
|
task: TaskRepo;
|
|
44
44
|
transaction: TransactionRepo;
|
|
45
|
-
}) => Promise<
|
|
45
|
+
}) => Promise<{
|
|
46
|
+
order: factory.order.IOrder;
|
|
47
|
+
}>;
|
|
46
48
|
export { placeOrder, placeOrderWithoutTransaction };
|
|
@@ -233,14 +233,29 @@ function placeOrder(params) {
|
|
|
233
233
|
}
|
|
234
234
|
else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
|
|
235
235
|
// OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
})
|
|
236
|
+
// OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
|
|
237
|
+
yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
|
|
238
|
+
order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderPaymentDue }),
|
|
239
|
+
placeOrderTransaction
|
|
240
|
+
})({
|
|
241
|
+
registerActionInProgress: repos.registerActionInProgress,
|
|
242
|
+
task: repos.task
|
|
243
|
+
});
|
|
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
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
|
|
244
259
|
}
|
|
245
260
|
}
|
|
246
261
|
// onOrderStatusChangedへ移行(2023-08-17~)
|
|
@@ -248,6 +263,7 @@ function placeOrder(params) {
|
|
|
248
263
|
// object: order,
|
|
249
264
|
// potentialActions: params.potentialActions
|
|
250
265
|
// })(repos);
|
|
266
|
+
return { order };
|
|
251
267
|
});
|
|
252
268
|
}
|
|
253
269
|
exports.placeOrder = placeOrder;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 注文サービス
|
|
3
3
|
*/
|
|
4
|
+
import { confirmPayTransaction } from './order/confirmPayTransaction';
|
|
4
5
|
import { deleteOrder } from './order/deleteOrder';
|
|
5
6
|
import { onOrderStatusChanged } from './order/onOrderStatusChanged';
|
|
6
7
|
import { onOrderUpdated } from './order/onOrderUpdated';
|
|
7
8
|
import { placeOrder, placeOrderWithoutTransaction } from './order/placeOrder';
|
|
8
|
-
import { returnOrder } from './order/returnOrder';
|
|
9
9
|
import { sendOrder } from './order/sendOrder';
|
|
10
|
-
export { deleteOrder, onOrderStatusChanged, onOrderUpdated, placeOrder, placeOrderWithoutTransaction,
|
|
10
|
+
export { confirmPayTransaction, deleteOrder, onOrderStatusChanged, onOrderUpdated, placeOrder, placeOrderWithoutTransaction, sendOrder };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendOrder = exports.
|
|
3
|
+
exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.onOrderUpdated = exports.onOrderStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文サービス
|
|
6
6
|
*/
|
|
7
|
+
const confirmPayTransaction_1 = require("./order/confirmPayTransaction");
|
|
8
|
+
Object.defineProperty(exports, "confirmPayTransaction", { enumerable: true, get: function () { return confirmPayTransaction_1.confirmPayTransaction; } });
|
|
7
9
|
const deleteOrder_1 = require("./order/deleteOrder");
|
|
8
10
|
Object.defineProperty(exports, "deleteOrder", { enumerable: true, get: function () { return deleteOrder_1.deleteOrder; } });
|
|
9
11
|
const onOrderStatusChanged_1 = require("./order/onOrderStatusChanged");
|
|
@@ -13,7 +15,6 @@ Object.defineProperty(exports, "onOrderUpdated", { enumerable: true, get: functi
|
|
|
13
15
|
const placeOrder_1 = require("./order/placeOrder");
|
|
14
16
|
Object.defineProperty(exports, "placeOrder", { enumerable: true, get: function () { return placeOrder_1.placeOrder; } });
|
|
15
17
|
Object.defineProperty(exports, "placeOrderWithoutTransaction", { enumerable: true, get: function () { return placeOrder_1.placeOrderWithoutTransaction; } });
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(exports, "returnOrder", { enumerable: true, get: function () { return returnOrder_1.returnOrder; } });
|
|
18
|
+
// import { returnOrder } from './order/returnOrder';
|
|
18
19
|
const sendOrder_1 = require("./order/sendOrder");
|
|
19
20
|
Object.defineProperty(exports, "sendOrder", { enumerable: true, get: function () { return sendOrder_1.sendOrder; } });
|
|
@@ -22,8 +22,7 @@ const project_1 = require("../../repo/project");
|
|
|
22
22
|
const seller_1 = require("../../repo/seller");
|
|
23
23
|
const task_1 = require("../../repo/task");
|
|
24
24
|
const transaction_1 = require("../../repo/transaction");
|
|
25
|
-
const
|
|
26
|
-
const payOrder_1 = require("../order/payOrder");
|
|
25
|
+
const confirmPayTransaction_1 = require("../order/confirmPayTransaction");
|
|
27
26
|
/**
|
|
28
27
|
* タスク実行関数
|
|
29
28
|
*/
|
|
@@ -32,106 +31,19 @@ function call(data) {
|
|
|
32
31
|
if (settings.redisClient === undefined) {
|
|
33
32
|
throw new factory.errors.Argument('settings', 'redisClient required');
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const action = yield actionRepo.start(data);
|
|
48
|
-
try {
|
|
49
|
-
for (const confirmingTransaction of data.object) {
|
|
50
|
-
yield PayTransactionService.confirm({
|
|
51
|
-
transactionNumber: confirmingTransaction.transactionNumber,
|
|
52
|
-
potentialActions: {
|
|
53
|
-
pay: {
|
|
54
|
-
purpose: {
|
|
55
|
-
typeOf: data.purpose.typeOf,
|
|
56
|
-
confirmationNumber: data.purpose.confirmationNumber,
|
|
57
|
-
orderNumber: data.purpose.orderNumber
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
})({
|
|
62
|
-
action: actionRepo,
|
|
63
|
-
accountingReport: accountingReportRepo,
|
|
64
|
-
assetTransaction: assetTransactionRepo,
|
|
65
|
-
event: eventRepo,
|
|
66
|
-
order: orderRepo,
|
|
67
|
-
product: productRepo,
|
|
68
|
-
project: projectRepo,
|
|
69
|
-
seller: sellerRepo,
|
|
70
|
-
task: taskRepo
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
// actionにエラー結果を追加
|
|
76
|
-
try {
|
|
77
|
-
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
78
|
-
yield actionRepo.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
|
|
79
|
-
}
|
|
80
|
-
catch (__) {
|
|
81
|
-
// 失敗したら仕方ない
|
|
82
|
-
}
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
// アクション完了
|
|
86
|
-
const actionResult = {};
|
|
87
|
-
yield actionRepo.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
88
|
-
// processOrder連携(2023-08-23~)
|
|
89
|
-
yield onConfirmed(data)({
|
|
90
|
-
assetTransaction: assetTransactionRepo,
|
|
91
|
-
order: orderRepo,
|
|
92
|
-
registerActionInProgress: registerServiceInProgressRepo,
|
|
93
|
-
task: taskRepo,
|
|
94
|
-
transaction: transactionRepo
|
|
34
|
+
yield (0, confirmPayTransaction_1.confirmPayTransaction)(data)({
|
|
35
|
+
action: new action_1.MongoRepository(settings.connection),
|
|
36
|
+
assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
|
|
37
|
+
order: new order_1.MongoRepository(settings.connection),
|
|
38
|
+
accountingReport: new accountingReport_1.MongoRepository(settings.connection),
|
|
39
|
+
event: new event_1.MongoRepository(settings.connection),
|
|
40
|
+
product: new product_1.MongoRepository(settings.connection),
|
|
41
|
+
project: new project_1.MongoRepository(settings.connection),
|
|
42
|
+
seller: new seller_1.MongoRepository(settings.connection),
|
|
43
|
+
task: new task_1.MongoRepository(settings.connection),
|
|
44
|
+
transaction: new transaction_1.MongoRepository(settings.connection),
|
|
45
|
+
registerServiceInProgress: new registerServiceInProgress_1.RedisRepository(settings.redisClient)
|
|
95
46
|
});
|
|
96
47
|
});
|
|
97
48
|
}
|
|
98
49
|
exports.call = call;
|
|
99
|
-
function onConfirmed(params) {
|
|
100
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
if (params.processOrder === true) {
|
|
102
|
-
// 注文のpaymentMethodIdを取得
|
|
103
|
-
const order = yield repos.order.findByOrderNumber({
|
|
104
|
-
orderNumber: params.purpose.orderNumber,
|
|
105
|
-
project: { id: params.project.id },
|
|
106
|
-
inclusion: ['paymentMethods'],
|
|
107
|
-
exclusion: []
|
|
108
|
-
});
|
|
109
|
-
// PayTransactionのステータス検証
|
|
110
|
-
let allPayTransactionConfirmed = false;
|
|
111
|
-
const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
|
|
112
|
-
.map((invoice) => invoice.paymentMethodId);
|
|
113
|
-
if (paymentMethodIds.length > 0) {
|
|
114
|
-
const referencedPayTransactions = yield repos.assetTransaction.search({
|
|
115
|
-
project: { id: { $eq: params.project.id } },
|
|
116
|
-
typeOf: factory.assetTransactionType.Pay,
|
|
117
|
-
transactionNumber: { $in: paymentMethodIds }
|
|
118
|
-
}, ['status']);
|
|
119
|
-
allPayTransactionConfirmed =
|
|
120
|
-
referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
allPayTransactionConfirmed = true;
|
|
124
|
-
}
|
|
125
|
-
if (allPayTransactionConfirmed) {
|
|
126
|
-
yield (0, payOrder_1.payOrder)({
|
|
127
|
-
project: { id: params.project.id },
|
|
128
|
-
object: {
|
|
129
|
-
confirmationNumber: params.purpose.confirmationNumber,
|
|
130
|
-
orderNumber: params.purpose.orderNumber
|
|
131
|
-
},
|
|
132
|
-
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
133
|
-
})(repos);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
@@ -17,7 +17,7 @@ const order_1 = require("../../repo/order");
|
|
|
17
17
|
const ownershipInfo_1 = require("../../repo/ownershipInfo");
|
|
18
18
|
const task_1 = require("../../repo/task");
|
|
19
19
|
const transaction_1 = require("../../repo/transaction");
|
|
20
|
-
const
|
|
20
|
+
const returnOrder_1 = require("../order/returnOrder");
|
|
21
21
|
/**
|
|
22
22
|
* タスク実行関数
|
|
23
23
|
*/
|
|
@@ -32,7 +32,7 @@ function call(data) {
|
|
|
32
32
|
const taskRepo = new task_1.MongoRepository(settings.connection);
|
|
33
33
|
const transactionRepo = new transaction_1.MongoRepository(settings.connection);
|
|
34
34
|
const registerServiceInProgressRepo = new registerServiceInProgress_1.RedisRepository(settings.redisClient);
|
|
35
|
-
yield
|
|
35
|
+
yield (0, returnOrder_1.returnOrder)(Object.assign(Object.assign({}, data), { useOnOrderStatusChanged: true }))({
|
|
36
36
|
action: actionRepo,
|
|
37
37
|
order: orderRepo,
|
|
38
38
|
ownershipInfo: ownershipInfoRepo,
|
package/package.json
CHANGED