@chevre/domain 21.18.0-alpha.4 → 21.18.0-alpha.41

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 (142) hide show
  1. package/example/src/chevre/aggreateOwnershipInfosByOrder.ts +24 -0
  2. package/example/src/chevre/offerCatalog2offerCatalogItem.ts +4 -0
  3. package/example/src/chevre/searchAcceptedOfferIds.ts +57 -0
  4. package/example/src/chevre/searchOffers.ts +41 -37
  5. package/example/src/chevre/searchOrderAcceptedOffers.ts +12 -12
  6. package/example/src/chevre/searchOrders.ts +36 -19
  7. package/example/src/chevre/searchReservationsByOrder.ts +30 -0
  8. package/example/src/chevre/searchTransactions.ts +41 -0
  9. package/example/src/chevre/transaction/processReturnOrder.ts +1 -0
  10. package/example/src/chevre/upsertMoviesByIdentifier.ts +5 -4
  11. package/example/src/chevre/upsertOfferCatalogsByIdentifier.ts +46 -0
  12. package/example/src/chevre/upsertOffersByIdentifier.ts +94 -0
  13. package/example/src/chevre/upsertScreeningEventSeriesByVersion.ts +104 -0
  14. package/lib/chevre/credentials.d.ts +0 -3
  15. package/lib/chevre/credentials.js +4 -3
  16. package/lib/chevre/repo/acceptedOffer.d.ts +60 -0
  17. package/lib/chevre/repo/acceptedOffer.js +158 -0
  18. package/lib/chevre/repo/creativeWork.d.ts +12 -2
  19. package/lib/chevre/repo/creativeWork.js +39 -25
  20. package/lib/chevre/repo/event.d.ts +15 -0
  21. package/lib/chevre/repo/event.js +66 -0
  22. package/lib/chevre/repo/offer.d.ts +14 -5
  23. package/lib/chevre/repo/offer.js +94 -19
  24. package/lib/chevre/repo/offerCatalog.d.ts +18 -1
  25. package/lib/chevre/repo/offerCatalog.js +51 -39
  26. package/lib/chevre/repo/order.d.ts +14 -54
  27. package/lib/chevre/repo/order.js +46 -180
  28. package/lib/chevre/repo/paymentService.d.ts +30 -0
  29. package/lib/chevre/repo/paymentService.js +75 -0
  30. package/lib/chevre/repo/place.js +14 -10
  31. package/lib/chevre/repo/product.d.ts +41 -10
  32. package/lib/chevre/repo/product.js +94 -47
  33. package/lib/chevre/repo/transaction.d.ts +5 -4
  34. package/lib/chevre/repository.d.ts +10 -7
  35. package/lib/chevre/repository.js +28 -17
  36. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +10 -1
  37. package/lib/chevre/service/aggregation/event/findEventOffers.js +10 -1
  38. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  39. package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +3 -1
  40. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  41. package/lib/chevre/service/assetTransaction/pay.d.ts +2 -0
  42. package/lib/chevre/service/assetTransaction/pay.js +47 -34
  43. package/lib/chevre/service/assetTransaction/refund/factory.d.ts +1 -1
  44. package/lib/chevre/service/assetTransaction/refund/factory.js +0 -5
  45. package/lib/chevre/service/assetTransaction/refund.js +15 -3
  46. package/lib/chevre/service/assetTransaction/registerService.js +18 -2
  47. package/lib/chevre/service/assetTransaction/reserve/factory/price.js +1 -1
  48. package/lib/chevre/service/assetTransaction/reserve.js +32 -2
  49. package/lib/chevre/service/delivery/factory.d.ts +3 -1
  50. package/lib/chevre/service/delivery/factory.js +4 -2
  51. package/lib/chevre/service/delivery.d.ts +1 -2
  52. package/lib/chevre/service/delivery.js +1 -3
  53. package/lib/chevre/service/event.js +1 -1
  54. package/lib/chevre/service/moneyTransfer.js +11 -1
  55. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  56. package/lib/chevre/service/offer/event/factory.js +4 -2
  57. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +40 -5
  58. package/lib/chevre/service/offer/product/factory.js +1 -1
  59. package/lib/chevre/service/offer/product/searchProductOffers.js +10 -1
  60. package/lib/chevre/service/offer/product.d.ts +0 -14
  61. package/lib/chevre/service/offer/product.js +61 -44
  62. package/lib/chevre/service/order/confirmPayTransaction.d.ts +2 -0
  63. package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
  64. package/lib/chevre/service/order/createAccountingReportIfNotExist.d.ts +3 -1
  65. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +4 -1
  66. package/lib/chevre/service/order/deleteOrder.d.ts +2 -0
  67. package/lib/chevre/service/order/deleteOrder.js +15 -4
  68. package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +3 -1
  69. package/lib/chevre/service/order/findPlaceOrderTransaction.js +1 -2
  70. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +3 -3
  71. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +15 -9
  72. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +11 -0
  73. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +54 -0
  74. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +10 -0
  75. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +38 -0
  76. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +12 -0
  77. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +111 -0
  78. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +12 -0
  79. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +64 -0
  80. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.d.ts +10 -0
  81. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +103 -0
  82. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +23 -0
  83. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +180 -0
  84. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +14 -0
  85. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +214 -0
  86. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +10 -0
  87. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +110 -0
  88. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.d.ts +14 -0
  89. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +164 -0
  90. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +9 -15
  91. package/lib/chevre/service/order/onOrderStatusChanged.js +11 -446
  92. package/lib/chevre/service/order/onOrderUpdated/factory.d.ts +6 -0
  93. package/lib/chevre/service/order/onOrderUpdated/factory.js +45 -0
  94. package/lib/chevre/service/order/onOrderUpdated.js +1 -1
  95. package/lib/chevre/service/order/payOrder.d.ts +2 -2
  96. package/lib/chevre/service/order/placeOrder.d.ts +2 -3
  97. package/lib/chevre/service/order/placeOrder.js +65 -22
  98. package/lib/chevre/service/order/returnOrder.d.ts +2 -2
  99. package/lib/chevre/service/order/returnOrder.js +34 -13
  100. package/lib/chevre/service/order/sendOrder.d.ts +2 -2
  101. package/lib/chevre/service/order/sendOrder.js +19 -6
  102. package/lib/chevre/service/order.d.ts +2 -2
  103. package/lib/chevre/service/order.js +2 -2
  104. package/lib/chevre/service/payment/any.js +1 -1
  105. package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -2
  106. package/lib/chevre/service/payment/paymentCard.js +9 -2
  107. package/lib/chevre/service/reserve/searchByOrder.d.ts +21 -0
  108. package/lib/chevre/service/reserve/searchByOrder.js +113 -0
  109. package/lib/chevre/service/reserve/verifyToken4reservation.js +0 -11
  110. package/lib/chevre/service/reserve.d.ts +2 -1
  111. package/lib/chevre/service/reserve.js +3 -1
  112. package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
  113. package/lib/chevre/service/task/deleteTransaction.js +2 -0
  114. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +5 -6
  115. package/lib/chevre/service/task/onAuthorizationCreated.js +9 -18
  116. package/lib/chevre/service/task/onOrderPaymentCompleted.js +5 -6
  117. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +1 -1
  118. package/lib/chevre/service/task/onResourceUpdated.js +1 -1
  119. package/lib/chevre/service/task/placeOrder.js +10 -17
  120. package/lib/chevre/service/task/returnOrder.js +10 -17
  121. package/lib/chevre/service/task/sendOrder.js +10 -17
  122. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -7
  123. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  124. package/lib/chevre/service/transaction/moneyTransfer.js +3 -4
  125. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +0 -4
  126. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +0 -86
  127. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -1
  128. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +1 -1
  129. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.d.ts +1 -0
  130. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +3 -3
  131. package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +1 -0
  132. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +1 -1
  133. package/lib/chevre/service/transaction/returnOrder.d.ts +3 -0
  134. package/lib/chevre/service/transaction/returnOrder.js +73 -55
  135. package/package.json +3 -3
  136. package/example/src/chevre/transaction/findPaymentCardPermit.ts +0 -29
  137. package/lib/chevre/repo/action/registerServiceInProgress.d.ts +0 -29
  138. package/lib/chevre/repo/action/registerServiceInProgress.js +0 -58
  139. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -42
  140. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +0 -467
  141. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +0 -26
  142. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +0 -65
