@chevre/domain 21.2.0-alpha.1 → 21.2.0-alpha.100

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 (306) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +58 -31
  3. package/example/src/chevre/countDelayedTasks.ts +17 -0
  4. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  5. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  6. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  7. package/example/src/chevre/deleteTasksByName.ts +10 -2
  8. package/example/src/chevre/importEventsFromCOA.ts +3 -4
  9. package/example/src/chevre/lockStockHolder.ts +48 -0
  10. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  11. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  12. package/example/src/chevre/processPay.ts +5 -1
  13. package/example/src/chevre/processReserve.ts +6 -3
  14. package/example/src/chevre/saveTasks.ts +13 -10
  15. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  16. package/example/src/chevre/searchActions.ts +33 -0
  17. package/example/src/chevre/searchEventSeats.ts +42 -0
  18. package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +37 -1
  19. package/example/src/chevre/searchSendEmailActions.ts +44 -0
  20. package/example/src/chevre/task/executeTasks.ts +26 -0
  21. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  22. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  23. package/example/src/chevre/transaction/processReturnOrder.ts +40 -0
  24. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  25. package/example/src/chevre/updateTransaction.ts +1 -1
  26. package/example/src/playOnMoment.ts +24 -0
  27. package/lib/chevre/credentials.d.ts +1 -0
  28. package/lib/chevre/credentials.js +2 -1
  29. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  30. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  31. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  32. package/lib/chevre/eventEmitter/task.js +25 -0
  33. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  34. package/lib/chevre/eventEmitter/transaction.js +25 -0
  35. package/lib/chevre/eventEmitter.d.ts +4 -0
  36. package/lib/chevre/eventEmitter.js +9 -0
  37. package/lib/chevre/index.d.ts +3 -2
  38. package/lib/chevre/index.js +5 -3
  39. package/lib/chevre/repo/account.js +0 -4
  40. package/lib/chevre/repo/accountTitle.js +0 -4
  41. package/lib/chevre/repo/accountTransaction.d.ts +3 -11
  42. package/lib/chevre/repo/accountTransaction.js +1 -58
  43. package/lib/chevre/repo/accountingReport.js +0 -4
  44. package/lib/chevre/repo/action.d.ts +29 -1
  45. package/lib/chevre/repo/action.js +98 -59
  46. package/lib/chevre/repo/additionalProperty.js +0 -4
  47. package/lib/chevre/repo/aggregation.js +0 -4
  48. package/lib/chevre/repo/assetTransaction.d.ts +25 -9
  49. package/lib/chevre/repo/assetTransaction.js +261 -89
  50. package/lib/chevre/repo/categoryCode.js +0 -4
  51. package/lib/chevre/repo/code.js +0 -4
  52. package/lib/chevre/repo/comment.d.ts +4 -1
  53. package/lib/chevre/repo/comment.js +20 -9
  54. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  55. package/lib/chevre/repo/confirmationNumber.js +3 -15
  56. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  57. package/lib/chevre/repo/creativeWork.js +0 -4
  58. package/lib/chevre/repo/customer.js +0 -4
  59. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  60. package/lib/chevre/repo/emailMessage.js +0 -4
  61. package/lib/chevre/repo/event.d.ts +5 -1
  62. package/lib/chevre/repo/event.js +0 -4
  63. package/lib/chevre/repo/member.js +0 -4
  64. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  65. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  66. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  67. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  68. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  69. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  70. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  71. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  72. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  73. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  74. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  75. package/lib/chevre/repo/mongoose/schemas/action.js +20 -1
  76. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  77. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  78. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  79. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  80. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  81. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +33 -19
  82. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  83. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  84. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  85. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  86. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  87. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  88. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  89. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  90. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  91. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  92. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  93. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  94. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  95. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  96. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  97. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  98. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  99. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  100. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  101. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  102. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  103. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  104. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +74 -0
  105. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +45 -0
  106. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  107. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  108. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  109. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  110. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  111. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  112. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  113. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  114. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  115. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  116. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  117. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  118. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +64 -5
  119. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  120. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  121. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  122. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  123. package/lib/chevre/repo/mongoose/schemas/seller.js +7 -0
  124. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  125. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  126. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  127. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  128. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  129. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  130. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  131. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  132. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  133. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  134. package/lib/chevre/repo/offer.js +0 -5
  135. package/lib/chevre/repo/offerCatalog.js +0 -4
  136. package/lib/chevre/repo/offerItemCondition.d.ts +22 -0
  137. package/lib/chevre/repo/offerItemCondition.js +120 -0
  138. package/lib/chevre/repo/order.d.ts +55 -3
  139. package/lib/chevre/repo/order.js +56 -9
  140. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  141. package/lib/chevre/repo/orderNumber.js +2 -12
  142. package/lib/chevre/repo/ownershipInfo.js +0 -4
  143. package/lib/chevre/repo/permit.js +0 -4
  144. package/lib/chevre/repo/place.d.ts +5 -1
  145. package/lib/chevre/repo/place.js +1 -10
  146. package/lib/chevre/repo/priceSpecification.js +0 -4
  147. package/lib/chevre/repo/product.js +0 -4
  148. package/lib/chevre/repo/project.js +0 -4
  149. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -2
  150. package/lib/chevre/repo/rateLimit/offer.js +14 -14
  151. package/lib/chevre/repo/reservation.d.ts +12 -4
  152. package/lib/chevre/repo/reservation.js +16 -48
  153. package/lib/chevre/repo/role.js +0 -4
  154. package/lib/chevre/repo/seller.js +19 -23
  155. package/lib/chevre/repo/serviceOutput.js +0 -4
  156. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +2 -1
  157. package/lib/chevre/repo/serviceOutputIdentifier.js +14 -15
  158. package/lib/chevre/repo/{itemAvailability/screeningEvent.d.ts → stockHolder.d.ts} +5 -8
  159. package/lib/chevre/repo/stockHolder.js +273 -0
  160. package/lib/chevre/repo/task.d.ts +45 -2
  161. package/lib/chevre/repo/task.js +101 -12
  162. package/lib/chevre/repo/telemetry.js +0 -4
  163. package/lib/chevre/repo/transaction.d.ts +23 -3
  164. package/lib/chevre/repo/transaction.js +174 -58
  165. package/lib/chevre/repo/transactionNumber.d.ts +2 -1
  166. package/lib/chevre/repo/transactionNumber.js +14 -15
  167. package/lib/chevre/repo/trip.js +0 -4
  168. package/lib/chevre/repository.d.ts +8 -7
  169. package/lib/chevre/repository.js +12 -11
  170. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -2
  171. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +4 -3
  172. package/lib/chevre/service/aggregation/system.d.ts +67 -22
  173. package/lib/chevre/service/aggregation/system.js +101 -89
  174. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -28
  175. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -23
  176. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +17 -1
  177. package/lib/chevre/service/assetTransaction/pay.d.ts +5 -1
  178. package/lib/chevre/service/assetTransaction/pay.js +18 -32
  179. package/lib/chevre/service/assetTransaction/refund.js +1 -23
  180. package/lib/chevre/service/assetTransaction/registerService.js +1 -25
  181. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +15 -5
  182. package/lib/chevre/service/assetTransaction/reserve/factory.js +122 -58
  183. package/lib/chevre/service/assetTransaction/reserve.d.ts +14 -5
  184. package/lib/chevre/service/assetTransaction/reserve.js +156 -74
  185. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  186. package/lib/chevre/service/assetTransaction.js +9 -5
  187. package/lib/chevre/service/event.js +3 -1
  188. package/lib/chevre/service/notification/factory.js +2 -2
  189. package/lib/chevre/service/notification.d.ts +3 -1
  190. package/lib/chevre/service/notification.js +41 -7
  191. package/lib/chevre/service/offer/event/authorize.d.ts +5 -2
  192. package/lib/chevre/service/offer/event/authorize.js +8 -2
  193. package/lib/chevre/service/offer/event/cancel.d.ts +2 -2
  194. package/lib/chevre/service/offer/event/factory.d.ts +3 -0
  195. package/lib/chevre/service/offer/event/factory.js +16 -5
  196. package/lib/chevre/service/offer/event/voidTransaction.d.ts +4 -2
  197. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  198. package/lib/chevre/service/offer.d.ts +13 -26
  199. package/lib/chevre/service/offer.js +22 -117
  200. package/lib/chevre/service/order/deleteOrder.d.ts +3 -1
  201. package/lib/chevre/service/order/deleteOrder.js +8 -8
  202. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +5 -2
  203. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +41 -81
  204. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -3
  205. package/lib/chevre/service/order/onOrderUpdated.d.ts +16 -0
  206. package/lib/chevre/service/order/onOrderUpdated.js +22 -0
  207. package/lib/chevre/service/order/placeOrder.d.ts +1 -0
  208. package/lib/chevre/service/order/placeOrder.js +41 -24
  209. package/lib/chevre/service/order/returnOrder.d.ts +1 -0
  210. package/lib/chevre/service/order/returnOrder.js +7 -12
  211. package/lib/chevre/service/order/sendOrder.d.ts +1 -0
  212. package/lib/chevre/service/order/sendOrder.js +7 -10
  213. package/lib/chevre/service/order.d.ts +2 -1
  214. package/lib/chevre/service/order.js +3 -1
  215. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  216. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  217. package/lib/chevre/service/payment/any.d.ts +9 -5
  218. package/lib/chevre/service/payment/any.js +80 -18
  219. package/lib/chevre/service/payment/creditCard.d.ts +1 -1
  220. package/lib/chevre/service/payment/creditCard.js +21 -15
  221. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +7 -6
  222. package/lib/chevre/service/payment/movieTicket/validation.d.ts +6 -6
  223. package/lib/chevre/service/payment/movieTicket/validation.js +54 -31
  224. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  225. package/lib/chevre/service/payment/movieTicket.js +5 -4
  226. package/lib/chevre/service/product.js +1 -5
  227. package/lib/chevre/service/report/telemetry.d.ts +0 -11
  228. package/lib/chevre/service/report/telemetry.js +21 -24
  229. package/lib/chevre/service/reserve/cancelReservation.d.ts +8 -6
  230. package/lib/chevre/service/reserve/cancelReservation.js +153 -145
  231. package/lib/chevre/service/reserve/checkInReservation.d.ts +9 -4
  232. package/lib/chevre/service/reserve/checkInReservation.js +77 -3
  233. package/lib/chevre/service/reserve/confirmReservation.d.ts +7 -4
  234. package/lib/chevre/service/reserve/confirmReservation.js +125 -58
  235. package/lib/chevre/service/reserve/factory.d.ts +1 -1
  236. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +17 -5
  237. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +26 -24
  238. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -3
  239. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  240. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -3
  241. package/lib/chevre/service/reserve/useReservation.d.ts +7 -3
  242. package/lib/chevre/service/reserve/useReservation.js +61 -71
  243. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +15 -0
  244. package/lib/chevre/service/reserve/verifyToken4reservation.js +56 -0
  245. package/lib/chevre/service/reserve.d.ts +3 -2
  246. package/lib/chevre/service/reserve.js +4 -2
  247. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -2
  248. package/lib/chevre/service/task/cancelPendingReservation.js +8 -4
  249. package/lib/chevre/service/task/cancelReservation.js +3 -3
  250. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  251. package/lib/chevre/service/task/deleteTransaction.js +10 -8
  252. package/lib/chevre/service/task/importOffersFromCOA.js +4 -0
  253. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +7 -0
  254. package/lib/chevre/service/task/onAuthorizationCreated.js +108 -0
  255. package/lib/chevre/service/task/placeOrder.js +1 -1
  256. package/lib/chevre/service/task/reserve.js +10 -7
  257. package/lib/chevre/service/task/returnOrder.js +1 -1
  258. package/lib/chevre/service/task/returnPayTransaction.js +2 -12
  259. package/lib/chevre/service/task/sendOrder.js +1 -1
  260. package/lib/chevre/service/task/useReservation.d.ts +7 -0
  261. package/lib/chevre/service/task/useReservation.js +36 -0
  262. package/lib/chevre/service/task/voidReserveTransaction.js +6 -4
  263. package/lib/chevre/service/task.d.ts +9 -0
  264. package/lib/chevre/service/task.js +43 -4
  265. package/lib/chevre/service/transaction/deleteTransaction.d.ts +21 -0
  266. package/lib/chevre/service/transaction/deleteTransaction.js +232 -0
  267. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +11 -1
  268. package/lib/chevre/service/transaction/moneyTransfer/factory.js +3 -1
  269. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -0
  270. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +1 -1
  271. package/lib/chevre/service/transaction/moneyTransfer.js +9 -12
  272. package/lib/chevre/service/transaction/orderProgramMembership.js +6 -2
  273. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +42 -30
  274. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  275. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +1 -1
  276. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.d.ts +1 -0
  277. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  278. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +1 -0
  279. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  280. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +1 -0
  281. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.d.ts +3 -0
  282. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +7 -3
  283. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -0
  284. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -2
  285. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.d.ts +1 -1
  286. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +2 -2
  287. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +2 -1
  288. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +23 -17
  289. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +0 -3
  290. package/lib/chevre/service/transaction/placeOrderInProgress.js +22 -11
  291. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +10 -1
  292. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +25 -17
  293. package/lib/chevre/service/transaction/returnOrder.d.ts +4 -0
  294. package/lib/chevre/service/transaction/returnOrder.js +225 -35
  295. package/lib/chevre/service/transaction.d.ts +8 -13
  296. package/lib/chevre/service/transaction.js +12 -145
  297. package/lib/chevre/settings.d.ts +4 -1
  298. package/lib/chevre/settings.js +16 -6
  299. package/package.json +5 -5
  300. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  301. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
  302. package/lib/chevre/repo/itemAvailability/screeningEvent.js +0 -181
  303. package/lib/chevre/service/task/deleteAssetTransaction.d.ts +0 -12
  304. package/lib/chevre/service/task/deleteAssetTransaction.js +0 -65
  305. package/lib/chevre/service/task/deleteOrder.d.ts +0 -6
  306. package/lib/chevre/service/task/deleteOrder.js +0 -35
