@chevre/domain 21.7.0-alpha.9 → 21.8.0-alpha.0

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.
Files changed (55) hide show
  1. package/example/src/chevre/countDelayedTasks.ts +1 -1
  2. package/example/src/chevre/createDeleteTransactionTasks.ts +108 -0
  3. package/example/src/chevre/createDeleteTransactionTasksIfNotExist.ts +98 -0
  4. package/example/src/chevre/deleteRunsAtPassedCertainPeriod.ts +28 -0
  5. package/example/src/chevre/deleteTasksByName.ts +1 -1
  6. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +1 -1
  7. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +4 -1
  8. package/example/src/chevre/unsetUnnecessaryFields.ts +1 -1
  9. package/lib/chevre/emailMessageBuilder.js +2 -1
  10. package/lib/chevre/repo/assetTransaction.js +22 -23
  11. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +4 -4
  12. package/lib/chevre/repo/mongoose/schemas/offer.js +5 -6
  13. package/lib/chevre/repo/project.d.ts +1 -0
  14. package/lib/chevre/repo/project.js +10 -4
  15. package/lib/chevre/repo/task.d.ts +6 -2
  16. package/lib/chevre/repo/task.js +25 -1
  17. package/lib/chevre/repo/transaction.d.ts +25 -1
  18. package/lib/chevre/repo/transaction.js +6 -1
  19. package/lib/chevre/service/notification.js +13 -6
  20. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +20 -0
  21. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +242 -1
  22. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -1
  23. package/lib/chevre/service/order/onOrderStatusChanged.js +139 -110
  24. package/lib/chevre/service/order/payOrder.d.ts +23 -0
  25. package/lib/chevre/service/order/payOrder.js +74 -0
  26. package/lib/chevre/service/order/placeOrder.d.ts +1 -3
  27. package/lib/chevre/service/order/placeOrder.js +33 -76
  28. package/lib/chevre/service/order/returnOrder.d.ts +1 -2
  29. package/lib/chevre/service/order/returnOrder.js +15 -97
  30. package/lib/chevre/service/order/sendOrder.d.ts +0 -1
  31. package/lib/chevre/service/order/sendOrder.js +6 -68
  32. package/lib/chevre/service/payment/any/factory.js +3 -2
  33. package/lib/chevre/service/task/confirmPayTransaction.js +56 -0
  34. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  35. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +6 -6
  36. package/lib/chevre/service/transaction/moneyTransfer/factory.js +1 -5
  37. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  38. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +12 -6
  39. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +4 -0
  40. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +92 -88
  41. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +1 -1
  42. package/lib/chevre/service/transaction/placeOrderInProgress.js +0 -2
  43. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +8 -1
  44. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +7 -4
  45. package/lib/chevre/service/transaction/returnOrder.js +0 -1
  46. package/lib/chevre/settings.d.ts +1 -1
  47. package/lib/chevre/settings.js +2 -2
  48. package/package.json +3 -3
  49. package/example/src/chevre/checkOrderMembershipTasks.ts +0 -127
  50. package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +0 -65
  51. package/example/src/chevre/transaction/orderMembershipService.ts +0 -105
  52. package/lib/chevre/service/task/orderProgramMembership.d.ts +0 -6
  53. package/lib/chevre/service/task/orderProgramMembership.js +0 -98
  54. package/lib/chevre/service/transaction/orderProgramMembership.d.ts +0 -50
  55. package/lib/chevre/service/transaction/orderProgramMembership.js +0 -349
@@ -22,7 +22,9 @@ const factory_1 = require("./onOrderStatusChanged/factory");
22
22
  const USE_CONFIRM_REGISTER_SERVICE_TRANSACTION = process.env.USE_CONFIRM_REGISTER_SERVICE_TRANSACTION === '1';
23
23
  const TOKEN_EXPIRES_IN = 604800;
