@chevre/domain 21.7.0-alpha.10 → 21.7.0-alpha.11
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/unsetUnnecessaryFields.ts +4 -2
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +1 -0
- package/lib/chevre/service/order/onOrderStatusChanged.js +118 -1
- package/lib/chevre/service/order/placeOrder.d.ts +1 -2
- package/lib/chevre/service/order/placeOrder.js +15 -74
- package/package.json +1 -1
|
@@ -14,12 +14,14 @@ async function main() {
|
|
|
14
14
|
let updateResult: any;
|
|
15
15
|
updateResult = await transactionRepo.unsetUnnecessaryFields({
|
|
16
16
|
filter: {
|
|
17
|
-
'project.id': { $eq: PROJECT_ID },
|
|
17
|
+
// 'project.id': { $eq: PROJECT_ID },
|
|
18
18
|
typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
|
|
19
19
|
status: { $eq: chevre.factory.transactionStatusType.Confirmed },
|
|
20
20
|
startDate: {
|
|
21
|
-
$lte: moment('2023-
|
|
21
|
+
$lte: moment('2023-04-01T00:00:00Z')
|
|
22
22
|
.toDate()
|
|
23
|
+
// $lte: moment('2023-08-16T07:26:00Z')
|
|
24
|
+
// .toDate()
|
|
23
25
|
},
|
|
24
26
|
'object.authorizeActions': { $exists: true }
|
|
25
27
|
},
|
|
@@ -11,4 +11,5 @@ export declare function onOrderStatusChanged(params: {
|
|
|
11
11
|
registerActionInProgress: RegisterServiceInProgressRepo;
|
|
12
12
|
task: TaskRepo;
|
|
13
13
|
}) => Promise<void>;
|
|
14
|
+
export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
|
|
14
15
|
export {};
|
|
@@ -23,6 +23,7 @@ const USE_CONFIRM_REGISTER_SERVICE_TRANSACTION = process.env.USE_CONFIRM_REGISTE
|
|
|
23
23
|
const TOKEN_EXPIRES_IN = 604800;
|
|
24
24
|
function onOrderStatusChanged(params) {
|
|
25
25
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b, _c;
|
|
26
27
|
let tasks = [];
|
|
27
28
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
|
|
28
29
|
const simpleOrder = {
|
|
@@ -76,7 +77,13 @@ function onOrderStatusChanged(params) {
|
|
|
76
77
|
...(0, factory_1.createInformTasks)(orderWithToken),
|
|
77
78
|
...yield createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
|
|
78
79
|
...yield createConfirmReserveTransactionTasks(params.order, simpleOrder)(repos),
|
|
79
|
-
...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos)
|
|
80
|
+
...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos),
|
|
81
|
+
// 取引のpotentialActionsを適用(2023-08-17~)
|
|
82
|
+
...createOnPlaceOrderTasksByTransaction({
|
|
83
|
+
object: params.order,
|
|
84
|
+
// potentialActions: params.potentialActions
|
|
85
|
+
potentialActions: (_c = (_b = (_a = params.placeOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.potentialActions
|
|
86
|
+
})
|
|
80
87
|
];
|
|
81
88
|
break;
|
|
82
89
|
case factory.orderStatus.OrderReturned:
|
|
@@ -363,3 +370,113 @@ function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
|
|
|
363
370
|
return tasks;
|
|
364
371
|
});
|
|
365
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* 注文作成後のアクション
|
|
375
|
+
*/
|
|
376
|
+
// export function onPlaceOrder(params: {
|
|
377
|
+
// object: factory.order.IOrder | IExternalOrder;
|
|
378
|
+
// potentialActions?: factory.action.trade.order.IPotentialActions;
|
|
379
|
+
// }) {
|
|
380
|
+
// return async (repos: {
|
|
381
|
+
// task: TaskRepo;
|
|
382
|
+
// }) => {
|
|
383
|
+
// const potentialActions = params.potentialActions;
|
|
384
|
+
// const now = new Date();
|
|
385
|
+
// // potentialActionsのためのタスクを生成
|
|
386
|
+
// const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
|
|
387
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
388
|
+
// /* istanbul ignore else */
|
|
389
|
+
// if (potentialActions !== undefined) {
|
|
390
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
391
|
+
// /* istanbul ignore else */
|
|
392
|
+
// if (potentialActions.sendOrder !== undefined) {
|
|
393
|
+
// const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
|
|
394
|
+
// project: potentialActions.sendOrder.project,
|
|
395
|
+
// name: factory.taskName.SendOrder,
|
|
396
|
+
// status: factory.taskStatus.Ready,
|
|
397
|
+
// runsAt: now, // なるはやで実行
|
|
398
|
+
// remainingNumberOfTries: 10,
|
|
399
|
+
// numberOfTried: 0,
|
|
400
|
+
// executionResults: [],
|
|
401
|
+
// // data: potentialActions.sendOrder
|
|
402
|
+
// data: {
|
|
403
|
+
// project: potentialActions.sendOrder.project,
|
|
404
|
+
// object: {
|
|
405
|
+
// ...potentialActions.sendOrder.object,
|
|
406
|
+
// confirmationNumber: params.object.confirmationNumber
|
|
407
|
+
// },
|
|
408
|
+
// ...(potentialActions.sendOrder.potentialActions !== undefined)
|
|
409
|
+
// ? { potentialActions: potentialActions.sendOrder.potentialActions }
|
|
410
|
+
// : undefined
|
|
411
|
+
// }
|
|
412
|
+
// };
|
|
413
|
+
// taskAttributes.push(sendOrderTask);
|
|
414
|
+
// }
|
|
415
|
+
// // ポイント付与
|
|
416
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
417
|
+
// /* istanbul ignore else */
|
|
418
|
+
// if (Array.isArray(potentialActions.givePointAward)) {
|
|
419
|
+
// taskAttributes.push(...potentialActions.givePointAward.map(
|
|
420
|
+
// (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
|
|
421
|
+
// return {
|
|
422
|
+
// project: a.project,
|
|
423
|
+
// name: factory.taskName.GivePointAward,
|
|
424
|
+
// status: factory.taskStatus.Ready,
|
|
425
|
+
// runsAt: now, // なるはやで実行
|
|
426
|
+
// remainingNumberOfTries: 10,
|
|
427
|
+
// numberOfTried: 0,
|
|
428
|
+
// executionResults: [],
|
|
429
|
+
// data: a
|
|
430
|
+
// };
|
|
431
|
+
// }));
|
|
432
|
+
// }
|
|
433
|
+
// }
|
|
434
|
+
// // タスク保管
|
|
435
|
+
// await repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
436
|
+
// };
|
|
437
|
+
// }
|
|
438
|
+
function createOnPlaceOrderTasksByTransaction(params) {
|
|
439
|
+
const potentialActions = params.potentialActions;
|
|
440
|
+
const now = new Date();
|
|
441
|
+
// potentialActionsのためのタスクを生成
|
|
442
|
+
const taskAttributes = [];
|
|
443
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
444
|
+
/* istanbul ignore else */
|
|
445
|
+
if (potentialActions !== undefined) {
|
|
446
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
447
|
+
/* istanbul ignore else */
|
|
448
|
+
if (potentialActions.sendOrder !== undefined) {
|
|
449
|
+
const sendOrderTask = {
|
|
450
|
+
project: potentialActions.sendOrder.project,
|
|
451
|
+
name: factory.taskName.SendOrder,
|
|
452
|
+
status: factory.taskStatus.Ready,
|
|
453
|
+
runsAt: now,
|
|
454
|
+
remainingNumberOfTries: 10,
|
|
455
|
+
numberOfTried: 0,
|
|
456
|
+
executionResults: [],
|
|
457
|
+
data: Object.assign({ project: potentialActions.sendOrder.project, object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber }) }, (potentialActions.sendOrder.potentialActions !== undefined)
|
|
458
|
+
? { potentialActions: potentialActions.sendOrder.potentialActions }
|
|
459
|
+
: undefined)
|
|
460
|
+
};
|
|
461
|
+
taskAttributes.push(sendOrderTask);
|
|
462
|
+
}
|
|
463
|
+
// ポイント付与
|
|
464
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
465
|
+
/* istanbul ignore else */
|
|
466
|
+
if (Array.isArray(potentialActions.givePointAward)) {
|
|
467
|
+
taskAttributes.push(...potentialActions.givePointAward.map((a) => {
|
|
468
|
+
return {
|
|
469
|
+
project: a.project,
|
|
470
|
+
name: factory.taskName.GivePointAward,
|
|
471
|
+
status: factory.taskStatus.Ready,
|
|
472
|
+
runsAt: now,
|
|
473
|
+
remainingNumberOfTries: 10,
|
|
474
|
+
numberOfTried: 0,
|
|
475
|
+
executionResults: [],
|
|
476
|
+
data: a
|
|
477
|
+
};
|
|
478
|
+
}));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return taskAttributes;
|
|
482
|
+
}
|
|
@@ -4,8 +4,8 @@ import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/act
|
|
|
4
4
|
import { MongoRepository as OrderRepo } from '../../repo/order';
|
|
5
5
|
import { MongoRepository as TaskRepo } from '../../repo/task';
|
|
6
6
|
import { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
7
|
+
import { IExternalOrder } from './onOrderStatusChanged';
|
|
7
8
|
import * as factory from '../../factory';
|
|
8
|
-
type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
|
|
9
9
|
/**
|
|
10
10
|
* 注文取引なしに注文を作成する
|
|
11
11
|
*/
|
|
@@ -15,7 +15,6 @@ declare function placeOrderWithoutTransaction(params: {
|
|
|
15
15
|
id: string;
|
|
16
16
|
};
|
|
17
17
|
object: IExternalOrder;
|
|
18
|
-
potentialActions?: factory.action.trade.order.IPotentialActions;
|
|
19
18
|
}): (repos: {
|
|
20
19
|
accountingReport: AccountingReportRepo;
|
|
21
20
|
action: ActionRepo;
|
|
@@ -98,12 +98,6 @@ function placeOrderWithoutTransaction(params) {
|
|
|
98
98
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
99
99
|
var _a;
|
|
100
100
|
const order = params.object;
|
|
101
|
-
// 注文番号から取引と注文をfixする
|
|
102
|
-
// const { order, placeOrderTransaction } = await createOrderFromBody({
|
|
103
|
-
// project: { id: params.project.id },
|
|
104
|
-
// confirmationNumber: params.object.confirmationNumber,
|
|
105
|
-
// orderNumber: params.object.orderNumber
|
|
106
|
-
// })({ transaction: repos.transaction });
|
|
107
101
|
// アクションを作成する(2022-04-11~)
|
|
108
102
|
const maskedCustomer = (0, order_1.createMaskedCustomer)(order, { noProfile: true });
|
|
109
103
|
const simpleOrder = {
|
|
@@ -145,21 +139,17 @@ function placeOrderWithoutTransaction(params) {
|
|
|
145
139
|
yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
|
|
146
140
|
// 経理レポートを保管
|
|
147
141
|
yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
// 潜在アクション
|
|
153
|
-
yield onPlaceOrder({
|
|
154
|
-
object: order,
|
|
155
|
-
potentialActions: params.potentialActions
|
|
156
|
-
})(repos);
|
|
142
|
+
// await onOrderStatusChanged({ order: <factory.order.IOrder>order })({
|
|
143
|
+
// registerActionInProgress: repos.registerActionInProgress,
|
|
144
|
+
// task: repos.task
|
|
145
|
+
// });
|
|
157
146
|
});
|
|
158
147
|
}
|
|
159
148
|
exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
|
|
160
149
|
/**
|
|
161
150
|
* 注文を作成する
|
|
162
151
|
*/
|
|
152
|
+
// tslint:disable-next-line:max-func-body-length
|
|
163
153
|
function placeOrder(params) {
|
|
164
154
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
165
155
|
var _a;
|
|
@@ -226,71 +216,22 @@ function placeOrder(params) {
|
|
|
226
216
|
}
|
|
227
217
|
yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
|
|
228
218
|
}
|
|
229
|
-
if (
|
|
219
|
+
if (typeof params.useOnOrderStatusChanged !== 'boolean') {
|
|
220
|
+
throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
|
|
221
|
+
}
|
|
222
|
+
if (params.useOnOrderStatusChanged) {
|
|
230
223
|
// 経理レポートを保管
|
|
231
224
|
yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
|
|
232
|
-
yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order })({
|
|
225
|
+
yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
|
|
233
226
|
registerActionInProgress: repos.registerActionInProgress,
|
|
234
227
|
task: repos.task
|
|
235
228
|
});
|
|
236
229
|
}
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
})(repos);
|
|
230
|
+
// onOrderStatusChangedへ移行(2023-08-17~)
|
|
231
|
+
// await onPlaceOrder({
|
|
232
|
+
// object: order,
|
|
233
|
+
// potentialActions: params.potentialActions
|
|
234
|
+
// })(repos);
|
|
242
235
|
});
|
|
243
236
|
}
|
|
244
237
|
exports.placeOrder = placeOrder;
|
|
245
|
-
/**
|
|
246
|
-
* 注文作成後のアクション
|
|
247
|
-
*/
|
|
248
|
-
function onPlaceOrder(params) {
|
|
249
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
const potentialActions = params.potentialActions;
|
|
251
|
-
const now = new Date();
|
|
252
|
-
// potentialActionsのためのタスクを生成
|
|
253
|
-
const taskAttributes = [];
|
|
254
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
255
|
-
/* istanbul ignore else */
|
|
256
|
-
if (potentialActions !== undefined) {
|
|
257
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
258
|
-
/* istanbul ignore else */
|
|
259
|
-
if (potentialActions.sendOrder !== undefined) {
|
|
260
|
-
const sendOrderTask = {
|
|
261
|
-
project: potentialActions.sendOrder.project,
|
|
262
|
-
name: factory.taskName.SendOrder,
|
|
263
|
-
status: factory.taskStatus.Ready,
|
|
264
|
-
runsAt: now,
|
|
265
|
-
remainingNumberOfTries: 10,
|
|
266
|
-
numberOfTried: 0,
|
|
267
|
-
executionResults: [],
|
|
268
|
-
// data: potentialActions.sendOrder
|
|
269
|
-
data: Object.assign({ project: potentialActions.sendOrder.project, object: Object.assign(Object.assign({}, potentialActions.sendOrder.object), { confirmationNumber: params.object.confirmationNumber }) }, (potentialActions.sendOrder.potentialActions !== undefined)
|
|
270
|
-
? { potentialActions: potentialActions.sendOrder.potentialActions }
|
|
271
|
-
: undefined)
|
|
272
|
-
};
|
|
273
|
-
taskAttributes.push(sendOrderTask);
|
|
274
|
-
}
|
|
275
|
-
// ポイント付与
|
|
276
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
277
|
-
/* istanbul ignore else */
|
|
278
|
-
if (Array.isArray(potentialActions.givePointAward)) {
|
|
279
|
-
taskAttributes.push(...potentialActions.givePointAward.map((a) => {
|
|
280
|
-
return {
|
|
281
|
-
project: a.project,
|
|
282
|
-
name: factory.taskName.GivePointAward,
|
|
283
|
-
status: factory.taskStatus.Ready,
|
|
284
|
-
runsAt: now,
|
|
285
|
-
remainingNumberOfTries: 10,
|
|
286
|
-
numberOfTried: 0,
|
|
287
|
-
executionResults: [],
|
|
288
|
-
data: a
|
|
289
|
-
};
|
|
290
|
-
}));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// タスク保管
|
|
294
|
-
yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
295
|
-
});
|
|
296
|
-
}
|
package/package.json
CHANGED