@@ -64,13 +64,10 @@ export declare class MongoRepository {
64
64
  typeOf: T;
65
65
  transactionNumber: string;
66
66
  }): Promise<factory.assetTransaction.ITransaction<T>>;
67
- /**
68
- * 取引を確定する
69
- */
70
67
  addReservations(params: {
71
68
  typeOf: factory.assetTransactionType.Reserve;
72
69
  id: string;
73
- object: factory.assetTransaction.reserve.IObject;
70
+ object: Pick<factory.assetTransaction.reserve.IObject, 'acceptedOffer' | 'issuedThrough' | 'reservationFor' | 'subReservation'>;
74
71
  }): Promise<factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>>;
75
72
  /**
76
73
  * 取引を確定する
@@ -78,9 +75,10 @@ export declare class MongoRepository {
78
75
  confirm<T extends factory.assetTransactionType>(params: {
79
76
  typeOf: T;
80
77
  id: string;
78
+ object?: Pick<factory.assetTransaction.reserve.IObject, 'underName'>;
81
79
  result: factory.assetTransaction.IResult<T>;
82
80
  potentialActions: factory.assetTransaction.IPotentialActions<T>;
83
- }): Promise<factory.assetTransaction.ITransaction<T>>;
81
+ }): Promise<void>;
84
82
  /**
85
83
  * 取引を開始&確定
86
84
  */
