@chevre/domain 25.2.0-alpha.54 → 25.2.0-alpha.56

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.
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onOrderPaymentDue = onOrderPaymentDue;
4
+ /**
5
+ * 注文決済時処理
6
+ */
7
+ const util_1 = require("util");
4
8
  const factory_1 = require("../../../factory");
5
9
  function onOrderPaymentDue(params) {
6
10
  return async (repos) => {
@@ -13,8 +17,9 @@ function onOrderPaymentDue(params) {
13
17
  switch (params.order.orderStatus) {
14
18
  // OrderPaymentDueを追加(2023-08-23~)
15
19
  case factory_1.factory.orderStatus.OrderPaymentDue:
20
+ await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos);
16
21
  tasks = [
17
- ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
22
+ // ...await createConfirmPayTransactionTasks(params.order, simpleOrder)(repos),
18
23
  ...createCreateAccountingReportTask(params.order) // 経理レポート作成タスク(2024-02-02~)
19
24
  ];
20
25
  break;
@@ -27,55 +32,79 @@ function onOrderPaymentDue(params) {
27
32
  function createConfirmPayTransactionTasks(order, simpleOrder) {
28
33
  return async (repos) => {
29
34
  const taskRunsAt = new Date();
30
- const tasks = [];
35
+ // const tasks: factory.task.IAttributes<factory.taskName.ConfirmPayTransaction>[] = [];
31
36
  await Promise.all(order.paymentMethods.map(async (invoice) => {
32
37
  // PaymentAutomaticallyAppliedであれば、自動決済処理を実行(2023-08-24~)
33
38
  if (invoice.paymentStatus !== factory_1.factory.paymentStatusType.PaymentAutomaticallyApplied) {
34
39
  return;
35
40
  }
36
- // 冗長なタスク作成を回避
37
- const existingTasks = await repos.task.projectFields({
38
- limit: 1,
39
- page: 1,
40
- project: { id: { $eq: order.project.id } },
41
+ // 識別子指定でタスク作成(2026-07-30~)
42
+ const data = {
43
+ project: order.project,
44
+ typeOf: factory_1.factory.actionType.ConfirmAction,
45
+ object: [{ typeOf: factory_1.factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
46
+ agent: order.project,
47
+ purpose: {
48
+ ...simpleOrder,
49
+ confirmationNumber: order.confirmationNumber
50
+ },
51
+ processOrder: order.orderStatus === factory_1.factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
52
+ useOnOrderStatusChanged: true
53
+ };
54
+ const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', order.project.id, factory_1.factory.taskName.ConfirmPayTransaction, data.purpose.typeOf, data.purpose.orderNumber, factory_1.factory.assetTransactionType.Pay, invoice.paymentMethodId);
55
+ const confirmPayTransactionTask = {
56
+ alternateName: taskIdentifier,
57
+ identifier: taskIdentifier,
58
+ project: order.project,
41
59
  name: factory_1.factory.taskName.ConfirmPayTransaction,
42
- data: {
43
- object: { transactionNumber: { $eq: invoice.paymentMethodId } },
44
- purpose: { orderNumber: { $eq: order.orderNumber } }
45
- }
46
- }, ['id']);
47
- if (existingTasks.length === 0) {
48
- const data = {
49
- project: order.project,
50
- typeOf: factory_1.factory.actionType.ConfirmAction,
51
- object: [{ typeOf: factory_1.factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
52
- agent: order.project,
53
- purpose: {
54
- ...simpleOrder,
55
- confirmationNumber: order.confirmationNumber
56
- },
57
- // 廃止(2024-03-12~)
58
- // instrument: {
59
- // typeOf: factory.assetTransactionType.Pay, // 産取引化(2024-03-11~)
60
- // identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre,
61
- // transactionNumber: invoice.paymentMethodId
62
- // },
63
- processOrder: order.orderStatus === factory_1.factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
64
- useOnOrderStatusChanged: true
65
- };
66
- tasks.push({
67
- project: order.project,
68
- name: factory_1.factory.taskName.ConfirmPayTransaction,
69
- status: factory_1.factory.taskStatus.Ready,
70
- runsAt: taskRunsAt,
71
- remainingNumberOfTries: 10,
72
- numberOfTried: 0,
73
- executionResults: [],
74
- data
75
- });
76
- }
60
+ status: factory_1.factory.taskStatus.Ready,
61
+ runsAt: taskRunsAt,
62
+ remainingNumberOfTries: 10,
63
+ numberOfTried: 0,
64
+ executionResults: [],
65
+ data
66
+ };
67
+ await repos.task.createIfNotExistByAlternateName(confirmPayTransactionTask, { emitImmediately: true });
68
+ // 冗長なタスク作成を回避
69
+ // const existingTasks = await repos.task.projectFields(
70
+ // {
71
+ // limit: 1,
72
+ // page: 1,
73
+ // project: { id: { $eq: order.project.id } },
74
+ // name: factory.taskName.ConfirmPayTransaction,
75
+ // data: {
76
+ // object: { transactionNumber: { $eq: invoice.paymentMethodId } },
77
+ // purpose: { orderNumber: { $eq: order.orderNumber } }
78
+ // }
79
+ // },
80
+ // ['id']
81
+ // ) as { id: string }[];
82
+ // if (existingTasks.length === 0) {
83
+ // const data: factory.task.IData<factory.taskName.ConfirmPayTransaction> = {
84
+ // project: order.project,
85
+ // typeOf: factory.actionType.ConfirmAction,
86
+ // object: [{ typeOf: factory.assetTransactionType.Pay, transactionNumber: invoice.paymentMethodId }],
87
+ // agent: order.project,
88
+ // purpose: {
89
+ // ...simpleOrder,
90
+ // confirmationNumber: order.confirmationNumber
91
+ // },
92
+ // processOrder: order.orderStatus === factory.orderStatus.OrderPaymentDue, // OrderPaymentDueの場合、processOrderを実行する
93
+ // useOnOrderStatusChanged: true
94
+ // };
95
+ // tasks.push({
96
+ // project: order.project,
97
+ // name: factory.taskName.ConfirmPayTransaction,
98
+ // status: factory.taskStatus.Ready,
99
+ // runsAt: taskRunsAt,
100
+ // remainingNumberOfTries: 10,
101
+ // numberOfTried: 0,
102
+ // executionResults: [],
103
+ // data
104
+ // });
105
+ // }
77
106
  }));
78
- return tasks;
107
+ // return tasks;
79
108
  };
80
109
  }
81
110
  function createCreateAccountingReportTask(order) {
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "25.2.0-alpha.54"
91
+ "version": "25.2.0-alpha.56"
92
92
  }