@@ -8,12 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.placeOrderWithoutTransaction = exports.placeOrder = void 0;
13
24
  const moment = require("moment");
14
25
  const order_1 = require("../../factory/order");
15
26
  const createAccountingReportIfNotExist_1 = require("./createAccountingReportIfNotExist");
16
- const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
17
27
  const onAssetTransactionStatusChanged_1 = require("./onAssetTransactionStatusChanged");
18
28
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
19
29
  const factory = require("../../factory");
@@ -78,17 +88,31 @@ function createOrderFromBody(params) {
78
88
  const confirmationNumber = String(params.confirmationNumber);
79
89
  const orderNumber = params.orderNumber;
80
90
  let order;
81
- const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
82
- project: { id: params.project.id },
83
- confirmationNumber,
84
- orderNumber
85
- })(repos);
86
- const orderByTransaction = (_a = placeOrderTransaction.result) === null || _a === void 0 ? void 0 : _a.order;
91
+ const placeOrderTransactions = yield repos.transaction.search({
92
+ limit: 1,
93
+ page: 1,
94
+ project: { id: { $eq: params.project.id } },
95
+ typeOf: factory.transactionType.PlaceOrder,
96
+ statuses: [factory.transactionStatusType.Confirmed],
97
+ result: {
98
+ order: {
99
+ confirmationNumber: { $eq: confirmationNumber },
100
+ orderNumbers: [orderNumber]
101
+ }
102
+ },
103
+ inclusion: ['id', 'potentialActions', 'project', 'typeOf', 'result'],
104
+ exclusion: []
105
+ });
106
+ const placeOrderTransactionWithResult = placeOrderTransactions.shift();
107
+ if (placeOrderTransactionWithResult === undefined) {
108
+ throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
109
+ }
110
+ const orderByTransaction = (_a = placeOrderTransactionWithResult.result) === null || _a === void 0 ? void 0 : _a.order;
87
111
  if (orderByTransaction === undefined) {
88
112
  throw new factory.errors.NotFound('transaction.result.order');
89
113
  }
