@chevre/domain 21.2.0-alpha.6 → 21.2.0-alpha.60

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 (232) hide show
  1. package/example/src/chevre/aggregation/aggregateSystem.ts +58 -31
  2. package/example/src/chevre/countDelayedTasks.ts +17 -0
  3. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  4. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  5. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  6. package/example/src/chevre/deleteTasksByName.ts +2 -1
  7. package/example/src/chevre/importEventsFromCOA.ts +3 -4
  8. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  9. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  10. package/example/src/chevre/saveTasks.ts +13 -10
  11. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  12. package/example/src/chevre/searchSendEmailActions.ts +44 -0
  13. package/example/src/chevre/task/executeTasks.ts +26 -0
  14. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  15. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  16. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  17. package/example/src/chevre/updateTransaction.ts +1 -1
  18. package/lib/chevre/credentials.d.ts +1 -0
  19. package/lib/chevre/credentials.js +2 -1
  20. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  21. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  22. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  23. package/lib/chevre/eventEmitter/task.js +25 -0
  24. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  25. package/lib/chevre/eventEmitter/transaction.js +25 -0
  26. package/lib/chevre/eventEmitter.d.ts +4 -0
  27. package/lib/chevre/eventEmitter.js +9 -0
  28. package/lib/chevre/index.d.ts +3 -2
  29. package/lib/chevre/index.js +5 -3
  30. package/lib/chevre/repo/account.js +0 -4
  31. package/lib/chevre/repo/accountTitle.js +0 -4
  32. package/lib/chevre/repo/accountTransaction.d.ts +3 -11
  33. package/lib/chevre/repo/accountTransaction.js +1 -58
  34. package/lib/chevre/repo/accountingReport.js +0 -4
  35. package/lib/chevre/repo/action.d.ts +29 -1
  36. package/lib/chevre/repo/action.js +32 -29
  37. package/lib/chevre/repo/additionalProperty.js +0 -4
  38. package/lib/chevre/repo/aggregation.js +0 -4
  39. package/lib/chevre/repo/assetTransaction.d.ts +23 -8
  40. package/lib/chevre/repo/assetTransaction.js +207 -68
  41. package/lib/chevre/repo/categoryCode.js +0 -4
  42. package/lib/chevre/repo/code.js +0 -4
  43. package/lib/chevre/repo/comment.d.ts +4 -1
  44. package/lib/chevre/repo/comment.js +20 -9
  45. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  46. package/lib/chevre/repo/confirmationNumber.js +3 -15
  47. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  48. package/lib/chevre/repo/creativeWork.js +0 -4
  49. package/lib/chevre/repo/customer.js +0 -4
  50. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  51. package/lib/chevre/repo/emailMessage.js +0 -4
  52. package/lib/chevre/repo/event.d.ts +5 -1
  53. package/lib/chevre/repo/event.js +0 -4
  54. package/lib/chevre/repo/member.js +0 -4
  55. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  56. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  57. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  58. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  59. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  60. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  61. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  62. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  63. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  64. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  65. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  66. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  67. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  68. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  69. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  70. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  71. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  72. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +3 -1
  73. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  74. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  75. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  76. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  77. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  78. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  79. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  80. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  82. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  83. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  84. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  85. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  86. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  87. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  88. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  89. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  90. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  91. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  92. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  93. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  94. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  95. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +74 -0
  96. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +45 -0
  97. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  98. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  99. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  100. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  101. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  102. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  103. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  104. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  105. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  106. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  107. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  108. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  109. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  110. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  111. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  112. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  113. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  114. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  115. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  116. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  117. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  118. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  119. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  120. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  121. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  122. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  123. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  124. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  125. package/lib/chevre/repo/offer.js +0 -5
  126. package/lib/chevre/repo/offerCatalog.js +0 -4
  127. package/lib/chevre/repo/offerItemCondition.d.ts +39 -0
  128. package/lib/chevre/repo/offerItemCondition.js +112 -0
  129. package/lib/chevre/repo/order.d.ts +25 -0
  130. package/lib/chevre/repo/order.js +5 -4
  131. package/lib/chevre/repo/ownershipInfo.js +0 -4
  132. package/lib/chevre/repo/permit.js +0 -4
  133. package/lib/chevre/repo/place.js +0 -4
  134. package/lib/chevre/repo/priceSpecification.js +0 -4
  135. package/lib/chevre/repo/product.js +0 -4
  136. package/lib/chevre/repo/project.js +0 -4
  137. package/lib/chevre/repo/reservation.js +0 -4
  138. package/lib/chevre/repo/role.js +0 -4
  139. package/lib/chevre/repo/seller.js +0 -4
  140. package/lib/chevre/repo/serviceOutput.js +0 -4
  141. package/lib/chevre/repo/stockHolder.js +30 -0
  142. package/lib/chevre/repo/task.d.ts +41 -2
  143. package/lib/chevre/repo/task.js +97 -12
  144. package/lib/chevre/repo/telemetry.js +0 -4
  145. package/lib/chevre/repo/transaction.d.ts +23 -3
  146. package/lib/chevre/repo/transaction.js +174 -58
  147. package/lib/chevre/repo/trip.js +0 -4
  148. package/lib/chevre/repository.d.ts +5 -2
  149. package/lib/chevre/repository.js +8 -4
  150. package/lib/chevre/service/aggregation/system.d.ts +67 -22
  151. package/lib/chevre/service/aggregation/system.js +101 -89
  152. package/lib/chevre/service/assetTransaction/cancelReservation.js +23 -25
  153. package/lib/chevre/service/assetTransaction/moneyTransfer.js +23 -21
  154. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +17 -1
  155. package/lib/chevre/service/assetTransaction/pay.js +32 -24
  156. package/lib/chevre/service/assetTransaction/refund.js +23 -21
  157. package/lib/chevre/service/assetTransaction/registerService.js +23 -22
  158. package/lib/chevre/service/assetTransaction/reserve.js +23 -21
  159. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  160. package/lib/chevre/service/assetTransaction.js +9 -5
  161. package/lib/chevre/service/event.js +3 -1
  162. package/lib/chevre/service/notification/factory.js +2 -2
  163. package/lib/chevre/service/notification.d.ts +3 -1
  164. package/lib/chevre/service/notification.js +41 -7
  165. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  166. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  167. package/lib/chevre/service/offer.js +1 -1
  168. package/lib/chevre/service/order/deleteOrder.js +8 -8
  169. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +25 -36
  170. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  171. package/lib/chevre/service/order/placeOrder.js +1 -1
  172. package/lib/chevre/service/order/returnOrder.js +1 -5
  173. package/lib/chevre/service/order/sendOrder.js +1 -1
  174. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  175. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  176. package/lib/chevre/service/payment/any.js +60 -10
  177. package/lib/chevre/service/payment/movieTicket/validation.d.ts +3 -2
  178. package/lib/chevre/service/payment/movieTicket/validation.js +12 -25
  179. package/lib/chevre/service/payment/movieTicket.d.ts +1 -1
  180. package/lib/chevre/service/payment/movieTicket.js +4 -3
  181. package/lib/chevre/service/product.js +1 -5
  182. package/lib/chevre/service/report/telemetry.d.ts +0 -11
  183. package/lib/chevre/service/report/telemetry.js +21 -24
  184. package/lib/chevre/service/reserve/cancelReservation.js +0 -2
  185. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +0 -3
  186. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +20 -20
  187. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -3
  188. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  189. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -3
  190. package/lib/chevre/service/reserve/useReservation.js +1 -8
  191. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  192. package/lib/chevre/service/task/deleteTransaction.js +10 -8
  193. package/lib/chevre/service/task/importOffersFromCOA.js +4 -0
  194. package/lib/chevre/service/task/returnPayTransaction.js +2 -12
  195. package/lib/chevre/service/task/voidReserveTransaction.js +3 -1
  196. package/lib/chevre/service/task.d.ts +9 -0
  197. package/lib/chevre/service/task.js +43 -4
  198. package/lib/chevre/service/transaction/deleteTransaction.d.ts +21 -0
  199. package/lib/chevre/service/transaction/deleteTransaction.js +226 -0
  200. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +11 -1
  201. package/lib/chevre/service/transaction/moneyTransfer/factory.js +3 -1
  202. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -0
  203. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +1 -1
  204. package/lib/chevre/service/transaction/moneyTransfer.js +9 -12
  205. package/lib/chevre/service/transaction/orderProgramMembership.js +2 -1
  206. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +42 -30
  207. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  208. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +1 -1
  209. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.d.ts +1 -0
  210. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  211. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +1 -0
  212. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  213. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +1 -0
  214. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.d.ts +3 -0
  215. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +7 -3
  216. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -0
  217. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -2
  218. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.d.ts +1 -1
  219. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +2 -2
  220. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +2 -1
  221. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +23 -17
  222. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +1 -3
  223. package/lib/chevre/service/transaction/placeOrderInProgress.js +22 -11
  224. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +10 -1
  225. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  226. package/lib/chevre/service/transaction.d.ts +8 -13
  227. package/lib/chevre/service/transaction.js +12 -145
  228. package/lib/chevre/settings.d.ts +6 -1
  229. package/lib/chevre/settings.js +17 -5
  230. package/package.json +5 -5
  231. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  232. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