@@ -100,7 +98,13 @@ export declare class MongoRepository {
100
98
  $in: T[];
101
99
  };
102
100
  status: factory.transactionStatusType;
103
- }): Promise<factory.assetTransaction.ITransaction<T> | null>;
101
+ id?: string;
102
+ tasksExportAction: {
103
+ agent: {
104
+ name: string;
105
+ };
106
+ };
107
+ }): Promise<Pick<factory.assetTransaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
104
108
  /**
105
109
  * タスクエクスポートリトライ
106
110
  * TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
@@ -108,6 +112,16 @@ export declare class MongoRepository {
108
112
  reexportTasks(params: {
109
113
  intervalInMinutes: number;
110
114
  }): Promise<void>;
115
+ /**
116
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
117
+ */
118
+ exportTasks(params: {
119
+ now: Date;
120
+ delayInSeconds: number;
121
+ status: {
122
+ $in: factory.transactionStatusType[];
123
+ };
124
+ }): Promise<Pick<import("@chevre/factory/lib/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/assetTransaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/assetTransaction/reserve").ITransaction | import("@chevre/factory/lib/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/assetTransaction/registerService").ITransaction, "id" | "typeOf" | "status">[]>;
111
125
  /**
112
126
  * set task status exported by transaction id
113
127
  * IDでタスクをエクスポート済に変更する
@@ -119,7 +133,9 @@ export declare class MongoRepository {
119
133
  * 取引を期限切れにする
120
134
  */