90
- order = orderByTransaction;
91
- order = createOrder(order);
114
+ order = createOrder(orderByTransaction);
115
+ const { result } = placeOrderTransactionWithResult, placeOrderTransaction = __rest(placeOrderTransactionWithResult, ["result"]);
92
116
  return { order, placeOrderTransaction };
93
117
  });
94
118
  }
@@ -124,7 +148,7 @@ function placeOrderWithoutTransaction(params) {
124
148
  };
125
149
  const action = yield repos.action.start(orderActionAttributes);
126
150
  try {
127
- yield repos.order.createIfNotExist(order);
151
+ yield repos.order.createIfNotExist(Object.assign(Object.assign({}, order), { discounts: [], acceptedOffers: [] }));
128
152
  }
129
153
  catch (error) {
130
154
  // actionにエラー結果を追加
@@ -138,12 +162,8 @@ function placeOrderWithoutTransaction(params) {
138
162
  throw error;
139
163
  }
140
164
  yield repos.action.complete({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
141
- // 経理レポートを保管
142
- yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
143
- // await onOrderStatusChanged({ order: <factory.order.IOrder>order })({
144
- // registerActionInProgress: repos.registerActionInProgress,
145
- // task: repos.task
146
- // });
165
+ // 経理レポートを保管は外部注文の場合保留(2023-12-08~)
166
+ // await createAccountingReportIfNotExist(order)({ accountingReport: repos.accountingReport });
147
167
  });
148
168
  }
149
169
  exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
@@ -226,19 +246,42 @@ function placeOrder(params) {
226
246
  yield (0, createAccountingReportIfNotExist_1.createAccountingReportIfNotExist)(order)({ accountingReport: repos.accountingReport });
227
247
  // PaymentDueであればonOrderStatusChangedを実行(2023-08-23~)
228
248
  if (order.orderStatus === factory.orderStatus.OrderPaymentDue) {
229
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
230
- registerActionInProgress: repos.registerActionInProgress,
249
+ yield (0, onOrderStatusChanged_1.onOrderPaymentDue)({
250
+ order: {
251
+ paymentMethods: order.paymentMethods,
252
+ project: order.project,
253
+ orderNumber: order.orderNumber,
254
+ confirmationNumber: order.confirmationNumber,
255
+ customer: order.customer,
256
+ orderDate: order.orderDate,
257
+ seller: order.seller,
258
+ typeOf: order.typeOf,
259
+ price: order.price,
260
+ priceCurrency: order.priceCurrency,
261
+ orderStatus: order.orderStatus
262
+ }
263
+ })({
231
264
  task: repos.task
232
265
  });
233
266
  }
234
267
  else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
235
268
  // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
236
269
  // OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
237
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
238
- order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderPaymentDue }),
239
- placeOrderTransaction
270
+ yield (0, onOrderStatusChanged_1.onOrderPaymentDue)({
271
+ order: {
272
+ paymentMethods: order.paymentMethods,
273
+ project: order.project,
274
+ orderNumber: order.orderNumber,
275
+ confirmationNumber: order.confirmationNumber,
276
+ customer: order.customer,
277
+ orderDate: order.orderDate,
278
+ seller: order.seller,
279
+ typeOf: order.typeOf,
280
+ price: order.price,
281
+ priceCurrency: order.priceCurrency,
282
+ orderStatus: factory.orderStatus.OrderPaymentDue
283
+ }
240
284
  })({
241
- registerActionInProgress: repos.registerActionInProgress,
242
285
  task: repos.task
243
286
  });
244
287
  }
@@ -1,5 +1,5 @@
1
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
1
2
  import type { MongoRepository as ActionRepo } from '../../repo/action';
2
- import type { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
3
3
  import type { MongoRepository as OrderRepo } from '../../repo/order';
4
4
  import type { MongoRepository as OwnershipInfoRepo } from '../../repo/ownershipInfo';
5
5
  import type { MongoRepository as TaskRepo } from '../../repo/task';
@@ -16,11 +16,11 @@ declare function returnOrder(params: {
16
16
  };
17
17
  useOnOrderStatusChanged: boolean;
18
18
  }): (repos: {
19
+ acceptedOffer: AcceptedOfferRepo;
19
20
  action: ActionRepo;
20
21
  order: OrderRepo;
21
22
  ownershipInfo: OwnershipInfoRepo;
22
23
  task: TaskRepo;
23
24
  transaction: TransactionRepo;
24
- registerServiceInProgress: RegisterServiceInProgressRepo;
25
25
  }) => Promise<void>;