@@ -13,13 +13,11 @@ exports.exportTasksById = exports.startAndConfirm = exports.confirm = exports.st
13
13
  /**
14
14
  * 予約取消取引サービス
15
15
  */
16
- const createDebug = require("debug");
17
16
  const moment = require("moment");
18
17
  const mongoose = require("mongoose");
19
18
  const factory = require("../../factory");
20
19
  const settings_1 = require("../../settings");
21
20
  const factory_1 = require("./cancelReservation/factory");
22
- const debug = createDebug('chevre-domain:service');
23
21
  function validateStartParams(params) {
24
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
25
23
  var _a, _b;
@@ -169,27 +167,29 @@ function exportTasksById(params) {
169
167
  });
170
168
  const potentialActions = transaction.potentialActions;
171
169
  const taskAttributes = [];
172
- // 資産取引削除タスクを作成
173
- const deleteTransactionTask = {
174
- project: transaction.project,
175
- name: factory.taskName.DeleteAssetTransaction,
176
- status: factory.taskStatus.Ready,
177
- runsAt: moment(transaction.endDate)
178
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
179
- .toDate(),
180
- remainingNumberOfTries: 3,
181
- numberOfTried: 0,
182
- executionResults: [],
183
- data: {
184
- object: {
185
- project: transaction.project,
186
- id: transaction.id,
187
- transactionNumber: transaction.transactionNumber,
188
- typeOf: transaction.typeOf
170
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
171
+ // 資産取引削除タスクを作成
172
+ const deleteTransactionTask = {
173
+ project: transaction.project,
174
+ name: factory.taskName.DeleteAssetTransaction,
175
+ status: factory.taskStatus.Ready,
176
+ runsAt: moment(transaction.endDate)
177
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
178
+ .toDate(),
179
+ remainingNumberOfTries: 3,
180
+ numberOfTried: 0,
181
+ executionResults: [],
182
+ data: {
183
+ object: {
184
+ project: transaction.project,
185
+ id: transaction.id,
186
+ transactionNumber: transaction.transactionNumber,
187
+ typeOf: transaction.typeOf
188
+ }
189
189
  }
190
- }
191
- };
192
- taskAttributes.push(deleteTransactionTask);
190
+ };
191
+ taskAttributes.push(deleteTransactionTask);
192
+ }
193
193
  switch (transaction.status) {
194
194
  case factory.transactionStatusType.Confirmed:
195
195
  // tslint:disable-next-line:no-single-line-block-comment
@@ -235,9 +235,7 @@ function exportTasksById(params) {
235
235
  default:
236
236
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
237
237
  }
238
- debug('taskAttributes prepared', taskAttributes);
239
- return repos.task.saveMany(taskAttributes);
240
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
238
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
241
239
  });
