@chevre/domain 21.2.0-alpha.13 → 21.2.0-alpha.131

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