26
26
  export { returnOrder };
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.returnOrder = void 0;
13
+ const createDebug = require("debug");
13
14
  const order_1 = require("../../factory/order");
14
- const factory_1 = require("../delivery/factory");
15
15
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
16
16
  const factory = require("../../factory");
17
+ const debug = createDebug('chevre-domain:service:order');
17
18
  function returnOrder(params) {
18
19
  // tslint:disable-next-line:max-func-body-length
19
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
@@ -28,7 +29,10 @@ function returnOrder(params) {
28
29
  let order = yield repos.order.findByOrderNumber({
29
30
  orderNumber,
30
31
  project: { id: params.project.id },
31
- inclusion: [],
32
+ inclusion: [
33
+ 'project', 'typeOf', 'orderNumber', 'dateReturned', 'id',
34
+ 'customer', 'returner', 'seller', 'price', 'priceCurrency', 'orderDate'
35
+ ],
32
36
  exclusion: []
33
37
  });
34
38
  // 返品取引検索
@@ -39,7 +43,7 @@ function returnOrder(params) {
39
43
  typeOf: factory.transactionType.ReturnOrder,
40
44
  statuses: [factory.transactionStatusType.Confirmed],
41
45
  object: { order: { orderNumbers: [orderNumber] } },
42
- inclusion: [],
46
+ inclusion: ['id', 'typeOf', 'potentialActions'],
43
47
  exclusion: []
44
48
  });
45
49
  const returnOrderTransaction = returnOrderTransactions.shift();
@@ -66,13 +70,15 @@ function returnOrder(params) {
66
70
  project: order.project,
67
71
  recipient: order.seller,
68
72
  typeOf: factory.actionType.ReturnAction
69
- // ...(params.potentialActions !== undefined) ? { potentialActions: params.potentialActions } : undefined
70
73
  };
71
74
  let returnedOwnershipInfos = [];
72
75
  // アクション開始
73
76
  const action = yield repos.action.start(returnOrderActionAttributes);
74
77
  try {
75
- returnedOwnershipInfos = yield processReturnOrder(order, dateReturned)({ ownershipInfo: repos.ownershipInfo });
78
+ returnedOwnershipInfos = yield processReturnOrder(order, dateReturned)({
79
+ acceptedOffer: repos.acceptedOffer,
80
+ ownershipInfo: repos.ownershipInfo
81
+ });
76
82
  // 注文ステータス変更
77
83
  order = yield repos.order.returnOrder({
78
84
  project: { id: order.project.id },
@@ -80,6 +86,7 @@ function returnOrder(params) {
80
86
  dateReturned,
81
87
  returner
82
88
  });
89
+ debug('repos.order.returnOrder processed. returnedOrder:', order);
83
90
  }
84
91
  catch (error) {
85
92
  // actionにエラー結果を追加
@@ -95,24 +102,38 @@ function returnOrder(params) {
95
102
  const result = returnedOwnershipInfos;
96
103
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: result });
97
104
  if (params.useOnOrderStatusChanged) {
98
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, returnOrderTransaction })({
99
- registerActionInProgress: repos.registerServiceInProgress,
105
+ yield (0, onOrderStatusChanged_1.onOrderReturned)({
106
+ order: {
107
+ project: order.project,
108
+ typeOf: order.typeOf,
109
+ orderNumber: order.orderNumber,
110
+ dateReturned: order.dateReturned,
111
+ id: order.id,
112
+ customer: order.customer,
113
+ returner: order.returner,
114
+ seller: order.seller,
115
+ price: order.price,
116
+ priceCurrency: order.priceCurrency,
117
+ orderDate: order.orderDate,
118
+ orderStatus: factory.orderStatus.OrderReturned
119
+ },
120
+ returnOrderTransaction
121
+ })({
122
+ acceptedOffer: repos.acceptedOffer,
100
123
  task: repos.task
101
124
  });
102
125
  }
103
- // 潜在アクション
104
- // onOrderStatusChangedへ移行(2023-08-19~)
105
- // await onReturn(returnOrderActionAttributes)({ task: repos.task });
106
126
  });
107
127
  }
108
128
  exports.returnOrder = returnOrder;