242
240
  }
243
241
  exports.exportTasksById = exportTasksById;
@@ -360,27 +360,29 @@ function exportTasksById(params) {
360
360
  });
361
361
  const potentialActions = transaction.potentialActions;
362
362
  const taskAttributes = [];
363
- // 資産取引削除タスクを作成
364
- const deleteTransactionTask = {
365
- project: transaction.project,
366
- name: factory.taskName.DeleteAssetTransaction,
367
- status: factory.taskStatus.Ready,
368
- runsAt: moment(transaction.endDate)
369
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
370
- .toDate(),
371
- remainingNumberOfTries: 3,
372
- numberOfTried: 0,
373
- executionResults: [],
374
- data: {
375
- object: {
376
- project: transaction.project,
377
- id: transaction.id,
378
- transactionNumber: transaction.transactionNumber,
379
- typeOf: transaction.typeOf
363
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
364
+ // 資産取引削除タスクを作成
365
+ const deleteTransactionTask = {
366
+ project: transaction.project,
367
+ name: factory.taskName.DeleteAssetTransaction,
368
+ status: factory.taskStatus.Ready,
369
+ runsAt: moment(transaction.endDate)
370
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
371
+ .toDate(),
372
+ remainingNumberOfTries: 3,
373
+ numberOfTried: 0,
374
+ executionResults: [],
375
+ data: {
376
+ object: {
377
+ project: transaction.project,
378
+ id: transaction.id,
379
+ transactionNumber: transaction.transactionNumber,
380
+ typeOf: transaction.typeOf
381
+ }
380
382
  }
381
- }
382
- };
383
- taskAttributes.push(deleteTransactionTask);
383
+ };
384
+ taskAttributes.push(deleteTransactionTask);
385
+ }
384
386
  // タスク実行日時バッファの指定があれば調整