24
24
  function onOrderStatusChanged(params) {
25
+ // tslint:disable-next-line:max-func-body-length
25
26
  return (repos) => __awaiter(this, void 0, void 0, function* () {
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
26
28
  let tasks = [];
27
29
  const maskedCustomer = (0, order_1.createMaskedCustomer)(params.order, { noProfile: true });
28
30
  const simpleOrder = {
@@ -40,7 +42,13 @@ function onOrderStatusChanged(params) {
40
42
  };
41
43
  switch (params.order.orderStatus) {
42
44
  case factory.orderStatus.OrderDelivered:
43
- tasks = (0, factory_1.createInformTasks)(params.order);
45
+ tasks = [
46
+ ...(0, factory_1.createInformTasks)(params.order),
47
+ // 取引のpotentialActionsを適用(2023-08-17~)
48
+ ...(0, factory_1.createOnOrderSentTasksByTransaction)({
49
+ potentialActions: (_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
50
+ })
51
+ ];
44
52
  // プロダクト登録プロセスロック解除
45
53
  try {
46
54
  const placeOrderTransaction = params.placeOrderTransaction;
@@ -69,6 +77,12 @@ function onOrderStatusChanged(params) {
69
77
  throw error;
70
78
  }
71
79
  break;
80
+ // OrderPaymentDueを追加(2023-08-23~)
81
+ case factory.orderStatus.OrderPaymentDue:
82
+ tasks = [
83
+ ...yield createConfirmPayTransactionTasks(params.order, simpleOrder)(repos)
84
+ ];
85
+ break;
72
86
  case factory.orderStatus.OrderProcessing:
73
87
  const orderWithToken = yield (0, factory_1.getOrderWithToken)({ order: params.order, expiresIn: TOKEN_EXPIRES_IN });
74
88
  tasks = [
@@ -76,15 +90,26 @@ function onOrderStatusChanged(params) {
76
90
  ...(0, factory_1.createInformTasks)(orderWithToken),
77
91
  ...yield createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
78
92
  ...yield createConfirmReserveTransactionTasks(params.order, simpleOrder)(repos),
79
- ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos)
93
+ ...yield createConfirmRegisterServiceTransactionTasks(params.order, simpleOrder)(repos),
94
+ // 取引のpotentialActionsを適用(2023-08-17~)
95
+ ...(0, factory_1.createOnPlaceOrderTasksByTransaction)({
96
+ object: params.order,
97
+ // potentialActions: params.potentialActions
98
+ potentialActions: (_h = (_g = (_f = params.placeOrderTransaction) === null || _f === void 0 ? void 0 : _f.potentialActions) === null || _g === void 0 ? void 0 : _g.order) === null || _h === void 0 ? void 0 : _h.potentialActions
99
+ })
80
100
  ];
81
101
  break;
82
102
  case factory.orderStatus.OrderReturned:
103
+ const potentialActionsByTransaction = (_m = (_l = (_k = (_j = params.returnOrderTransaction) === null || _j === void 0 ? void 0 : _j.potentialActions) === null || _k === void 0 ? void 0 : _k.returnOrder) === null || _l === void 0 ? void 0 : _l.find((returnOrderActionByTransaction) => {
104
+ return returnOrderActionByTransaction.object.orderNumber === params.order.orderNumber;
105
+ })) === null || _m === void 0 ? void 0 : _m.potentialActions;
83
106
  tasks = [
84
107
  ...(0, factory_1.createInformTasks)(params.order),
85
- ...yield createReturnReserveTransactionTasks(params.order, simpleOrder)(repos),
108
+ ...createReturnReserveTransactionTasks(params.order, simpleOrder),
86
109
  // 決済取引返却タスクを作成(2022-06-09~)
87
- ...yield createReturnPayTransactionTasks(params.order, simpleOrder, params.returnOrderTransaction)(repos)
110
+ ...createReturnPayTransactionTasks(params.order, simpleOrder, params.returnOrderTransaction),
111
+ // 取引のpotentialActionsを適用(2023-08-19~)
112
+ ...(0, factory_1.createOnOrderReturnedTasksByTransaction)({ potentialActions: potentialActionsByTransaction })
88
113
  ];
89
114
  break;
90
115
  default:
@@ -98,7 +123,13 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
98
123
  const taskRunsAt = moment(order.orderDate)
99
124
  .toDate();
100
125
  const tasks = [];
101
- yield Promise.all(order.paymentMethods.map((paymentMethod) => __awaiter(this, void 0, void 0, function* () {
126
+ yield Promise.all(order.paymentMethods.map((invoice) => __awaiter(this, void 0, void 0, function* () {
127
+ // tslint:disable-next-line:no-suspicious-comment
128
+ // TODO 注文にpaymentStatusを保証した後に実装する
129
+ // PaymentAutomaticallyAppliedであれば、自動決済処理を実行
130
+ // if (invoice.paymentStatus !== factory.paymentStatusType.PaymentAutomaticallyApplied) {
131
+ // return;
132
+ // }
102
133
  // 冗長なタスク作成を回避
103
134
  const existingTasks = yield repos.task.search({
104
135
  limit: 1,
@@ -106,7 +137,7 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
106
137
  project: { id: { $eq: order.project.id } },
107
138
  name: factory.taskName.ConfirmPayTransaction,
108
139
  data: {
109
- object: { transactionNumber: { $eq: paymentMethod.paymentMethodId } },
140
+ object: { transactionNumber: { $eq: invoice.paymentMethodId } },
110
141
  purpose: { orderNumber: { $eq: order.orderNumber } }
111
142
  }
112
143
  }, {
@@ -117,13 +148,15 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
117
148
  const data = {
118
149
  project: order.project,
119
150
  typeOf: factory.actionType.ConfirmAction,
120
- object: [{ typeOf: factory.assetTransactionType.Pay, transactionNumber: paymentMethod.paymentMethodId }],
151
+ object: [{ typeOf: factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
121
152
  agent: order.project,
122
153
  purpose: Object.assign(Object.assign({}, simpleOrder), { confirmationNumber: order.confirmationNumber }),
123
154
  instrument: {
124
155
  typeOf: 'WebAPI',
125
156
  identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre
126
- }
157
+ },
158
+ processOrder: order.orderStatus === factory.orderStatus.OrderPaymentDue,
159
+ useOnOrderStatusChanged: true
127
160
  };
128
161
  tasks.push({
129
162
  project: order.project,
@@ -254,112 +287,108 @@ function createConfirmRegisterServiceTransactionTasks(order, simpleOrder) {
254
287
  }
255
288
  const RETURN_COA_TASK_DELAY_IN_SECONDS = 0;
256
289
  function createReturnReserveTransactionTasks(order, simpleOrder) {
257
- return (__) => __awaiter(this, void 0, void 0, function* () {
258
- var _a, _b;
259
- const taskRunsAt = moment(order.dateReturned)
260
- .toDate();
261
- const taskRunsAt4coa = moment(order.dateReturned)
262
- .add(RETURN_COA_TASK_DELAY_IN_SECONDS, 'seconds')
263
- .toDate();
264
- const tasks = [];
265
- const returnActionRecipient = {
266
- typeOf: order.seller.typeOf,
267
- id: order.seller.id,
268
- name: order.seller.name
269
- };
270
- const reservationNumbers = [];
271
- // 注文アイテムから返却アクションを作成する
272
- const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
273
- for (const acceptedOffer of acceptedOffers) {
274
- if (acceptedOffer.itemOffered.typeOf === factory.reservationType.EventReservation
275
- || acceptedOffer.itemOffered.typeOf === factory.reservationType.BusReservation) {
276
- const reservation = acceptedOffer.itemOffered;
277
- const reservationNumber = reservation.reservationNumber;
278
- // 予約番号ごとに返却アクションを作成する
279
- if (!reservationNumbers.includes(reservationNumber)) {
280
- let returnReserveTransactionAction;
281
- switch ((_a = acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) {
282
- case factory.service.webAPI.Identifier.COA:
283
- const superEventLocationBranchCode = (_b = reservation.reservationFor) === null || _b === void 0 ? void 0 : _b.superEvent.location.branchCode;
284
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
285
- const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
286
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
287
- // COAでは数字のみ受け付けるので数字以外を除去
288
- telNum = telNum.replace(/[^\d]/g, '');
289
- returnReserveTransactionAction = {
290
- project: order.project,
291
- typeOf: factory.actionType.ReturnAction,
292
- object: {
293
- theaterCode: superEventLocationBranchCode,
294
- reserveNum: reservationNumber,
295
- telNum: telNum,
296
- typeOf: 'COAReserveTransaction'
297
- },
298
- agent: order.project,
299
- // potentialActions: {},
300
- purpose: simpleOrder,
301
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
302
- recipient: returnActionRecipient
303
- };
304
- break;
305
- default:
306
- returnReserveTransactionAction = {
307
- project: order.project,
308
- typeOf: factory.actionType.ReturnAction,
309
- object: {
310
- typeOf: factory.assetTransactionType.Reserve,
311
- transactionNumber: reservationNumber
312
- },
313
- agent: order.project,
314
- // potentialActions: {},
315
- purpose: simpleOrder,
316
- instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
317
- recipient: returnActionRecipient
318
- };
319
- }
320
- tasks.push({
321
- project: order.project,
322
- name: factory.taskName.ReturnReserveTransaction,
323
- status: factory.taskStatus.Ready,
324
- runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
325
- ? taskRunsAt4coa
326
- : taskRunsAt,
327
- remainingNumberOfTries: 10,
328
- numberOfTried: 0,
329
- executionResults: [],
330
- data: returnReserveTransactionAction
331
- });
332
- reservationNumbers.push(reservationNumber);
290
+ var _a, _b;
291
+ const taskRunsAt = moment(order.dateReturned)
292
+ .toDate();
293
+ const taskRunsAt4coa = moment(order.dateReturned)
294
+ .add(RETURN_COA_TASK_DELAY_IN_SECONDS, 'seconds')
295
+ .toDate();
296
+ const tasks = [];
297
+ const returnActionRecipient = {
298
+ typeOf: order.seller.typeOf,
299
+ id: order.seller.id,
300
+ name: order.seller.name
301
+ };
302
+ const reservationNumbers = [];
303
+ // 注文アイテムから返却アクションを作成する
304
+ const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
305
+ for (const acceptedOffer of acceptedOffers) {
306
+ if (acceptedOffer.itemOffered.typeOf === factory.reservationType.EventReservation
307
+ || acceptedOffer.itemOffered.typeOf === factory.reservationType.BusReservation) {
308
+ const reservation = acceptedOffer.itemOffered;
309
+ const reservationNumber = reservation.reservationNumber;
310
+ // 予約番号ごとに返却アクションを作成する
311
+ if (!reservationNumbers.includes(reservationNumber)) {
312
+ let returnReserveTransactionAction;
313
+ switch ((_a = acceptedOffer.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) {
314
+ case factory.service.webAPI.Identifier.COA:
315
+ const superEventLocationBranchCode = (_b = reservation.reservationFor) === null || _b === void 0 ? void 0 : _b.superEvent.location.branchCode;
316
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
317
+ const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
318
+ let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
319
+ // COAでは数字のみ受け付けるので数字以外を除去
320
+ telNum = telNum.replace(/[^\d]/g, '');
321
+ returnReserveTransactionAction = {
322
+ project: order.project,
323
+ typeOf: factory.actionType.ReturnAction,
324
+ object: {
325
+ theaterCode: superEventLocationBranchCode,
326
+ reserveNum: reservationNumber,
327
+ telNum: telNum,
328
+ typeOf: 'COAReserveTransaction'
329
+ },
330
+ agent: order.project,
331
+ // potentialActions: {},
332
+ purpose: simpleOrder,
333
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.COA },
334
+ recipient: returnActionRecipient
335
+ };
336
+ break;
337
+ default:
338
+ returnReserveTransactionAction = {
339
+ project: order.project,
340
+ typeOf: factory.actionType.ReturnAction,
341
+ object: {
342
+ typeOf: factory.assetTransactionType.Reserve,
343
+ transactionNumber: reservationNumber
344
+ },
345
+ agent: order.project,
346
+ // potentialActions: {},
347
+ purpose: simpleOrder,
348
+ instrument: { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre },
349
+ recipient: returnActionRecipient
350
+ };
333
351
  }
334
- }
335
- }
336
- return tasks;
337
- });
338
- }
339
- const RETURN_PAY_TASK_DELAY_IN_SECONDS = 0;
340
- function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
341
- return (__1) => __awaiter(this, void 0, void 0, function* () {
342
- var _a, _b;
343
- const taskRunsAt = moment(order.dateReturned)
344
- .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
345
- .toDate();
346
- const tasks = [];
347
- const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
348
- const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
349
- if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
350
- tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
351
- return {
352
- project: a.project,
353
- name: factory.taskName.ReturnPayTransaction,
352
+ tasks.push({
353
+ project: order.project,
354
+ name: factory.taskName.ReturnReserveTransaction,
354
355
  status: factory.taskStatus.Ready,
355
- runsAt: taskRunsAt,
356
+ runsAt: (returnReserveTransactionAction.object.typeOf === 'COAReserveTransaction')
357
+ ? taskRunsAt4coa
358
+ : taskRunsAt,
356
359
  remainingNumberOfTries: 10,
357
360
  numberOfTried: 0,
358
361
  executionResults: [],
359
- data: a
360
- };
361
- }));
362
+ data: returnReserveTransactionAction
363
+ });
364
+ reservationNumbers.push(reservationNumber);
365
+ }
362
366
  }
363
- return tasks;
364
- });
367
+ }
368
+ return tasks;
369
+ }
370
+ const RETURN_PAY_TASK_DELAY_IN_SECONDS = 0;
371
+ function createReturnPayTransactionTasks(order, __, returnOrderTransaction) {
372
+ var _a, _b;
373
+ const taskRunsAt = moment(order.dateReturned)
374
+ .add(RETURN_PAY_TASK_DELAY_IN_SECONDS, 'seconds')
375
+ .toDate();
376
+ const tasks = [];
377
+ const returnOrderPotentialActions = (_b = (_a = returnOrderTransaction === null || returnOrderTransaction === void 0 ? void 0 : returnOrderTransaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder.find((action) => action.object.orderNumber === order.orderNumber)) === null || _b === void 0 ? void 0 : _b.potentialActions;
378
+ const returnPayActionsByReturnOrderTransaction = returnOrderPotentialActions === null || returnOrderPotentialActions === void 0 ? void 0 : returnOrderPotentialActions.returnPaymentMethod;
379
+ if (Array.isArray(returnPayActionsByReturnOrderTransaction)) {
380
+ tasks.push(...returnPayActionsByReturnOrderTransaction.map((a) => {
381
+ return {
382
+ project: a.project,
383
+ name: factory.taskName.ReturnPayTransaction,
384
+ status: factory.taskStatus.Ready,
385
+ runsAt: taskRunsAt,
386
+ remainingNumberOfTries: 10,
387
+ numberOfTried: 0,
388
+ executionResults: [],
389
+ data: a
390
+ };
391
+ }));
392
+ }
393
+ return tasks;
365
394
  }
@@ -0,0 +1,23 @@
1
+ import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
2
+ import { MongoRepository as OrderRepo } from '../../repo/order';
3
+ import { MongoRepository as TaskRepo } from '../../repo/task';
4
+ import { MongoRepository as TransactionRepo } from '../../repo/transaction';
5
+ /**
6
+ * 注文を決済する
7
+ */
8
+ declare function payOrder(params: {
9
+ project: {
10
+ id: string;
11
+ };
12
+ object: {
13
+ confirmationNumber: string;
14
+ orderNumber: string;
15
+ };
16
+ useOnOrderStatusChanged: boolean;
17
+ }): (repos: {
18
+ order: OrderRepo;
19
+ registerActionInProgress: RegisterServiceInProgressRepo;
20
+ task: TaskRepo;
21
+ transaction: TransactionRepo;
22
+ }) => Promise<void>;
23
+ export { payOrder };
@@ -0,0 +1,74 @@
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.payOrder = void 0;
13
+ const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
14
+ const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
15
+ const factory = require("../../factory");
16
+ /**
17
+ * 注文を決済する
18
+ */
19
+ function payOrder(params) {
20
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
21
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
22
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
23
+ }
24
+ const orderNumber = params.object.orderNumber;
25
+ const confirmationNumber = params.object.confirmationNumber;
26
+ const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
27
+ project: { id: params.project.id },
28
+ confirmationNumber,
29
+ orderNumber
30
+ })({ transaction: repos.transaction });
31
+ let order = yield repos.order.findByOrderNumber({
32
+ orderNumber,
33
+ project: { id: params.project.id },
34
+ inclusion: [],
35
+ exclusion: []
36
+ });
37
+ try {
38
+ order = yield repos.order.changeStatus({
39
+ project: { id: order.project.id },
40
+ orderNumber,
41
+ orderStatus: factory.orderStatus.OrderPaymentDue,
42
+ previousOrderStatus: factory.orderStatus.OrderProcessing
43
+ });
44
+ }
45
+ catch (error) {
46
+ let throwsError = true;
47
+ // すでにステータスが煤でいた場合、OrderPaymentDue->OrderProcessingの処理自体は成功しているので、後処理を続行する
48
+ order = yield repos.order.findByOrderNumber({
49
+ orderNumber: params.object.orderNumber,
50
+ project: { id: params.project.id },
51
+ inclusion: [],
52
+ exclusion: []
53
+ });
54
+ if (order.orderStatus === factory.orderStatus.OrderDelivered
55
+ || order.orderStatus === factory.orderStatus.OrderReturned) {
56
+ throwsError = false;
57
+ }
58
+ if (throwsError) {
59
+ throw error;
60
+ }
61
+ }
62
+ if (params.useOnOrderStatusChanged) {
63
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
64
+ order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderProcessing // 強制的にOrderProcessingとして処理する
65
+ }),
66
+ placeOrderTransaction
67
+ })({
68
+ registerActionInProgress: repos.registerActionInProgress,
69
+ task: repos.task
70
+ });
71
+ }
72
+ });
73
+ }
74
+ exports.payOrder = payOrder;
@@ -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;
@@ -35,7 +34,6 @@ declare function placeOrder(params: {
35
34
  confirmationNumber: string;
36
35
  orderNumber: string;
37
36
  };
38
- potentialActions?: factory.action.trade.order.IPotentialActions;
39
37
  useOnOrderStatusChanged: boolean;
40
38
  }): (repos: {
41
39
  accountingReport: AccountingReportRepo;
@@ -15,6 +15,7 @@ const order_1 = require("../../factory/order");
15
15
  const createAccountingReportIfNotExist_1 = require("./createAccountingReportIfNotExist");
16
16
  const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
17
17
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
18
+ const payOrder_1 = require("./payOrder");
18
19
  const factory = require("../../factory");
19
20
  function createOrder(params) {
20
21
  // 必要な属性についてDate型に変換(でないと検索クエリを効率的に使えない)
@@ -98,12 +99,6 @@ function placeOrderWithoutTransaction(params) {
98
99
  return (repos) => __awaiter(this, void 0, void 0, function* () {
99
100
  var _a;
100
101
  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
102
  // アクションを作成する(2022-04-11~)
108
103
  const maskedCustomer = (0, order_1.createMaskedCustomer)(order, { noProfile: true });
109
104
  const simpleOrder = {
@@ -145,24 +140,24 @@ function placeOrderWithoutTransaction(params) {
145
140
  yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
146
141
  // 経理レポートを保管
147
142
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
148
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order: order })({
149
- registerActionInProgress: repos.registerActionInProgress,
150
- task: repos.task
151
- });
152
- // 潜在アクション
153
- yield onPlaceOrder({
154
- object: order,
155
- potentialActions: params.potentialActions
156
- })(repos);
143
+ // await onOrderStatusChanged({ order: <factory.order.IOrder>order })({
144
+ // registerActionInProgress: repos.registerActionInProgress,
145
+ // task: repos.task
146
+ // });
157
147
  });
158
148
  }
159
149
  exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
160
150
  /**
161
151
  * 注文を作成する
162
152
  */
153
+ // tslint:disable-next-line:max-func-body-length
163
154
  function placeOrder(params) {
155
+ // tslint:disable-next-line:max-func-body-length
164
156
  return (repos) => __awaiter(this, void 0, void 0, function* () {
165
157
  var _a;
158
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
159
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
160
+ }
166
161
  // 注文番号から取引と注文をfixする
167
162
  const { order, placeOrderTransaction } = yield createOrderFromBody({
168
163
  project: { id: params.project.id },
@@ -226,71 +221,33 @@ function placeOrder(params) {
226
221
  }
227
222
  yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
228
223
  }
229
- if (params.useOnOrderStatusChanged || params.useOnOrderStatusChanged === undefined) {
224
+ if (params.useOnOrderStatusChanged) {
230
225
  // 経理レポートを保管
231
226
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
232
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order })({
233
- registerActionInProgress: repos.registerActionInProgress,
234
- task: repos.task
235
- });
236
- }
237
- // 潜在アクション
238
- yield onPlaceOrder({
239
- object: order,
240
- potentialActions: params.potentialActions
241
- })(repos);
242
- });
243
- }
244
- 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);
227
+ // PaymentDueであればonOrderStatusChangedを実行(2023-08-23~)
228
+ if (order.orderStatus === factory.orderStatus.OrderPaymentDue) {
229
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
230
+ registerActionInProgress: repos.registerActionInProgress,
231
+ task: repos.task
232
+ });
274
233
  }
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
- }));
234
+ else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
235
+ // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
236
+ yield (0, payOrder_1.payOrder)({
237
+ project: { id: order.project.id },
238
+ object: {
239
+ confirmationNumber: order.confirmationNumber,
240
+ orderNumber: order.orderNumber
241
+ },
242
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
243
+ })(repos);
291
244
  }
292
245
  }
293
- // タスク保管
294
- yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
246
+ // onOrderStatusChangedへ移行(2023-08-17~)
247
+ // await onPlaceOrder({
248
+ // object: order,
249
+ // potentialActions: params.potentialActions
250
+ // })(repos);
295
251
  });
296
252
  }
253
+ exports.placeOrder = placeOrder;
@@ -9,12 +9,11 @@ declare function returnOrder(params: {
9
9
  agent: factory.action.transfer.returnAction.order.IAgent;
10
10
  object: {
11
11
  orderNumber: string;
12
- dateReturned?: Date;
12
+ dateReturned: Date;
13
13
  };
14
14
  project: {
15
15
  id: string;
16
16
  };
17
- potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
18
17
  useOnOrderStatusChanged: boolean;
19
18
  }): (repos: {
20
19
  action: ActionRepo;