109
129
  function processReturnOrder(order, dateReturned) {
110
130
  return (repos) => __awaiter(this, void 0, void 0, function* () {
111
131
  const returnedOwnershipInfos = [];
112
- // tslint:disable-next-line:no-suspicious-comment
113
- // TODO 注文配送によって発生した所有権の特定を他の方法で行えないか?
114
132
  // 所有権の所有期間変更
115
- const ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({ order });
133
+ // 注文オファーリポジトリから所有権識別子を検索する(2023-12-07~)
134
+ const ownershipInfos = yield repos.acceptedOffer.aggreateOwnershipInfosByOrder({ orderNumber: { $eq: order.orderNumber } });
135
+ // const ownershipInfos = createOwnershipInfosFromOrder({ order });
136
+ debug('processing findByIdentifierAndUpdateOwnedThrough...', ownershipInfos);
116
137
  if (Array.isArray(ownershipInfos)) {
117
138
  yield Promise.all(ownershipInfos.map((ownershipInfo) => __awaiter(this, void 0, void 0, function* () {
118
139
  const ownershipInfoReturned = yield repos.ownershipInfo.findByIdentifierAndUpdateOwnedThrough({
@@ -1,15 +1,15 @@
1
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
1
2
  import type { MongoRepository as ActionRepo } from '../../repo/action';
2
- import type { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
3
3
  import type { MongoRepository as OrderRepo } from '../../repo/order';
4
4
  import type { MongoRepository as OwnershipInfoRepo } from '../../repo/ownershipInfo';
5
5
  import type { MongoRepository as TaskRepo } from '../../repo/task';
6
6
  import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
7
7
  import * as factory from '../../factory';
8
8
  type ISendOperation<T> = (repos: {
9
+ acceptedOffer: AcceptedOfferRepo;
9
10
  action: ActionRepo;
10
11
  order: OrderRepo;
11
12
  ownershipInfo: OwnershipInfoRepo;
12
- registerActionInProgress: RegisterServiceInProgressRepo;
13
13
  task: TaskRepo;
14
14
  transaction: TransactionRepo;
15
15
  }) => Promise<T>;
@@ -37,7 +37,7 @@ function sendOrder(params) {
37
37
  let order = yield repos.order.findByOrderNumber({
38
38
  orderNumber,
39
39
  project: { id: params.project.id },
40
- inclusion: [],
40
+ inclusion: ['confirmationNumber', 'project', 'typeOf', 'seller', 'orderNumber', 'price', 'priceCurrency', 'orderDate', 'customer', '_id'],
41
41
  exclusion: []
42
42
  });
43
43
  // プロジェクト条件検証
@@ -76,7 +76,12 @@ function sendOrder(params) {
76
76
  let ownershipInfos;
77
77
  try {
78
78
  // 所有権作成
79
- ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({ order });
79
+ ownershipInfos = (0, factory_1.createOwnershipInfosFromOrder)({
80
+ order: Object.assign(Object.assign({}, order), { acceptedOffers: yield repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
81
+ orderNumber: { $eq: order.orderNumber },
82
+ project: { id: { $eq: order.project.id } }
83
+ }) })
84
+ });
80
85
  ownershipInfos = yield Promise.all(ownershipInfos.map((ownershipInfo) => __awaiter(this, void 0, void 0, function* () {
81
86
  return repos.ownershipInfo.createIfNotExistByIdentifier(ownershipInfo);
82
87
  })));
@@ -100,8 +105,18 @@ function sendOrder(params) {
100
105
  const result = ownershipInfos;
101
106
  yield repos.action.complete({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
102
107
  if (params.useOnOrderStatusChanged) {
103
- yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({ order, placeOrderTransaction })({
104
- registerActionInProgress: repos.registerActionInProgress,
108
+ yield (0, onOrderStatusChanged_1.onOrderDelivered)({
109
+ order: {
110
+ id: order.id,
111
+ customer: order.customer,
112
+ orderDate: order.orderDate,
113
+ orderNumber: order.orderNumber,
114
+ project: order.project,
115
+ typeOf: order.typeOf,
116
+ orderStatus: factory.orderStatus.OrderDelivered
117
+ },
118
+ placeOrderTransaction
119
+ })({
105
120
  task: repos.task
106
121
  });
107
122
  }
@@ -122,8 +137,6 @@ function sendOrder(params) {
122
137
  throw error;
123
138
  }
124
139
  }
125
- // onOrderStatusChangedへ移行(2023-08-17~)
126
- // await onSend(params)({ task: repos.task });
127
140
  });
128
141
  }
129
142
  exports.sendOrder = sendOrder;
@@ -4,9 +4,9 @@
4
4
  import { confirmPayTransaction } from './order/confirmPayTransaction';
5
5
  import { deleteOrder } from './order/deleteOrder';
6
6
  import { onAssetTransactionStatusChanged, paymentDue2Processing } from './order/onAssetTransactionStatusChanged';
7
- import { onOrderStatusChanged } from './order/onOrderStatusChanged';
7
+ import { onOrderProcessing } from './order/onOrderStatusChanged';
8
8
  import { onOrderUpdated } from './order/onOrderUpdated';
9
9
  import { payOrder } from './order/payOrder';
10
10
  import { placeOrder, placeOrderWithoutTransaction } from './order/placeOrder';
11
11
  import { sendOrder } from './order/sendOrder';
12
- export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderStatusChanged, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
12
+ export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderProcessing, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.paymentDue2Processing = exports.onOrderUpdated = exports.onOrderStatusChanged = exports.onAssetTransactionStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
3
+ exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.payOrder = exports.paymentDue2Processing = exports.onOrderUpdated = exports.onOrderProcessing = exports.onAssetTransactionStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
4
4
  /**
5
5
  * 注文サービス
6
6
  */
@@ -12,7 +12,7 @@ const onAssetTransactionStatusChanged_1 = require("./order/onAssetTransactionSta
12
12
  Object.defineProperty(exports, "onAssetTransactionStatusChanged", { enumerable: true, get: function () { return onAssetTransactionStatusChanged_1.onAssetTransactionStatusChanged; } });
13
13
  Object.defineProperty(exports, "paymentDue2Processing", { enumerable: true, get: function () { return onAssetTransactionStatusChanged_1.paymentDue2Processing; } });
14
14
  const onOrderStatusChanged_1 = require("./order/onOrderStatusChanged");
15
- Object.defineProperty(exports, "onOrderStatusChanged", { enumerable: true, get: function () { return onOrderStatusChanged_1.onOrderStatusChanged; } });
15
+ Object.defineProperty(exports, "onOrderProcessing", { enumerable: true, get: function () { return onOrderStatusChanged_1.onOrderProcessing; } });
16
16
  const onOrderUpdated_1 = require("./order/onOrderUpdated");
17
17
  Object.defineProperty(exports, "onOrderUpdated", { enumerable: true, get: function () { return onOrderUpdated_1.onOrderUpdated; } });
18
18
  const payOrder_1 = require("./order/payOrder");
@@ -114,7 +114,7 @@ function processVoidPayTransaction(params) {
114
114
  transaction = (yield repos.transaction.findById({
115
115
  typeOf: params.purpose.typeOf,
116
116
  id: params.purpose.id,
117
- inclusion: ['_id', 'typeOf', 'status', 'result.order.paymentMethods']
117
+ inclusion: ['_id', 'typeOf', 'status', 'result']
118
118
  }));
119
119
  }
120
120
  // 承認アクションを取得
@@ -15,12 +15,11 @@ function getCredentials(params) {
15
15
  return (repos) => __awaiter(this, void 0, void 0, function* () {
16
16
  var _a, _b, _c;
17
17
  // 決済サービスからcredentialsを取得する
18
- const paymentServices = yield repos.product.search({
18
+ const paymentServices = yield repos.product.searchPaymentServices({
19
19
  limit: 1,
20
20
  page: 1,
21
21
  project: { id: { $eq: params.seller.project.id } },
22
22
  typeOf: { $eq: factory.service.paymentService.PaymentServiceType.MovieTicket },
23
- // serviceType: { codeValue: { $eq: params.paymentMethodType } },
24
23
  id: { $eq: params.paymentServiceId }
25
24
  }, [], []);
26
25
  const paymentService = paymentServices.shift();
@@ -79,8 +79,15 @@ function validatePaymentMethod(params, paymentServiceId) {
79
79
  throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
80
80
  }
81
81
  // プロダクトから通貨区分を取得
82
- const paymentCatdProduct = yield repos.product.findById({ id: paymentServiceId }, ['serviceOutput'], []);
83
- const currency = (_e = (_d = paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
82
+ // const paymentCatdProduct = <Pick<factory.product.IProduct, 'serviceOutput'>>
83
+ // await repos.product.findProductById({ id: paymentServiceId }, ['serviceOutput'], []);
84
+ const paymentCatdProduct = (yield repos.product.searchProducts({
85
+ limit: 1,
86
+ page: 1,
87
+ id: { $eq: paymentServiceId },
88
+ typeOf: { $eq: factory.product.ProductType.PaymentCard }
89
+ }, ['serviceOutput'], [])).shift();
90
+ const currency = (_e = (_d = paymentCatdProduct === null || paymentCatdProduct === void 0 ? void 0 : paymentCatdProduct.serviceOutput) === null || _d === void 0 ? void 0 : _d.amount) === null || _e === void 0 ? void 0 : _e.currency;
84
91
  if (typeof currency !== 'string') {
85
92
  throw new factory.errors.NotFound('product.serviceOutput.amount.currency');
86
93
  }
@@ -0,0 +1,21 @@
1
+ import * as factory from '../../factory';
2
+ import type { MongoRepository as AcceptedOfferRepo } from '../../repo/acceptedOffer';
3
+ import type { MongoRepository as OrderRepo } from '../../repo/order';
4
+ import type { MongoRepository as ReservationRepo } from '../../repo/reservation';
5
+ type IReservationResult = Pick<factory.reservation.IReservation<factory.reservationType>, 'id' | 'additionalTicketText' | 'reservationStatus'>;
6
+ declare function searchByOrder(params: {
7
+ limit: number;
8
+ page: number;
9
+ typeOf: factory.reservationType;
10
+ project: {
11
+ id: string;
12
+ };
13
+ orderNumber: string;
14
+ }): (repos: {
15
+ acceptedOffer: AcceptedOfferRepo;
16
+ order: OrderRepo;
17
+ reservation: ReservationRepo;
18
+ }) => Promise<{
19
+ reservations: IReservationResult[];
20
+ }>;
21
+ export { searchByOrder };
@@ -0,0 +1,113 @@
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.searchByOrder = void 0;
13
+ const COA = require("@motionpicture/coa-service");
14
+ const google_libphonenumber_1 = require("google-libphonenumber");
15
+ const factory = require("../../factory");
16
+ const credentials_1 = require("../../credentials");
17
+ const coaAuthClient = new COA.auth.RefreshToken({
18
+ endpoint: credentials_1.credentials.coa.endpoint,
19
+ refreshToken: credentials_1.credentials.coa.refreshToken
20
+ });
21
+ function searchByOrder(params) {
22
+ // tslint:disable-next-line:max-func-body-length
23
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
24
+ const reservationType = params.typeOf;
25
+ const acceptedOffers = yield repos.acceptedOffer.searchAcceptedOffersByOrderNumber({
26
+ limit: params.limit,
27
+ page: params.page,
28
+ project: { id: { $eq: params.project.id } },
29
+ orderNumber: { $eq: params.orderNumber },
30
+ acceptedOffers: { itemOffered: { typeOf: { $in: [reservationType] } } }
31
+ }, ['itemOffered']);
32
+ const reservationIds = acceptedOffers.map((offer) => {
33
+ if (offer.itemOffered.typeOf === reservationType) {
34
+ return offer.itemOffered.id;
35
+ }
36
+ else {
37
+ // 検索条件にreservationTypeを含めているので、ありえないケース
38
+ throw new factory.errors.ServiceUnavailable(`unexpected itemOffered.typeOf ${offer.itemOffered.typeOf}`);
39
+ }
40
+ });
41
+ const offeredThroughIdentifier = (yield repos.acceptedOffer.distinctValues({
42
+ orderNumber: { $in: [params.orderNumber] }
43
+ }, 'acceptedOffers.offeredThrough.identifier')).shift();
44
+ let reservations = [];
45
+ if (reservationIds.length > 0) {
46
+ switch (offeredThroughIdentifier) {
47
+ // COA対応
48
+ case factory.service.webAPI.Identifier.COA:
49
+ const order = (yield repos.order.search({
50
+ limit: 1,
51
+ page: 1,
52
+ orderNumbers: [params.orderNumber]
53
+ }, { customer: 1 })).shift();
54
+ if (order === undefined) {
55
+ throw new factory.errors.NotFound(factory.order.OrderType.Order);
56
+ }
57
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
58
+ const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
59
+ let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
60
+ // COAでは数字のみ受け付けるので数字以外を除去
61
+ telNum = telNum.replace(/[^\d]/g, '');
62
+ const reservationNumber = (yield repos.acceptedOffer.distinctValues({
63
+ orderNumber: { $in: [params.orderNumber] }
64
+ }, 'acceptedOffers.itemOffered.reservationNumber')).shift();
65
+ const superEventLocationBranchCode = (yield repos.acceptedOffer.distinctValues({
66
+ orderNumber: { $in: [params.orderNumber] }
67
+ }, 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode')).shift();
68
+ if (typeof reservationNumber !== 'string') {
69
+ throw new factory.errors.NotFound('acceptedOffers.itemOffered.reservationNumber');
70
+ }
71
+ if (typeof superEventLocationBranchCode !== 'string') {
72
+ throw new factory.errors.NotFound('acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode');
73
+ }
74
+ const reserveService = new COA.service.Reserve({
75
+ endpoint: credentials_1.credentials.coa.endpoint,
76
+ auth: coaAuthClient
77
+ }, { timeout: credentials_1.credentials.coa.timeout });
78
+ const stateReserveResult = yield reserveService.stateReserve({
79
+ theaterCode: superEventLocationBranchCode,
80
+ reserveNum: reservationNumber,
81
+ telNum
82
+ });
83
+ const listTicket = stateReserveResult === null || stateReserveResult === void 0 ? void 0 : stateReserveResult.listTicket;
84
+ if (Array.isArray(listTicket)) {
85
+ reservations = listTicket.map((ticket, key) => {
86
+ return {
87
+ id: reservationIds[key],
88
+ reservationStatus: factory.reservationStatusType.ReservationConfirmed,
89
+ additionalTicketText: ticket.seatQrcode
90
+ };
91
+ });
92
+ }
93
+ else {
94
+ reservations = reservationIds.map((reservationId) => {
95
+ return {
96
+ id: reservationId,
97
+ reservationStatus: factory.reservationStatusType.ReservationCancelled
98
+ };
99
+ });
100
+ }
101
+ break;
102
+ default:
103
+ reservations = yield repos.reservation.search({
104
+ project: { id: { $eq: params.project.id } },
105
+ typeOf: reservationType,
106
+ id: { $in: reservationIds }
107
+ }, { id: 1, additionalTicketText: 1, reservationStatus: 1 });
108
+ }
109
+ }
110
+ return { reservations };
111
+ });
112
+ }
113
+ exports.searchByOrder = searchByOrder;
@@ -38,17 +38,6 @@ function verifyToken4reservation(params) {
38
38
  default:
39
39
  throw new factory.errors.Argument('token', `invalid orderStatus '${order.orderStatus}'`);
40
40
  }
41
- // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
42
- // const reservationExistsInOrder = acceptedOffers.some((offer) => {
43
- // return (
44
- // offer.itemOffered.typeOf === factory.reservationType.EventReservation
45
- // || offer.itemOffered.typeOf === factory.reservationType.BusReservation
46
- // )
47
- // && offer.itemOffered.id === params.reservationId;
48
- // });
49
- // if (!reservationExistsInOrder) {
50
- // throw new factory.errors.NotFound('AcceptedOffer');
51
- // }
52
41
  break;
53
42
  default:
54
43
  throw new factory.errors.NotImplemented(`Payload type ${payload.typeOf} not implemented`);
@@ -5,6 +5,7 @@ import { maskUnderName } from './reserve/factory';
5
5
  import { cancelPendingReservation, cancelReservation } from './reserve/cancelReservation';
6
6
  import { checkInReservation } from './reserve/checkInReservation';
7
7
  import { confirmReservation } from './reserve/confirmReservation';
8
+ import { searchByOrder } from './reserve/searchByOrder';
8
9
  import { useReservation } from './reserve/useReservation';
9
10
  import { verifyToken4reservation } from './reserve/verifyToken4reservation';
10
- export { maskUnderName, cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, useReservation, verifyToken4reservation };
11
+ export { maskUnderName, cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, searchByOrder, useReservation, verifyToken4reservation };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyToken4reservation = exports.useReservation = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
3
+ exports.verifyToken4reservation = exports.useReservation = exports.searchByOrder = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = exports.maskUnderName = void 0;
4
4
  /**
5
5
  * 予約サービス
6
6
  */
@@ -13,6 +13,8 @@ const checkInReservation_1 = require("./reserve/checkInReservation");
13
13
  Object.defineProperty(exports, "checkInReservation", { enumerable: true, get: function () { return checkInReservation_1.checkInReservation; } });
14
14
  const confirmReservation_1 = require("./reserve/confirmReservation");
15
15
  Object.defineProperty(exports, "confirmReservation", { enumerable: true, get: function () { return confirmReservation_1.confirmReservation; } });
16
+ const searchByOrder_1 = require("./reserve/searchByOrder");
17
+ Object.defineProperty(exports, "searchByOrder", { enumerable: true, get: function () { return searchByOrder_1.searchByOrder; } });
16
18
  const useReservation_1 = require("./reserve/useReservation");
17
19
  Object.defineProperty(exports, "useReservation", { enumerable: true, get: function () { return useReservation_1.useReservation; } });
18
20
  const verifyToken4reservation_1 = require("./reserve/verifyToken4reservation");
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const factory = require("../../factory");
14
+ const acceptedOffer_1 = require("../../repo/acceptedOffer");
14
15
  const accountingReport_1 = require("../../repo/accountingReport");
15
16
  const action_1 = require("../../repo/action");
16
17
  const assetTransaction_1 = require("../../repo/assetTransaction");
@@ -30,6 +31,7 @@ function call(data) {
30
31
  throw new factory.errors.Argument('settings', 'redisClient required');
31
32
  }
32
33
  yield (0, confirmPayTransaction_1.confirmPayTransaction)(data)({
34
+ acceptedOffer: new acceptedOffer_1.MongoRepository(settings.connection),
33
35
  action: new action_1.MongoRepository(settings.connection),
34
36
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
35
37
  order: new order_1.MongoRepository(settings.connection),
@@ -37,7 +39,6 @@ function call(data) {
37
39
  event: new event_1.MongoRepository(settings.connection),
38
40
  product: new product_1.MongoRepository(settings.connection),
39
41
  project: new project_1.MongoRepository(settings.connection),
40
- // seller: new SellerRepo(settings.connection),
41
42
  task: new task_1.MongoRepository(settings.connection),
42
43
  transaction: new transaction_1.MongoRepository(settings.connection)
43
44
  });
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
+ const acceptedOffer_1 = require("../../repo/acceptedOffer");
13
14
  const accountingReport_1 = require("../../repo/accountingReport");
14
15
  const action_1 = require("../../repo/action");
15
16
  const assetTransaction_1 = require("../../repo/assetTransaction");
@@ -26,6 +27,7 @@ const TransactionService = require("../transaction");
26
27
  function call(data) {
27
28
  return (settings) => __awaiter(this, void 0, void 0, function* () {
28
29
  yield TransactionService.deleteTransaction(data)({
30
+ acceptedOffer: new acceptedOffer_1.MongoRepository(settings.connection),
29
31
  accountingReport: new accountingReport_1.MongoRepository(settings.connection),
30
32
  action: new action_1.MongoRepository(settings.connection),
31
33
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),