385
387
  let taskRunsAt = new Date();
386
388
  if (typeof params.runsTasksAfterInSeconds === 'number') {
@@ -430,7 +432,7 @@ function exportTasksById(params) {
430
432
  default:
431
433
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
432
434
  }
433
- return repos.task.saveMany(taskAttributes);
435
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
434
436
  });
435
437
  }
436
438
  exports.exportTasksById = exportTasksById;
@@ -126,8 +126,9 @@ function createPayObjectServiceOutput(params) {
126
126
  if (Array.isArray(movieTickets)) {
127
127
  paymentServiceOutput = movieTickets.map((movieTicket) => {
128
128
  var _a;
129
+ const amount = movieTicket2amount(transaction, movieTicket);
129
130
  const reservation4invoice = movieTicket2reservation4invoice(movieTicket, order, String(paymentMethodType));
130
- return Object.assign({ identifier: movieTicket.identifier }, (typeof ((_a = reservation4invoice.priceSpecification) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
131
+ return Object.assign(Object.assign({ identifier: movieTicket.identifier }, (typeof (amount === null || amount === void 0 ? void 0 : amount.value) === 'number') ? { amount } : undefined), (typeof ((_a = reservation4invoice.priceSpecification) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
131
132
  ? {
132
133
  serviceOutput: reservation4invoice
133
134
  }
@@ -140,6 +141,21 @@ function createPayObjectServiceOutput(params) {
140
141
  }
141
142
  return paymentServiceOutput;
142
143
  }
144
+ function movieTicket2amount(transaction, movieTicket) {
145
+ var _a;
146
+ let amount;
147
+ const accountsReceivables = transaction.object.accountsReceivablesByServiceType;
148
+ if (Array.isArray(accountsReceivables)) {
149
+ const accountsReceivable = (_a = accountsReceivables.find((a) => a.serviceType === movieTicket.serviceType)) === null || _a === void 0 ? void 0 : _a.accountsReceivable;
150
+ if (typeof accountsReceivable === 'number') {
151
+ amount = {
152
+ typeOf: 'MonetaryAmount',
153
+ value: accountsReceivable
154
+ };
155
+ }
156
+ }
157
+ return amount;
158
+ }
143
159
  function reservationPriceComponent2invoicePriceComponent(component) {
144
160
  var _a;
145
161
  const accounting = (typeof ((_a = component.accounting) === null || _a === void 0 ? void 0 : _a.accountsReceivable) === 'number')
@@ -272,16 +272,22 @@ function processAuthorizeCreditCard(params, transaction, paymentServiceId) {
272
272
  }
273
273
  function processAuthorizeMovieTicket(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay) {
274
274
  return (repos) => __awaiter(this, void 0, void 0, function* () {
275
- const { accountId, checkResult, payAction } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
275
+ const { accountId, payAction, accountsReceivablesByServiceType } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
276
276
  return saveAuthorizeResult({
277
277
  id: transaction.id,
278
- update: Object.assign({ 'object.accountId': accountId, 'object.paymentMethod.accountId': accountId, 'object.payAction': payAction }, (checkResult !== undefined) ? { 'object.checkResult': checkResult } : undefined)
278
+ update: {
279
+ 'object.accountId': accountId,
280
+ 'object.paymentMethod.accountId': accountId,
281
+ 'object.payAction': payAction,
282
+ // 認証レスポンスより計上金額を保管(2023-05-15~)
283
+ 'object.accountsReceivablesByServiceType': accountsReceivablesByServiceType
284
+ }
279
285
  })(repos);
280
286
  });
281
287
  }
282
288
  function saveAuthorizeResult(params) {
283
289
  return (repos) => __awaiter(this, void 0, void 0, function* () {
284
- return repos.assetTransaction.findByIdAndUpdate(params);
290
+ return repos.assetTransaction.findByIdAndUpdateInProgress(params);
285
291
  });
286
292
  }
287
293
  /**
@@ -393,27 +399,29 @@ function exportTasksById(params) {
393
399
  });
394
400
  const potentialActions = transaction.potentialActions;
395
401
  const taskAttributes = [];
396
- // 資産取引削除タスクを作成
397
- const deleteTransactionTask = {
398
- project: transaction.project,
399
- name: factory.taskName.DeleteAssetTransaction,
400
- status: factory.taskStatus.Ready,
401
- runsAt: moment(transaction.endDate)
402
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
403
- .toDate(),
404
- remainingNumberOfTries: 3,
405
- numberOfTried: 0,
406
- executionResults: [],
407
- data: {
408
- object: {
409
- project: transaction.project,
410
- id: transaction.id,
411
- transactionNumber: transaction.transactionNumber,
412
- typeOf: transaction.typeOf
402
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
403
+ // 資産取引削除タスクを作成
404
+ const deleteTransactionTask = {
405
+ project: transaction.project,
406
+ name: factory.taskName.DeleteAssetTransaction,
407
+ status: factory.taskStatus.Ready,
408
+ runsAt: moment(transaction.endDate)
409
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
410
+ .toDate(),
411
+ remainingNumberOfTries: 3,
412
+ numberOfTried: 0,
413
+ executionResults: [],
414
+ data: {
415
+ object: {
416
+ project: transaction.project,
417
+ id: transaction.id,
418
+ transactionNumber: transaction.transactionNumber,
419
+ typeOf: transaction.typeOf
420
+ }
413
421
  }
414
- }
415
- };
416
- taskAttributes.push(deleteTransactionTask);
422
+ };
423
+ taskAttributes.push(deleteTransactionTask);
424
+ }
417
425
  // タスク実行日時バッファの指定があれば調整
418
426
  let taskRunsAt = new Date();
419
427
  if (typeof params.runsTasksAfterInSeconds === 'number') {
@@ -470,7 +478,7 @@ function exportTasksById(params) {
470
478
  default:
471
479
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
472
480
  }
473
- return repos.task.saveMany(taskAttributes);
481
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
474
482
  });
475
483
  }
476
484
  exports.exportTasksById = exportTasksById;
@@ -160,27 +160,29 @@ function exportTasksById(params) {
160
160
  });
161
161
  const potentialActions = transaction.potentialActions;
162
162
  const taskAttributes = [];
163
- // 資産取引削除タスクを作成
164
- const deleteTransactionTask = {
165
- project: transaction.project,
166
- name: factory.taskName.DeleteAssetTransaction,
167
- status: factory.taskStatus.Ready,
168
- runsAt: moment(transaction.endDate)
169
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
170
- .toDate(),
171
- remainingNumberOfTries: 3,
172
- numberOfTried: 0,
173
- executionResults: [],
174
- data: {
175
- object: {
176
- project: transaction.project,
177
- id: transaction.id,
178
- transactionNumber: transaction.transactionNumber,
179
- typeOf: transaction.typeOf
163
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
164
+ // 資産取引削除タスクを作成
165
+ const deleteTransactionTask = {
166
+ project: transaction.project,
167
+ name: factory.taskName.DeleteAssetTransaction,
168
+ status: factory.taskStatus.Ready,
169
+ runsAt: moment(transaction.endDate)
170
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
171
+ .toDate(),
172
+ remainingNumberOfTries: 3,
173
+ numberOfTried: 0,
174
+ executionResults: [],
175
+ data: {
176
+ object: {
177
+ project: transaction.project,
178
+ id: transaction.id,
179
+ transactionNumber: transaction.transactionNumber,
180
+ typeOf: transaction.typeOf
181
+ }
180
182
  }
181
- }
182
- };
183
- taskAttributes.push(deleteTransactionTask);
183
+ };
184
+ taskAttributes.push(deleteTransactionTask);
185
+ }
184
186
  // タスク実行日時バッファの指定があれば調整
185
187
  let taskRunsAt = new Date();
186
188
  if (typeof params.runsTasksAfterInSeconds === 'number') {
@@ -218,7 +220,7 @@ function exportTasksById(params) {
218
220
  default:
219
221
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
220
222
  }
221
- return repos.task.saveMany(taskAttributes);
223
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
222
224
  });
223
225
  }
224
226
  exports.exportTasksById = exportTasksById;
@@ -230,27 +230,29 @@ function exportTasksById(params) {
230
230
  });
231
231
  const potentialActions = transaction.potentialActions;
232
232
  const taskAttributes = [];
233
- // 資産取引削除タスクを作成
234
- const deleteTransactionTask = {
235
- project: transaction.project,
236
- name: factory.taskName.DeleteAssetTransaction,
237
- status: factory.taskStatus.Ready,
238
- runsAt: moment(transaction.endDate)
239
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
240
- .toDate(),
241
- remainingNumberOfTries: 3,
242
- numberOfTried: 0,
243
- executionResults: [],
244
- data: {
245
- object: {
246
- project: transaction.project,
247
- id: transaction.id,
248
- transactionNumber: transaction.transactionNumber,
249
- typeOf: transaction.typeOf
233
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
234
+ // 資産取引削除タスクを作成
235
+ const deleteTransactionTask = {
236
+ project: transaction.project,
237
+ name: factory.taskName.DeleteAssetTransaction,
238
+ status: factory.taskStatus.Ready,
239
+ runsAt: moment(transaction.endDate)
240
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
241
+ .toDate(),
242
+ remainingNumberOfTries: 3,
243
+ numberOfTried: 0,
244
+ executionResults: [],
245
+ data: {
246
+ object: {
247
+ project: transaction.project,
248
+ id: transaction.id,
249
+ transactionNumber: transaction.transactionNumber,
250
+ typeOf: transaction.typeOf
251
+ }
250
252
  }
251
- }
252
- };
253
- taskAttributes.push(deleteTransactionTask);
253
+ };
254
+ taskAttributes.push(deleteTransactionTask);
255
+ }
254
256
  const taskRunsAt = new Date();
255
257
  switch (transaction.status) {
256
258
  case factory.transactionStatusType.Confirmed:
@@ -301,8 +303,7 @@ function exportTasksById(params) {
301
303
  default:
302
304
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
303
305
  }
304
- return repos.task.saveMany(taskAttributes);
305
- // return Promise.all(taskAttributes.map(async (a) => repos.task.save(a)));
306
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
306
307
  });
307
308
  }
308
309
  exports.exportTasksById = exportTasksById;
@@ -773,27 +773,29 @@ function exportTasksById(params) {
773
773
  });
774
774
  const potentialActions = transaction.potentialActions;
775
775
  const taskAttributes = [];
776
- // 資産取引削除タスクを作成
777
- const deleteTransactionTask = {
778
- project: transaction.project,
779
- name: factory.taskName.DeleteAssetTransaction,
780
- status: factory.taskStatus.Ready,
781
- runsAt: moment(transaction.endDate)
782
- .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
783
- .toDate(),
784
- remainingNumberOfTries: 3,
785
- numberOfTried: 0,
786
- executionResults: [],
787
- data: {
788
- object: {
789
- project: transaction.project,
790
- id: transaction.id,
791
- transactionNumber: transaction.transactionNumber,
792
- typeOf: transaction.typeOf
776
+ if (settings_1.USE_DELETE_ASSET_TRANSACTION_TASK) {
777
+ // 資産取引削除タスクを作成
778
+ const deleteTransactionTask = {
779
+ project: transaction.project,
780
+ name: factory.taskName.DeleteAssetTransaction,
781
+ status: factory.taskStatus.Ready,
782
+ runsAt: moment(transaction.endDate)
783
+ .add(settings_1.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS, 'days')
784
+ .toDate(),
785
+ remainingNumberOfTries: 3,
786
+ numberOfTried: 0,
787
+ executionResults: [],
788
+ data: {
789
+ object: {
790
+ project: transaction.project,
791
+ id: transaction.id,
792
+ transactionNumber: transaction.transactionNumber,
793
+ typeOf: transaction.typeOf
794
+ }
793
795
  }
794
- }
795
- };
796
- taskAttributes.push(deleteTransactionTask);
796
+ };
797
+ taskAttributes.push(deleteTransactionTask);
798
+ }
797
799
  switch (transaction.status) {
798
800
  case factory.transactionStatusType.Confirmed:
799
801
  // tslint:disable-next-line:no-single-line-block-comment
@@ -860,7 +862,7 @@ function exportTasksById(params) {
860
862
  default:
861
863
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
862
864
  }
863
- return repos.task.saveMany(taskAttributes);
865
+ return repos.task.saveMany(taskAttributes, { emitImmediately: true });
864
866
  });
865
867
  }
866
868
  exports.exportTasksById = exportTasksById;
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import * as factory from '../factory';
5
5
  import { MongoRepository as AssetTransactionRepo } from '../repo/assetTransaction';
6
- import { MongoRepository as ProjectRepo } from '../repo/project';
7
6
  import { MongoRepository as TaskRepo } from '../repo/task';
8
7
  import * as CancelReservationTransactionService from './assetTransaction/cancelReservation';
9
8
  import * as MoneyTransferTransactionService from './assetTransaction/moneyTransfer';
@@ -29,8 +28,13 @@ export declare function exportTasks<T extends factory.assetTransactionType>(para
29
28
  typeOf?: {
30
29
  $in: T[];
31
30
  };
31
+ id?: string;
32
+ tasksExportAction?: {
33
+ agent: {
34
+ name: string;
35
+ };
36
+ };
32
37
  }): (repos: {
33
- project: ProjectRepo;
34
38
  task: TaskRepo;
35
39
  assetTransaction: AssetTransactionRepo;
36
40
  }) => Promise<{
@@ -20,6 +20,7 @@ const PayTransactionService = require("./assetTransaction/pay");
20
20
  const RefundTransactionService = require("./assetTransaction/refund");
21
21
  const RegisterServiceTransactionService = require("./assetTransaction/registerService");
22
22
  const ReserveTransactionService = require("./assetTransaction/reserve");
23
+ const settings_1 = require("../settings");
23
24
  exports.cancelReservation = CancelReservationTransactionService;
24
25
  exports.moneyTransfer = MoneyTransferTransactionService;
25
26
  exports.pay = PayTransactionService;
@@ -31,11 +32,14 @@ exports.reserve = ReserveTransactionService;
31
32
  */
32
33
  function exportTasks(params) {
33
34
  return (repos) => __awaiter(this, void 0, void 0, function* () {
34
- const transaction = yield repos.assetTransaction.startExportTasks({
35
- // project: params.project,
36
- typeOf: params.typeOf,
37
- status: params.status
38
- });
35
+ var _a;
36
+ const transaction = yield repos.assetTransaction.startExportTasks(Object.assign({ typeOf: params.typeOf, status: params.status, tasksExportAction: {
37
+ agent: {
38
+ name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
39
+ ? params.tasksExportAction.agent.name
40
+ : settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
41
+ }
42
+ } }, (typeof params.id === 'string') ? { id: params.id } : undefined));
39
43
  if (transaction === null) {
40
44
  return;
41
45
  }
@@ -127,7 +127,7 @@ function importFromCOA(params) {
127
127
  })(repos);
128
128
  savedScreeningEventSeriesCount = savedEventsCount;
129
129
  try {
130
- // イベントごとに永続化トライ
130
+ // イベント永続化
131
131
  const screeningEvents = yield saveScreeningEvents({
132
132
  locationBranchCode: params.locationBranchCode,
133
133
  movieTheater: movieTheater,
@@ -154,6 +154,8 @@ function importFromCOA(params) {
154
154
  // "message": "ESOCKETTIMEDOUT",
155
155
  if (error.name === 'COAServiceError') {
156
156
  if (error.message === 'ESOCKETTIMEDOUT') {
157
+ // tslint:disable-next-line:no-console
158
+ console.error('saveScreeningEvents throwed an error', error.name, error.message);
157
159
  throwsError = false;
158
160
  }
159
161
  }
@@ -12,7 +12,7 @@ function task2lineNotify(params) {
12
12
  const lastExecutionResult = (task.executionResults.length > 0) ? task.executionResults.slice(-1)[0] : undefined;
13
13
  let lastError = lastExecutionResult === null || lastExecutionResult === void 0 ? void 0 : lastExecutionResult.error;
14
14
  if (typeof lastError === 'string') {
15
- lastError = { message: lastError };
15
+ lastError = { message: lastError, name: 'Error' };
16
16
  }
17
17
  const lastMessage = `${String(lastError === null || lastError === void 0 ? void 0 : lastError.name)} ${String(lastError === null || lastError === void 0 ? void 0 : lastError.message)}`;
18
18
  const content = `project:${(_a = task.project) === null || _a === void 0 ? void 0 : _a.id}
@@ -38,7 +38,7 @@ function tasks2lineNotify(params) {
38
38
  const lastExecutionResult = (task.executionResults.length > 0) ? task.executionResults.slice(-1)[0] : undefined;
39
39
  let lastError = lastExecutionResult === null || lastExecutionResult === void 0 ? void 0 : lastExecutionResult.error;
40
40
  if (typeof lastError === 'string') {
41
- lastError = { message: lastError };
41
+ lastError = { message: lastError, name: 'Error' };
42
42
  }
43
43
  const lastMessage = `${String(lastError === null || lastError === void 0 ? void 0 : lastError.name)} ${String(lastError === null || lastError === void 0 ? void 0 : lastError.message)}`;
44
44
  return `project:${(_a = task.project) === null || _a === void 0 ? void 0 : _a.id}
@@ -1,7 +1,9 @@
1
1
  import * as factory from '../factory';
2
2
  import { MongoRepository as ActionRepo } from '../repo/action';
3
3
  import { MongoRepository as ProjectRepo } from '../repo/project';
4
- export type Operation<T> = () => Promise<T>;
4
+ export type Operation<T> = (repos: {
5
+ accessToken: string;
6
+ }) => Promise<T>;
5
7
  /**
6
8
  * Eメールメッセージを送信する
7
9
  * https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
@@ -111,15 +111,11 @@ exports.sendEmailMessage = sendEmailMessage;
111
111
  * https://notify-bot.line.me/doc/ja/
112
112
  */
113
113
  function report2developers(subject, content, imageThumbnail, imageFullsize) {
114
- return () => __awaiter(this, void 0, void 0, function* () {
114
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
115
115
  const LINE_NOTIFY_URL = credentials_1.credentials.lineNotify.url;
116
- const LINE_NOTIFY_ACCESS_TOKEN = credentials_1.credentials.lineNotify.accessToken;
117
116
  if (LINE_NOTIFY_URL === undefined) {
118
117
  throw new Error('Environment variable LINE_NOTIFY_URL not set');
119
118
  }
120
- if (LINE_NOTIFY_ACCESS_TOKEN === undefined) {
121
- throw new Error('Environment variable LINE_NOTIFY_ACCESS_TOKEN not set');
122
- }
123
119
  const message = `--------
124
120
  ${subject}
125
121
  --------
@@ -130,7 +126,7 @@ ${content}`;
130
126
  var _a;
131
127
  request.post({
132
128
  url: LINE_NOTIFY_URL,
133
- auth: { bearer: LINE_NOTIFY_ACCESS_TOKEN },
129
+ auth: { bearer: repos.accessToken },
134
130
  form: formData,
135
131
  json: true,
136
132
  timeout: (_a = settings_1.settings.webhook) === null || _a === void 0 ? void 0 : _a.timeout
@@ -154,6 +150,45 @@ ${content}`;
154
150
  exports.report2developers = report2developers;
155
151
  const USERNAME_ARGUMENT_REQUIRED_MESSAGE = 'Missing required key \'Username\' in params';
156
152
  function triggerWebhook(params) {
153
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
154
+ // retryableにする(2023-05-12~)
155
+ let retry = true;
156
+ let numberOfTry = 0;
157
+ while (numberOfTry >= 0) {
158
+ try {
159
+ numberOfTry += 1;
160
+ if (numberOfTry > settings_1.TRIGGER_WEBHOOK_MAX_RETRY_COUNT) {
161
+ retry = false;
162
+ }
163
+ // retryInterval
164
+ if (numberOfTry > 1) {
165
+ yield sleep(settings_1.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS * (numberOfTry - 1));
166
+ }
167
+ yield processInformAction(params)(repos);
168
+ break;
169
+ }
170
+ catch (error) {
171
+ if (retry) {
172
+ continue;
173
+ }
174
+ else {
175
+ throw error;
176
+ }
177
+ }
178
+ }
179
+ });
180
+ }
181
+ exports.triggerWebhook = triggerWebhook;
182
+ function sleep(waitTime) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ return new Promise((resolve) => {
185
+ setTimeout(() => {
186
+ resolve();
187
+ }, waitTime);
188
+ });
189
+ });
190
+ }
191
+ function processInformAction(params) {
157
192
  return (repos) => __awaiter(this, void 0, void 0, function* () {
158
193
  var _a, _b;
159
194
  // アクション開始
@@ -219,4 +254,3 @@ function triggerWebhook(params) {
219
254
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: result });
220
255
  });
221
256
  }
222
- exports.triggerWebhook = triggerWebhook;
@@ -5,6 +5,7 @@ import { RedisRepository as OfferRateLimitRepo } from '../../../repo/rateLimit/o
5
5
  import { MongoRepository as ReservationRepo } from '../../../repo/reservation';
6
6
  import { StockHolderRepository as StockHolderRepo } from '../../../repo/stockHolder';
7
7
  import { MongoRepository as TaskRepo } from '../../../repo/task';
8
+ import { MongoRepository as TransactionRepo } from '../../../repo/transaction';
8
9
  export import WebAPIIdentifier = factory.service.webAPI.Identifier;
9
10
  interface IVoidTransactionRepos {
10
11
  action: ActionRepo;
@@ -13,6 +14,7 @@ interface IVoidTransactionRepos {
13
14
  offerRateLimit: OfferRateLimitRepo;
14
15
  reservation: ReservationRepo;
15
16
  task: TaskRepo;
17
+ transaction: TransactionRepo;
16
18
  }
17
19
  /**
18
20
  * イベントオファー承認取消(タスクから実行)