121
135
  makeExpired(params: {
122
- expires: Date;
136
+ expires: {
137
+ $lt: Date;
138
+ };
123
139
  }): Promise<void>;
124
140
  /**
125
141
  * 取引を中止する
@@ -133,7 +149,7 @@ export declare class MongoRepository {
133
149
  /**
134
150
  * 取引を検索する
135
151
  */
136
- search<T extends factory.assetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>, projection?: any): Promise<factory.assetTransaction.ITransaction<T>[]>;
152
+ search<T extends factory.assetTransactionType>(params: factory.assetTransaction.ISearchConditions<T>, inclusion?: string[], exclusion?: string[]): Promise<factory.assetTransaction.ITransaction<T>[]>;
137
153
  /**
138
154
  * 取引番号指定で削除する
139
155
  */
@@ -159,7 +175,7 @@ export declare class MongoRepository {
159
175
  /**
160
176
  * 特定の取引を更新する(汎用)
161
177
  */
162
- findByIdAndUpdate<T extends factory.assetTransactionType>(params: {
178
+ findByIdAndUpdateInProgress<T extends factory.assetTransactionType>(params: {
163
179
  id: string;
164
180
  update: any;
165
181
  }): Promise<factory.assetTransaction.ITransaction<T>>;
@@ -11,22 +11,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
15
14
  const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
16
15
  const factory = require("../factory");
16
+ const assetTransaction_2 = require("../eventEmitter/assetTransaction");
17
17
  /**
18
18
  * 資産取引リポジトリ
19
19
  */
20
20
  class MongoRepository {
21
21
  constructor(connection) {
22
22
  this.transactionModel = connection.model(assetTransaction_1.modelName, assetTransaction_1.schema);
23
- if (connection.get('autoIndex') === true) {
24
- this.transactionModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
25
- }
26
23
  }
27
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
28
25
  static CREATE_MONGO_CONDITIONS(params) {
29
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
30
27
  const andConditions = [
31
28
  {
32
29
  typeOf: params.typeOf
@@ -106,6 +103,11 @@ class MongoRepository {
106
103
  }
107
104
  });
108
105
  }
106
+ if (Array.isArray(params.tasksExportationStatuses)) {
107
+ andConditions.push({
108
+ tasksExportationStatus: { $in: params.tasksExportationStatuses }
109
+ });
110
+ }
109
111
  switch (params.typeOf) {
110
112
  case factory.assetTransactionType.Pay:
111
113
  const objectAccountIdEq = (_e = (_d = params.object) === null || _d === void 0 ? void 0 : _d.accountId) === null || _e === void 0 ? void 0 : _e.$eq;
@@ -131,15 +133,18 @@ class MongoRepository {
131
133
  const objectPaymentMethodIdEq4refund = (_j = (_h = params.object) === null || _h === void 0 ? void 0 : _h.paymentMethodId) === null || _j === void 0 ? void 0 : _j.$eq;
132
134
  if (typeof objectPaymentMethodIdEq4refund === 'string') {
133
135
  andConditions.push({
134
- 'object.paymentMethodId': {
135
- $exists: true,
136
- $eq: objectPaymentMethodIdEq4refund
137
- }
136
+ 'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq4refund }
137
+ });
138
+ }
139
+ const objectPaymentMethodIdIn4refund = (_l = (_k = params.object) === null || _k === void 0 ? void 0 : _k.paymentMethodId) === null || _l === void 0 ? void 0 : _l.$in;
140
+ if (Array.isArray(objectPaymentMethodIdIn4refund)) {
141
+ andConditions.push({
142
+ 'object.paymentMethodId': { $exists: true, $in: objectPaymentMethodIdIn4refund }
138
143
  });
139
144
  }
140
145
  break;
141
146
  case factory.assetTransactionType.MoneyTransfer:
142
- const fromLocationIdentifierEq = (_m = (_l = (_k = params.object) === null || _k === void 0 ? void 0 : _k.fromLocation) === null || _l === void 0 ? void 0 : _l.identifier) === null || _m === void 0 ? void 0 : _m.$eq;
147
+ const fromLocationIdentifierEq = (_p = (_o = (_m = params.object) === null || _m === void 0 ? void 0 : _m.fromLocation) === null || _o === void 0 ? void 0 : _o.identifier) === null || _p === void 0 ? void 0 : _p.$eq;
143
148
  if (typeof fromLocationIdentifierEq === 'string') {
144
149
  andConditions.push({
145
150
  'object.fromLocation.identifier': {
@@ -148,7 +153,7 @@ class MongoRepository {
148
153
  }
149
154
  });
150
155
  }
151
- const toLocationIdentifierEq = (_q = (_p = (_o = params.object) === null || _o === void 0 ? void 0 : _o.toLocation) === null || _p === void 0 ? void 0 : _p.identifier) === null || _q === void 0 ? void 0 : _q.$eq;
156
+ const toLocationIdentifierEq = (_s = (_r = (_q = params.object) === null || _q === void 0 ? void 0 : _q.toLocation) === null || _r === void 0 ? void 0 : _r.identifier) === null || _s === void 0 ? void 0 : _s.$eq;
152
157
  if (typeof toLocationIdentifierEq === 'string') {
153
158
  andConditions.push({
154
159
  'object.toLocation.identifier': {
@@ -157,7 +162,7 @@ class MongoRepository {
157
162
  }
158
163
  });
159
164
  }
160
- const pendingTransactionIdentifierEq = (_t = (_s = (_r = params.object) === null || _r === void 0 ? void 0 : _r.pendingTransaction) === null || _s === void 0 ? void 0 : _s.identifier) === null || _t === void 0 ? void 0 : _t.$eq;
165
+ const pendingTransactionIdentifierEq = (_v = (_u = (_t = params.object) === null || _t === void 0 ? void 0 : _t.pendingTransaction) === null || _u === void 0 ? void 0 : _u.identifier) === null || _v === void 0 ? void 0 : _v.$eq;
161
166
  if (typeof pendingTransactionIdentifierEq === 'string') {
162
167
  andConditions.push({
163
168
  'object.pendingTransaction.identifier': {
@@ -170,7 +175,25 @@ class MongoRepository {
170
175
  case factory.assetTransactionType.CancelReservation:
171
176
  break;
172
177
  case factory.assetTransactionType.Reserve:
173
- const objectReservationNumberEq = (_v = (_u = params.object) === null || _u === void 0 ? void 0 : _u.reservationNumber) === null || _v === void 0 ? void 0 : _v.$eq;
178
+ const objectReservationForIdEq = (_y = (_x = (_w = params.object) === null || _w === void 0 ? void 0 : _w.reservationFor) === null || _x === void 0 ? void 0 : _x.id) === null || _y === void 0 ? void 0 : _y.$eq;
179
+ if (typeof objectReservationForIdEq === 'string') {
180
+ andConditions.push({
181
+ 'object.reservationFor.id': {
182
+ $exists: true,
183
+ $eq: objectReservationForIdEq
184
+ }
185
+ });
186
+ }
187
+ const objectReservationNumberIn = (_0 = (_z = params.object) === null || _z === void 0 ? void 0 : _z.reservationNumber) === null || _0 === void 0 ? void 0 : _0.$in;
188
+ if (Array.isArray(objectReservationNumberIn)) {
189
+ andConditions.push({
190
+ 'object.reservationNumber': {
191
+ $exists: true,
192
+ $in: objectReservationNumberIn
193
+ }
194
+ });
195
+ }
196
+ const objectReservationNumberEq = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.reservationNumber) === null || _2 === void 0 ? void 0 : _2.$eq;
174
197
  if (typeof objectReservationNumberEq === 'string') {
175
198
  andConditions.push({
176
199
  'object.reservationNumber': {
@@ -179,19 +202,17 @@ class MongoRepository {
179
202
  }
180
203
  });
181
204
  }
205
+ const objectSubReservationIdIn = (_5 = (_4 = (_3 = params.object) === null || _3 === void 0 ? void 0 : _3.reservations) === null || _4 === void 0 ? void 0 : _4.id) === null || _5 === void 0 ? void 0 : _5.$in;
206
+ if (Array.isArray(objectSubReservationIdIn)) {
207
+ andConditions.push({
208
+ 'object.subReservation.id': {
209
+ $exists: true,
210
+ $in: objectSubReservationIdIn
211
+ }
212
+ });
213
+ }
182
214
  if (params.object !== undefined) {
183
215
  if (params.object.reservations !== undefined) {
184
- if (params.object.reservations.id !== undefined) {
185
- if (Array.isArray(params.object.reservations.id.$in)) {
186
- andConditions.push({
187
- // 'object.reservations.id': {
188
- 'object.subReservation.id': {
189
- $exists: true,
190
- $in: params.object.reservations.id.$in
191
- }
192
- });
193
- }
194
- }
195
216
  if (params.object.reservations.reservationNumber !== undefined) {
196
217
  if (Array.isArray(params.object.reservations.reservationNumber.$in)) {
197
218
  andConditions.push({
@@ -216,9 +237,27 @@ class MongoRepository {
216
237
  }
217
238
  }
218
239
  }
240
+ const objectUnderNameIdEq = (_8 = (_7 = (_6 = params.object) === null || _6 === void 0 ? void 0 : _6.underName) === null || _7 === void 0 ? void 0 : _7.id) === null || _8 === void 0 ? void 0 : _8.$eq;
241
+ if (typeof objectUnderNameIdEq === 'string') {
242
+ andConditions.push({
243
+ 'object.underName.id': {
244
+ $exists: true,
245
+ $eq: objectUnderNameIdEq
246
+ }
247
+ });
248
+ }
249
+ const objectSubReservationSeatNumberEq = (_13 = (_12 = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.reservations) === null || _10 === void 0 ? void 0 : _10.reservedTicket) === null || _11 === void 0 ? void 0 : _11.ticketedSeat) === null || _12 === void 0 ? void 0 : _12.seatNumber) === null || _13 === void 0 ? void 0 : _13.$eq;
250
+ if (typeof objectSubReservationSeatNumberEq === 'string') {
251
+ andConditions.push({
252
+ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
253
+ $exists: true,
254
+ $eq: objectSubReservationSeatNumberEq
255
+ }
256
+ });
257
+ }
219
258
  break;
220
259
  case factory.assetTransactionType.RegisterService:
221
- const objectItemOfferedServiceOutputIdentifierEq = (_z = (_y = (_x = (_w = params.object) === null || _w === void 0 ? void 0 : _w.itemOffered) === null || _x === void 0 ? void 0 : _x.serviceOutput) === null || _y === void 0 ? void 0 : _y.identifier) === null || _z === void 0 ? void 0 : _z.$eq;
260
+ const objectItemOfferedServiceOutputIdentifierEq = (_17 = (_16 = (_15 = (_14 = params.object) === null || _14 === void 0 ? void 0 : _14.itemOffered) === null || _15 === void 0 ? void 0 : _15.serviceOutput) === null || _16 === void 0 ? void 0 : _16.identifier) === null || _17 === void 0 ? void 0 : _17.$eq;
222
261
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
223
262
  andConditions.push({
224
263
  'object.itemOffered.serviceOutput.identifier': {
@@ -227,7 +266,7 @@ class MongoRepository {
227
266
  }
228
267
  });
229
268
  }
230
- const objectItemOfferedServiceOutputIdentifierIn = (_3 = (_2 = (_1 = (_0 = params.object) === null || _0 === void 0 ? void 0 : _0.itemOffered) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.identifier) === null || _3 === void 0 ? void 0 : _3.$in;
269
+ const objectItemOfferedServiceOutputIdentifierIn = (_21 = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceOutput) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$in;
231
270
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
232
271
  andConditions.push({
233
272
  'object.itemOffered.serviceOutput.identifier': {
@@ -246,7 +285,9 @@ class MongoRepository {
246
285
  */
247
286
  start(params) {
248
287
  return __awaiter(this, void 0, void 0, function* () {
249
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate: new Date(), endDate: undefined, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
288
+ return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate: new Date(), endDate: undefined, tasksExportAction: {
289
+ actionStatus: factory.actionStatusType.PotentialActionStatus
290
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
250
291
  .then((doc) => doc.toObject());
251
292
  });
252
293
  }
@@ -276,26 +317,24 @@ class MongoRepository {
276
317
  return doc.toObject();
277
318
  });
278
319
  }
279
- /**
280
- * 取引を確定する
281
- */
282
320
  addReservations(params) {
321
+ var _a;
283
322
  return __awaiter(this, void 0, void 0, function* () {
284
323
  const doc = yield this.transactionModel.findOneAndUpdate({
285
- _id: params.id,
286
- typeOf: params.typeOf,
287
- status: factory.transactionStatusType.InProgress
288
- }, {
289
- 'object.acceptedOffer': params.object.acceptedOffer,
324
+ _id: { $eq: params.id },
325
+ typeOf: { $eq: params.typeOf },
326
+ status: { $eq: factory.transactionStatusType.InProgress }
327
+ }, Object.assign({ 'object.acceptedOffer': params.object.acceptedOffer,
290
328
  // 念のため残す(2021/10/14)が、そのうち削除
291
329
  // 冗長なので削除(2021/10/19~)
292
330
  // 'object.event': params.object.reservationFor,
293
- 'object.reservationFor': params.object.reservationFor,
331
+ 'object.reservationFor': params.object.reservationFor,
294
332
  // 念のため残す(2021/10/14)が、そのうち削除
295
333
  // 冗長なので削除(2021/10/19~)
296
334
  // 'object.reservations': params.object.subReservation,
297
- 'object.subReservation': params.object.subReservation
298
- }, { new: true })
335
+ 'object.subReservation': params.object.subReservation }, (typeof ((_a = params.object.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
336
+ ? { 'object.issuedThrough': params.object.issuedThrough }
337
+ : undefined), { new: true })
299
338
  .exec();
300
339
  if (doc === null) {
301
340
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -307,36 +346,40 @@ class MongoRepository {
307
346
  * 取引を確定する
308
347
  */
309
348
  confirm(params) {
349
+ var _a, _b;
310
350
  return __awaiter(this, void 0, void 0, function* () {
311
351
  const doc = yield this.transactionModel.findOneAndUpdate({
312
- _id: params.id,
313
- typeOf: params.typeOf,
314
- status: factory.transactionStatusType.InProgress
315
- }, {
316
- status: factory.transactionStatusType.Confirmed,
317
- endDate: new Date(),
318
- result: params.result,
319
- potentialActions: params.potentialActions // resultを更新
320
- }, { new: true })
352
+ _id: { $eq: params.id },
353
+ typeOf: { $eq: params.typeOf },
354
+ status: { $eq: factory.transactionStatusType.InProgress }
355
+ }, Object.assign({ status: factory.transactionStatusType.Confirmed, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
356
+ ? { 'object.underName': params.object.underName }
357
+ : undefined), {
358
+ new: true,
359
+ projection: { _id: 1 }
360
+ })
321
361
  .exec();
322
362
  // NotFoundであれば取引状態確認
323
363
  if (doc === null) {
324
364
  const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
325
365
  if (transaction.status === factory.transactionStatusType.Confirmed) {
326
- // すでに確定済の場合
327
- return transaction;
366
+ // すでに確定済の場合スルー
328
367
  }
329
368
  else if (transaction.status === factory.transactionStatusType.Expired) {
330
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
369
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
331
370
  }
332
371
  else if (transaction.status === factory.transactionStatusType.Canceled) {
333
- throw new factory.errors.Argument('Transaction id', 'Transaction already canceled');
372
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already canceled`);
334
373
  }
335
374
  else {
336
375
  throw new factory.errors.NotFound(this.transactionModel.modelName);
337
376
  }
338
377
  }
339
- return doc.toObject();
378
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
379
+ id: params.id,
380
+ typeOf: params.typeOf,
381
+ status: factory.transactionStatusType.Confirmed
382
+ });
340
383
  });
341
384
  }
342
385
  /**
@@ -344,23 +387,42 @@ class MongoRepository {
344
387
  */
345
388
  startAndConfirm(params) {
346
389
  return __awaiter(this, void 0, void 0, function* () {
347
- return this.transactionModel.create(Object.assign(Object.assign({ _id: params.id, typeOf: params.typeOf }, params), { startDate: new Date(), status: factory.transactionStatusType.Confirmed, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }))
390
+ const startDate = new Date();
391
+ const confirmedTransaction = yield this.transactionModel.create(Object.assign(Object.assign({}, params), { _id: params.id, typeOf: params.typeOf, startDate, status: factory.transactionStatusType.Confirmed, tasksExportAction: {
392
+ actionStatus: factory.actionStatusType.PotentialActionStatus
393
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: startDate, result: params.result, potentialActions: params.potentialActions }))
348
394
  .then((doc) => doc.toObject());
395
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
396
+ id: params.id,
397
+ typeOf: params.typeOf,
398
+ status: factory.transactionStatusType.Confirmed
399
+ });
400
+ return confirmedTransaction;
349
401
  });
350
402
  }
351
403
  /**
352
404
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
353
405
  */
354
406
  startExportTasks(params) {
355
- var _a, _b, _c;
407
+ var _a, _b;
356
408
  return __awaiter(this, void 0, void 0, function* () {
357
- return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({}, (typeof ((_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === 'string')
358
- ? {
359
- 'project.id': {
360
- $eq: params.project.id
361
- }
362
- } : undefined), (Array.isArray((_b = params.typeOf) === null || _b === void 0 ? void 0 : _b.$in))
363
- ? { typeOf: { $in: (_c = params.typeOf) === null || _c === void 0 ? void 0 : _c.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
409
+ switch (params.status) {
410
+ case factory.transactionStatusType.InProgress:
411
+ throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
412
+ default:
413
+ // no op
414
+ }
415
+ const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
416
+ return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === 'string') ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
417
+ 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
418
+ 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
419
+ 'tasksExportAction.startDate': new Date(),
420
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
421
+ }, { new: true })
422
+ .select({
423
+ _id: 1,
424
+ typeOf: 1
425
+ })
364
426
  .exec()
365
427
  // tslint:disable-next-line:no-null-keyword
366
428
  .then((doc) => (doc === null) ? null : doc.toObject());
@@ -373,17 +435,74 @@ class MongoRepository {
373
435
  */
374
436
  reexportTasks(params) {
375
437
  return __awaiter(this, void 0, void 0, function* () {
376
- yield this.transactionModel.updateMany({
377
- tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
438
+ const reexportingTransactions = yield this.transactionModel.find({
439
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
378
440
  updatedAt: {
379
441
  $lt: moment()
380
442
  .add(-params.intervalInMinutes, 'minutes')
381
443
  .toDate()
382
444
  }
383
- }, {
384
- tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
385
445
  })
446
+ .select({
447
+ _id: 1,
448
+ typeOf: 1,
449
+ status: 1
450
+ })
451
+ .setOptions({ maxTimeMS: 10000 })
386
452
  .exec();
453
+ if (reexportingTransactions.length > 0) {
454
+ for (const reexportingTransaction of reexportingTransactions) {
455
+ yield this.transactionModel.updateOne({
456
+ _id: { $eq: reexportingTransaction.id },
457
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
458
+ }, {
459
+ tasksExportAction: {
460
+ actionStatus: factory.actionStatusType.PotentialActionStatus
461
+ },
462
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
463
+ })
464
+ .exec();
465
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
466
+ id: reexportingTransaction.id,
467
+ typeOf: reexportingTransaction.typeOf,
468
+ status: reexportingTransaction.status
469
+ });
470
+ }
471
+ }
472
+ });
473
+ }
474
+ /**
475
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
476
+ */
477
+ exportTasks(params) {
478
+ return __awaiter(this, void 0, void 0, function* () {
479
+ const delayedTransactions = yield this.transactionModel.find({
480
+ status: { $in: params.status.$in },
481
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported },
482
+ endDate: {
483
+ $exists: true,
484
+ $lt: moment(params.now)
485
+ .add(-params.delayInSeconds, 'seconds')
486
+ .toDate()
487
+ }
488
+ })
489
+ .select({
490
+ _id: 1,
491
+ typeOf: 1,
492
+ status: 1
493
+ })
494
+ .setOptions({ maxTimeMS: 10000 })
495
+ .exec();
496
+ if (delayedTransactions.length > 0) {
497
+ delayedTransactions.forEach((delayedTransaction) => {
498
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
499
+ id: delayedTransaction.id,
500
+ typeOf: delayedTransaction.typeOf,
501
+ status: delayedTransaction.status
502
+ });
503
+ });
504
+ }
505
+ return delayedTransactions;
387
506
  });
388
507
  }
389
508
  /**
@@ -392,10 +511,15 @@ class MongoRepository {
392
511
  */
393
512
  setTasksExportedById(params) {
394
513
  return __awaiter(this, void 0, void 0, function* () {
395
- yield this.transactionModel.findByIdAndUpdate(params.id, {
514
+ const endDate = new Date();
515
+ yield this.transactionModel.updateOne({
516
+ _id: { $eq: params.id },
517
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
518
+ }, {
396
519
  tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
397
- tasksExportedAt: moment()
398
- .toDate()
520
+ tasksExportedAt: endDate,
521
+ 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
522
+ 'tasksExportAction.endDate': endDate
399
523
  })
400
524
  .exec();
401
525
  });
@@ -405,15 +529,36 @@ class MongoRepository {
405
529
  */
406
530
  makeExpired(params) {
407
531
  return __awaiter(this, void 0, void 0, function* () {
408
- // ステータスと期限を見て更新
409
- yield this.transactionModel.updateMany({
410
- status: factory.transactionStatusType.InProgress,
411
- expires: { $lt: params.expires }
412
- }, {
413
- status: factory.transactionStatusType.Expired,
414
- endDate: new Date()
532
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
533
+ const expiringTransactions = yield this.transactionModel.find({
534
+ status: { $eq: factory.transactionStatusType.InProgress },
535
+ expires: { $lt: params.expires.$lt }
415
536
  })
537
+ .select({
538
+ _id: 1,
539
+ typeOf: 1
540
+ })
541
+ .setOptions({ maxTimeMS: 10000 })
416
542
  .exec();
543
+ if (expiringTransactions.length > 0) {
544
+ // ステータスと期限を見て更新
545
+ yield this.transactionModel.updateMany({
546
+ _id: { $in: expiringTransactions.map((t) => t.id) },
547
+ status: { $eq: factory.transactionStatusType.InProgress },
548
+ expires: { $lt: params.expires.$lt }
549
+ }, {
550
+ status: factory.transactionStatusType.Expired,
551
+ endDate: new Date()
552
+ })
553
+ .exec();
554
+ expiringTransactions.forEach((expiringTransaction) => {
555
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
556
+ id: expiringTransaction.id,
557
+ typeOf: expiringTransaction.typeOf,
558
+ status: factory.transactionStatusType.Expired
559
+ });
560
+ });
561
+ }
417
562
  });
418
563
  }
419
564
  /**
@@ -421,19 +566,18 @@ class MongoRepository {
421
566
  */
422
567
  cancel(params) {
423
568
  return __awaiter(this, void 0, void 0, function* () {
424
- const endDate = moment()
425
- .toDate();
569
+ const endDate = new Date();
426
570
  // 進行中ステータスの取引を中止する
427
- const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: params.typeOf }, (typeof params.id === 'string') ? { _id: params.id } : undefined), (typeof params.transactionNumber === 'string')
571
+ const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: { $eq: params.typeOf } }, (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), (typeof params.transactionNumber === 'string')
428
572
  ? { transactionNumber: { $exists: true, $eq: params.transactionNumber } }
429
- : undefined), { status: factory.transactionStatusType.InProgress }), {
573
+ : undefined), { status: { $eq: factory.transactionStatusType.InProgress } }), {
430
574
  status: factory.transactionStatusType.Canceled,
431
575
  endDate: endDate
432
576
  }, { new: true })
433
577
  .exec();
578
+ let transaction;
434
579
  // NotFoundであれば取引状態確認
435
580
  if (doc === null) {
436
- let transaction;
437
581
  if (typeof params.id === 'string') {
438
582
  transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
439
583
  }
@@ -447,20 +591,27 @@ class MongoRepository {
447
591
  throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
448
592
  }
449
593
  if (transaction.status === factory.transactionStatusType.Canceled) {
450
- // すでに中止済の場合
451
- return transaction;
594
+ // すでに中止済の場合スルー
452
595
  }
453
596
  else if (transaction.status === factory.transactionStatusType.Expired) {
454
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
597
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
455
598
  }
456
599
  else if (transaction.status === factory.transactionStatusType.Confirmed) {
457
- throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
600
+ throw new factory.errors.Argument('Transaction id', `Confirmed transaction ${transaction.typeOf} ${transaction.transactionNumber} unable to cancel`);
458
601
  }
459
602
  else {
460
603
  throw new factory.errors.NotFound(this.transactionModel.modelName);
461
604
  }
462
605
  }
463
- return doc.toObject();
606
+ else {
607
+ transaction = doc.toObject();
608
+ }
609
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
610
+ id: transaction.id,
611
+ typeOf: params.typeOf,
612
+ status: factory.transactionStatusType.Canceled
613
+ });
614
+ return transaction;
464
615
  });
465
616
  }
466
617
  count(params) {
@@ -474,12 +625,30 @@ class MongoRepository {
474
625
  /**
475
626
  * 取引を検索する
476
627
  */
477
- search(params, projection) {
628
+ search(params, inclusion, exclusion) {
478
629
  var _a;
479
630
  return __awaiter(this, void 0, void 0, function* () {
480
631
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
632
+ let projection = {};
633
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
634
+ inclusion.forEach((field) => {
635
+ projection[field] = 1;
636
+ });
637
+ }
638
+ else {
639
+ projection = {
640
+ __v: 0,
641
+ createdAt: 0,
642
+ updatedAt: 0
643
+ };
644
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
645
+ exclusion.forEach((field) => {
646
+ projection[field] = 0;
647
+ });
648
+ }
649
+ }
481
650
  const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
482
- .select(Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
651
+ .select(projection);
483
652
  if (typeof params.limit === 'number' && params.limit > 0) {
484
653
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
485
654
  query.limit(params.limit)
@@ -522,9 +691,12 @@ class MongoRepository {
522
691
  /**
523
692
  * 特定の取引を更新する(汎用)
524
693
  */
525
- findByIdAndUpdate(params) {
694
+ findByIdAndUpdateInProgress(params) {
526
695
  return __awaiter(this, void 0, void 0, function* () {
527
- return this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, { new: true })
696
+ return this.transactionModel.findOneAndUpdate({
697
+ _id: { $eq: params.id },
698
+ status: { $eq: factory.transactionStatusType.InProgress }
699
+ }, params.update, { new: true })
528
700
  .exec()
529
701
  .then((doc) => {
530
702
  if (doc === null) {