@chevre/domain 23.2.0-alpha.61 → 23.2.0-alpha.63

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 (481) hide show
  1. package/lib/chevre/credentials/customSearch.js +2 -0
  2. package/lib/chevre/credentials/lineNotify.js +4 -0
  3. package/lib/chevre/credentials/sendGrid.js +2 -0
  4. package/lib/chevre/credentials.js +15 -30
  5. package/lib/chevre/emailMessageBuilder.js +225 -250
  6. package/lib/chevre/errorHandler.js +38 -59
  7. package/lib/chevre/eventEmitter/assetTransaction.js +0 -1
  8. package/lib/chevre/eventEmitter/task.js +0 -1
  9. package/lib/chevre/eventEmitter/transaction.js +0 -1
  10. package/lib/chevre/factory/event.js +69 -42
  11. package/lib/chevre/factory/transactionNumber.js +2 -2
  12. package/lib/chevre/index.js +15 -30
  13. package/lib/chevre/repo/acceptedOffer.js +177 -197
  14. package/lib/chevre/repo/acceptedPaymentMethod.js +131 -144
  15. package/lib/chevre/repo/account.js +194 -238
  16. package/lib/chevre/repo/accountTitle.js +9 -21
  17. package/lib/chevre/repo/accountTransaction.js +186 -193
  18. package/lib/chevre/repo/accountingReport.js +88 -107
  19. package/lib/chevre/repo/action.js +849 -883
  20. package/lib/chevre/repo/additionalProperty.js +64 -92
  21. package/lib/chevre/repo/advanceBookingRequirement.js +69 -91
  22. package/lib/chevre/repo/aggregateOffer.js +392 -430
  23. package/lib/chevre/repo/aggregateOrder.js +50 -62
  24. package/lib/chevre/repo/aggregateReservation.js +76 -89
  25. package/lib/chevre/repo/aggregation.js +42 -63
  26. package/lib/chevre/repo/assetTransaction.js +692 -729
  27. package/lib/chevre/repo/authorization.js +115 -134
  28. package/lib/chevre/repo/categoryCode.js +114 -147
  29. package/lib/chevre/repo/comment.js +73 -82
  30. package/lib/chevre/repo/concurrentLock.js +17 -29
  31. package/lib/chevre/repo/confirmationNumber.js +19 -35
  32. package/lib/chevre/repo/creativeWork.js +152 -180
  33. package/lib/chevre/repo/credentials.js +39 -51
  34. package/lib/chevre/repo/customer.js +64 -88
  35. package/lib/chevre/repo/customerType.js +52 -62
  36. package/lib/chevre/repo/emailMessage.js +51 -80
  37. package/lib/chevre/repo/event.js +640 -684
  38. package/lib/chevre/repo/eventOffer.js +122 -125
  39. package/lib/chevre/repo/eventSellerMakesOffer.js +64 -76
  40. package/lib/chevre/repo/eventSeries.js +207 -244
  41. package/lib/chevre/repo/identity.js +94 -107
  42. package/lib/chevre/repo/identityProvider.js +72 -96
  43. package/lib/chevre/repo/issuer.js +102 -135
  44. package/lib/chevre/repo/member.js +238 -259
  45. package/lib/chevre/repo/memberProgram.js +157 -177
  46. package/lib/chevre/repo/merchantReturnPolicy.js +61 -94
  47. package/lib/chevre/repo/message.js +122 -135
  48. package/lib/chevre/repo/mongoose/onIndexCreated.js +0 -1
  49. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.js +1 -1
  50. package/lib/chevre/repo/mongoose/schemas/account.js +1 -1
  51. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -1
  52. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
  53. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -1
  54. package/lib/chevre/repo/mongoose/schemas/action.js +1 -1
  55. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +1 -1
  56. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -1
  57. package/lib/chevre/repo/mongoose/schemas/advanceBookingRequirement.js +1 -1
  58. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +1 -1
  59. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +1 -1
  60. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +1 -1
  61. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -1
  62. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -1
  63. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
  64. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -1
  65. package/lib/chevre/repo/mongoose/schemas/civicStructure.js +1 -1
  66. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -1
  67. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -1
  68. package/lib/chevre/repo/mongoose/schemas/customerType.js +1 -1
  69. package/lib/chevre/repo/mongoose/schemas/event.js +1 -1
  70. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +1 -1
  71. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +1 -1
  72. package/lib/chevre/repo/mongoose/schemas/identity.js +1 -1
  73. package/lib/chevre/repo/mongoose/schemas/identityProvider.js +1 -1
  74. package/lib/chevre/repo/mongoose/schemas/issuer.js +1 -1
  75. package/lib/chevre/repo/mongoose/schemas/member/global.js +1 -1
  76. package/lib/chevre/repo/mongoose/schemas/member.js +1 -1
  77. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -1
  78. package/lib/chevre/repo/mongoose/schemas/message.js +1 -1
  79. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +1 -1
  80. package/lib/chevre/repo/mongoose/schemas/note.js +1 -1
  81. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -1
  82. package/lib/chevre/repo/mongoose/schemas/offerCatalogItem.js +1 -1
  83. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +1 -1
  84. package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
  85. package/lib/chevre/repo/mongoose/schemas/paymentService.js +1 -1
  86. package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +1 -1
  87. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +1 -1
  88. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.js +1 -1
  89. package/lib/chevre/repo/mongoose/schemas/place.js +1 -1
  90. package/lib/chevre/repo/mongoose/schemas/potentialAction.js +1 -1
  91. package/lib/chevre/repo/mongoose/schemas/product.js +1 -1
  92. package/lib/chevre/repo/mongoose/schemas/productModel.js +1 -1
  93. package/lib/chevre/repo/mongoose/schemas/productOffer.js +1 -1
  94. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
  95. package/lib/chevre/repo/mongoose/schemas/reserveInterface.js +1 -1
  96. package/lib/chevre/repo/mongoose/schemas/role.js +1 -1
  97. package/lib/chevre/repo/mongoose/schemas/schedule.js +1 -1
  98. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -1
  99. package/lib/chevre/repo/mongoose/schemas/sellerReturnPolicy.js +1 -1
  100. package/lib/chevre/repo/mongoose/schemas/service/availableHour.js +1 -1
  101. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -1
  102. package/lib/chevre/repo/mongoose/schemas/task.js +1 -2
  103. package/lib/chevre/repo/mongoose/schemas/ticket.js +1 -1
  104. package/lib/chevre/repo/mongoose/schemas/transaction.js +1 -1
  105. package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +1 -1
  106. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -1
  107. package/lib/chevre/repo/mongoose/schemas/webSite.js +1 -1
  108. package/lib/chevre/repo/movieTicketType.js +67 -94
  109. package/lib/chevre/repo/note.js +143 -147
  110. package/lib/chevre/repo/noteAboutOrder.js +112 -113
  111. package/lib/chevre/repo/offer/unitPriceInCatalog.js +330 -314
  112. package/lib/chevre/repo/offerCatalog.js +302 -334
  113. package/lib/chevre/repo/offerCatalogItem.js +289 -317
  114. package/lib/chevre/repo/offerItemCondition.js +60 -85
  115. package/lib/chevre/repo/order.js +559 -607
  116. package/lib/chevre/repo/orderInTransaction.js +113 -136
  117. package/lib/chevre/repo/orderNumber.js +95 -112
  118. package/lib/chevre/repo/ownershipInfo.js +212 -240
  119. package/lib/chevre/repo/passport.js +93 -102
  120. package/lib/chevre/repo/paymentMethod/creditCard.js +151 -169
  121. package/lib/chevre/repo/paymentService.js +179 -200
  122. package/lib/chevre/repo/paymentServiceChannel.js +76 -100
  123. package/lib/chevre/repo/paymentServiceProvider.js +186 -201
  124. package/lib/chevre/repo/pendingReservation.js +272 -305
  125. package/lib/chevre/repo/permit.js +47 -42
  126. package/lib/chevre/repo/person.js +217 -256
  127. package/lib/chevre/repo/place/busStop.js +76 -106
  128. package/lib/chevre/repo/place/entranceGate.js +123 -128
  129. package/lib/chevre/repo/place/hasPOS.js +108 -120
  130. package/lib/chevre/repo/place/movieTheater.js +185 -220
  131. package/lib/chevre/repo/place/screeningRoom.js +339 -325
  132. package/lib/chevre/repo/place/seat.js +538 -481
  133. package/lib/chevre/repo/place/section.js +328 -296
  134. package/lib/chevre/repo/potentialAction.js +67 -87
  135. package/lib/chevre/repo/priceSpecification.js +102 -146
  136. package/lib/chevre/repo/product.js +203 -239
  137. package/lib/chevre/repo/productHasOfferCatalog.js +39 -50
  138. package/lib/chevre/repo/productModel.js +94 -127
  139. package/lib/chevre/repo/productOffer.js +119 -118
  140. package/lib/chevre/repo/project.js +123 -141
  141. package/lib/chevre/repo/projectMakesOffer.js +96 -108
  142. package/lib/chevre/repo/rateLimit/offer.js +43 -57
  143. package/lib/chevre/repo/reservation.js +369 -398
  144. package/lib/chevre/repo/reserveInterface.js +31 -42
  145. package/lib/chevre/repo/role.js +93 -112
  146. package/lib/chevre/repo/schedule.js +25 -36
  147. package/lib/chevre/repo/seller.js +114 -147
  148. package/lib/chevre/repo/sellerMakesOffer.js +95 -110
  149. package/lib/chevre/repo/sellerPaymentAccepted.js +92 -109
  150. package/lib/chevre/repo/sellerReturnPolicy.js +74 -97
  151. package/lib/chevre/repo/service/availableHour.js +27 -38
  152. package/lib/chevre/repo/serviceOutput.js +54 -67
  153. package/lib/chevre/repo/serviceOutputIdentifier.js +46 -58
  154. package/lib/chevre/repo/setting/jwt.js +40 -50
  155. package/lib/chevre/repo/setting.js +48 -48
  156. package/lib/chevre/repo/stockHolder.js +179 -199
  157. package/lib/chevre/repo/task.js +610 -619
  158. package/lib/chevre/repo/telemetry.js +1 -0
  159. package/lib/chevre/repo/ticket.js +52 -65
  160. package/lib/chevre/repo/transaction.js +754 -815
  161. package/lib/chevre/repo/transactionNumber.js +67 -80
  162. package/lib/chevre/repo/transactionNumberCounter.js +68 -79
  163. package/lib/chevre/repo/transactionProcess.js +36 -47
  164. package/lib/chevre/repo/trip.js +144 -164
  165. package/lib/chevre/repo/webSite.js +90 -106
  166. package/lib/chevre/repository.js +455 -647
  167. package/lib/chevre/service/account.js +9 -21
  168. package/lib/chevre/service/accountTransaction/deposit.js +16 -17
  169. package/lib/chevre/service/accountTransaction/transfer.js +18 -22
  170. package/lib/chevre/service/accountTransaction/withdraw.js +16 -17
  171. package/lib/chevre/service/accountTransaction.js +4 -16
  172. package/lib/chevre/service/aggregation/event/aggregateOffers.js +63 -60
  173. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +52 -55
  174. package/lib/chevre/service/aggregation/event/findEventOffers.js +7 -17
  175. package/lib/chevre/service/aggregation/event/importFromCOA.js +4 -14
  176. package/lib/chevre/service/aggregation/project.js +10 -19
  177. package/lib/chevre/service/aggregation/system.js +182 -99
  178. package/lib/chevre/service/assetTransaction/cancelReservation/factory.js +31 -17
  179. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +17 -24
  180. package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.js +17 -15
  181. package/lib/chevre/service/assetTransaction/cancelReservation.js +7 -18
  182. package/lib/chevre/service/assetTransaction/cancelReservationCOA/factory.js +11 -4
  183. package/lib/chevre/service/assetTransaction/cancelReservationCOA.js +4 -13
  184. package/lib/chevre/service/assetTransaction/fixInformAction.js +6 -16
  185. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +13 -25
  186. package/lib/chevre/service/assetTransaction/moneyTransfer.js +101 -90
  187. package/lib/chevre/service/assetTransaction/pay/cancel.js +3 -12
  188. package/lib/chevre/service/assetTransaction/pay/check.js +4 -14
  189. package/lib/chevre/service/assetTransaction/pay/confirm.js +18 -21
  190. package/lib/chevre/service/assetTransaction/pay/exportTasksById.js +4 -14
  191. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +33 -34
  192. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.js +7 -17
  193. package/lib/chevre/service/assetTransaction/pay/start/account/validation.js +6 -16
  194. package/lib/chevre/service/assetTransaction/pay/start/factory.js +64 -37
  195. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateAcceptedPaymentMethodIfNeeded.js +7 -19
  196. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateSeller.js +6 -16
  197. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +7 -17
  198. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.js +9 -15
  199. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +3 -12
  200. package/lib/chevre/service/assetTransaction/pay/start.js +29 -35
  201. package/lib/chevre/service/assetTransaction/refund/factory.js +36 -16
  202. package/lib/chevre/service/assetTransaction/refund/potentialActions.js +12 -21
  203. package/lib/chevre/service/assetTransaction/refund.js +35 -41
  204. package/lib/chevre/service/assetTransaction/registerService/factory.js +65 -28
  205. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +50 -43
  206. package/lib/chevre/service/assetTransaction/registerService.js +45 -56
  207. package/lib/chevre/service/assetTransaction/reserve/cancel.js +5 -14
  208. package/lib/chevre/service/assetTransaction/reserve/confirm/factory.js +15 -4
  209. package/lib/chevre/service/assetTransaction/reserve/confirm.js +21 -26
  210. package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +3 -13
  211. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +99 -83
  212. package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.js +17 -12
  213. package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.js +108 -72
  214. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +69 -30
  215. package/lib/chevre/service/assetTransaction/reserve/start/factory/price.js +29 -20
  216. package/lib/chevre/service/assetTransaction/reserve/start.js +91 -108
  217. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +5 -15
  218. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +41 -54
  219. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +42 -56
  220. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +7 -19
  221. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +15 -27
  222. package/lib/chevre/service/assetTransaction/reserveCOA/cancel.js +24 -24
  223. package/lib/chevre/service/assetTransaction/reserveCOA/factory.js +12 -4
  224. package/lib/chevre/service/assetTransaction/reserveCOA.js +4 -13
  225. package/lib/chevre/service/assetTransaction.js +17 -21
  226. package/lib/chevre/service/delivery/factory.js +3 -4
  227. package/lib/chevre/service/delivery/product/factory.js +16 -7
  228. package/lib/chevre/service/delivery/reservation/factory.js +14 -3
  229. package/lib/chevre/service/delivery.js +48 -52
  230. package/lib/chevre/service/event/processUpdateMovieTheater.js +21 -26
  231. package/lib/chevre/service/event/saveScreeningEventSeries.js +56 -41
  232. package/lib/chevre/service/event/saveScreeningEvents.js +14 -29
  233. package/lib/chevre/service/event.js +34 -30
  234. package/lib/chevre/service/iam.js +8 -17
  235. package/lib/chevre/service/moneyTransfer.js +128 -112
  236. package/lib/chevre/service/notification/factory.js +11 -10
  237. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +11 -15
  238. package/lib/chevre/service/notification/notifyByEmail.js +7 -19
  239. package/lib/chevre/service/notification/sendEmailMessage.js +23 -26
  240. package/lib/chevre/service/notification/triggerWebhook.js +58 -56
  241. package/lib/chevre/service/offer/any.js +6 -15
  242. package/lib/chevre/service/offer/event/authorize/factory.js +139 -63
  243. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +8 -19
  244. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +43 -27
  245. package/lib/chevre/service/offer/event/authorize.js +114 -71
  246. package/lib/chevre/service/offer/event/checkAvailability.js +5 -15
  247. package/lib/chevre/service/offer/event/importFromCOA/factory.js +9 -3
  248. package/lib/chevre/service/offer/event/importFromCOA.js +13 -19
  249. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +38 -39
  250. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +26 -41
  251. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.js +11 -22
  252. package/lib/chevre/service/offer/event/searchOfferCatalogItemAvailability.js +13 -26
  253. package/lib/chevre/service/offer/event/searchOfferCatalogItems.js +15 -23
  254. package/lib/chevre/service/offer/event/searchOffersByIds.js +24 -39
  255. package/lib/chevre/service/offer/event/searchPriceSpecs4event.js +5 -14
  256. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +4 -13
  257. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +6 -15
  258. package/lib/chevre/service/offer/event/voidTransaction.js +35 -41
  259. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +14 -20
  260. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +52 -42
  261. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/factory.js +5 -1
  262. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +34 -37
  263. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +45 -26
  264. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +67 -62
  265. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +16 -27
  266. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +8 -18
  267. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +42 -43
  268. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +22 -25
  269. package/lib/chevre/service/offer/factory.js +18 -8
  270. package/lib/chevre/service/offer/moneyTransfer/authorize.js +31 -36
  271. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +9 -18
  272. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +10 -19
  273. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +14 -24
  274. package/lib/chevre/service/offer/onEventChanged.js +69 -65
  275. package/lib/chevre/service/offer/product/factory.js +54 -32
  276. package/lib/chevre/service/offer/product/searchProductOffers.js +30 -24
  277. package/lib/chevre/service/offer/product.js +106 -82
  278. package/lib/chevre/service/offer.js +48 -45
  279. package/lib/chevre/service/order/confirmPayTransaction.js +28 -27
  280. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +54 -41
  281. package/lib/chevre/service/order/deleteOrder.js +28 -36
  282. package/lib/chevre/service/order/findPlaceOrderTransaction.js +3 -12
  283. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +64 -70
  284. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +1 -2
  285. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +3 -12
  286. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +11 -6
  287. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +5 -14
  288. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +22 -9
  289. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +5 -14
  290. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +23 -26
  291. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +13 -19
  292. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +5 -14
  293. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +24 -14
  294. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +23 -32
  295. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +8 -18
  296. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +10 -9
  297. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +23 -28
  298. package/lib/chevre/service/order/onOrderUpdated/factory.js +3 -5
  299. package/lib/chevre/service/order/onOrderUpdated.js +13 -15
  300. package/lib/chevre/service/order/payOrder.js +3 -12
  301. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +9 -20
  302. package/lib/chevre/service/order/placeOrder/factory/orderedItem.js +31 -15
  303. package/lib/chevre/service/order/placeOrder/factory.js +35 -22
  304. package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +3 -12
  305. package/lib/chevre/service/order/placeOrder.js +12 -23
  306. package/lib/chevre/service/order/placeOrderWithoutTransaction.js +10 -18
  307. package/lib/chevre/service/order/returnOrder.js +27 -30
  308. package/lib/chevre/service/order/sendOrder.js +37 -37
  309. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +19 -25
  310. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +24 -39
  311. package/lib/chevre/service/payment/any/factory.js +106 -50
  312. package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +4 -13
  313. package/lib/chevre/service/payment/any/onPayActionCompleted.js +13 -18
  314. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.js +34 -37
  315. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.js +18 -24
  316. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +16 -16
  317. package/lib/chevre/service/payment/any/onRefundActionCompletedOrFailed.js +15 -21
  318. package/lib/chevre/service/payment/any/person2username.js +32 -45
  319. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +8 -18
  320. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +5 -17
  321. package/lib/chevre/service/payment/any.js +181 -142
  322. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +2 -2
  323. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.js +44 -25
  324. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3ds.js +6 -15
  325. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3dsResult2recipe.js +5 -1
  326. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCardResult2recipe.js +10 -2
  327. package/lib/chevre/service/payment/creditCard/authorize.js +20 -22
  328. package/lib/chevre/service/payment/creditCard/factory.js +22 -4
  329. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +8 -18
  330. package/lib/chevre/service/payment/creditCard/payCreditCard.js +31 -36
  331. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +40 -51
  332. package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +33 -45
  333. package/lib/chevre/service/payment/creditCard/voidTransaction.js +15 -26
  334. package/lib/chevre/service/payment/faceToFace.js +14 -23
  335. package/lib/chevre/service/payment/factory/createPayObjectServiceOutput.js +44 -25
  336. package/lib/chevre/service/payment/factory.js +50 -24
  337. package/lib/chevre/service/payment/movieTicket/authorize.js +35 -30
  338. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +22 -25
  339. package/lib/chevre/service/payment/movieTicket/factory.js +33 -10
  340. package/lib/chevre/service/payment/movieTicket/getCredentials.js +5 -15
  341. package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +29 -40
  342. package/lib/chevre/service/payment/movieTicket/processPurchaseNumberAuth.js +8 -18
  343. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +60 -60
  344. package/lib/chevre/service/payment/movieTicket/validation.js +41 -37
  345. package/lib/chevre/service/payment/movieTicket/voidTransaction.js +8 -18
  346. package/lib/chevre/service/payment/paymentCard.js +87 -104
  347. package/lib/chevre/service/permit.js +36 -35
  348. package/lib/chevre/service/product.js +23 -28
  349. package/lib/chevre/service/project.js +22 -31
  350. package/lib/chevre/service/report/ownershipInfo.js +3 -4
  351. package/lib/chevre/service/report/telemetry.js +51 -70
  352. package/lib/chevre/service/reserve/cancelReservation.js +92 -93
  353. package/lib/chevre/service/reserve/checkInReservation.js +24 -29
  354. package/lib/chevre/service/reserve/confirmReservation.js +33 -39
  355. package/lib/chevre/service/reserve/factory.js +42 -20
  356. package/lib/chevre/service/reserve/findByCode.js +13 -18
  357. package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +18 -24
  358. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +17 -25
  359. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +38 -30
  360. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +45 -37
  361. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +37 -33
  362. package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +17 -23
  363. package/lib/chevre/service/reserve/searchByOrder.js +10 -20
  364. package/lib/chevre/service/reserve/useReservation.js +47 -34
  365. package/lib/chevre/service/reserve/verifyToken4reservation.js +7 -14
  366. package/lib/chevre/service/reserveCOA/cancelReservation.js +7 -17
  367. package/lib/chevre/service/reserveCOA/factory.js +5 -1
  368. package/lib/chevre/service/task/acceptCOAOffer.js +20 -25
  369. package/lib/chevre/service/task/aggregateOffers.js +3 -12
  370. package/lib/chevre/service/task/aggregateOnSystem.js +4 -14
  371. package/lib/chevre/service/task/aggregateScreeningEvent.js +3 -12
  372. package/lib/chevre/service/task/authorizePayment.js +9 -15
  373. package/lib/chevre/service/task/cancelMoneyTransfer.js +3 -12
  374. package/lib/chevre/service/task/cancelPendingReservation.js +10 -20
  375. package/lib/chevre/service/task/cancelReservation.js +3 -12
  376. package/lib/chevre/service/task/checkMovieTicket.js +16 -19
  377. package/lib/chevre/service/task/checkResource.js +7 -16
  378. package/lib/chevre/service/task/confirmMoneyTransfer.js +3 -12
  379. package/lib/chevre/service/task/confirmPayTransaction.js +6 -12
  380. package/lib/chevre/service/task/confirmRegisterService.js +3 -12
  381. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +24 -31
  382. package/lib/chevre/service/task/confirmReserveTransaction.js +48 -45
  383. package/lib/chevre/service/task/createAccountingReport.js +14 -20
  384. package/lib/chevre/service/task/deletePerson.js +48 -60
  385. package/lib/chevre/service/task/deleteTransaction.js +3 -12
  386. package/lib/chevre/service/task/givePointAward.js +3 -12
  387. package/lib/chevre/service/task/handleNotification.js +4 -14
  388. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +6 -16
  389. package/lib/chevre/service/task/importEventsFromCOA.js +6 -16
  390. package/lib/chevre/service/task/importOffersFromCOA.js +8 -18
  391. package/lib/chevre/service/task/invalidatePaymentUrl.js +6 -12
  392. package/lib/chevre/service/task/moneyTransfer.js +3 -12
  393. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +3 -12
  394. package/lib/chevre/service/task/onAuthorizationCreated.js +11 -19
  395. package/lib/chevre/service/task/onEventChanged.js +3 -12
  396. package/lib/chevre/service/task/onOrderPaymentCompleted.js +3 -12
  397. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +7 -16
  398. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +7 -16
  399. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +8 -17
  400. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +10 -19
  401. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +8 -17
  402. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +6 -15
  403. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +14 -24
  404. package/lib/chevre/service/task/onResourceDeleted.js +17 -27
  405. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +9 -21
  406. package/lib/chevre/service/task/onResourceUpdated/onCategoryCodeUpdated.js +3 -12
  407. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +11 -23
  408. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +13 -25
  409. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +9 -15
  410. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +21 -27
  411. package/lib/chevre/service/task/onResourceUpdated.js +113 -158
  412. package/lib/chevre/service/task/pay.js +8 -16
  413. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +4 -14
  414. package/lib/chevre/service/task/payment/payByTask.js +49 -38
  415. package/lib/chevre/service/task/payment/refundByTask.js +7 -17
  416. package/lib/chevre/service/task/payment/voidPaymentByTask.js +6 -15
  417. package/lib/chevre/service/task/placeOrder.js +6 -12
  418. package/lib/chevre/service/task/publishPaymentUrl.js +9 -14
  419. package/lib/chevre/service/task/refund.js +8 -16
  420. package/lib/chevre/service/task/registerService.js +3 -12
  421. package/lib/chevre/service/task/reserve.js +3 -12
  422. package/lib/chevre/service/task/returnMoneyTransfer.js +3 -12
  423. package/lib/chevre/service/task/returnOrder.js +6 -12
  424. package/lib/chevre/service/task/returnPayTransaction.js +54 -49
  425. package/lib/chevre/service/task/returnPointAward.js +3 -12
  426. package/lib/chevre/service/task/returnReserveTransaction.js +29 -30
  427. package/lib/chevre/service/task/sendEmailMessage.js +6 -13
  428. package/lib/chevre/service/task/sendOrder.js +12 -15
  429. package/lib/chevre/service/task/syncResourcesFromCOA.js +39 -45
  430. package/lib/chevre/service/task/triggerWebhook.js +6 -12
  431. package/lib/chevre/service/task/useReservation.js +11 -14
  432. package/lib/chevre/service/task/voidMoneyTransferTransaction.js +3 -12
  433. package/lib/chevre/service/task/voidPayTransaction.js +7 -12
  434. package/lib/chevre/service/task/voidPayment.js +3 -12
  435. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -12
  436. package/lib/chevre/service/task/voidReserveTransaction.js +10 -16
  437. package/lib/chevre/service/task.js +16 -26
  438. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +9 -20
  439. package/lib/chevre/service/taskHandler/onOperationFailed.js +20 -17
  440. package/lib/chevre/service/taskHandler.js +19 -22
  441. package/lib/chevre/service/transaction/deleteTransaction.js +104 -88
  442. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +15 -9
  443. package/lib/chevre/service/transaction/moneyTransfer/factory.js +13 -4
  444. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +12 -24
  445. package/lib/chevre/service/transaction/moneyTransfer.js +119 -98
  446. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +49 -51
  447. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +14 -25
  448. package/lib/chevre/service/transaction/placeOrder/confirm/publishCode.js +4 -14
  449. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.js +3 -4
  450. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateMovieTicket.js +3 -6
  451. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +2 -3
  452. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +30 -47
  453. package/lib/chevre/service/transaction/placeOrder/confirm.js +75 -59
  454. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +31 -15
  455. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +6 -15
  456. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +6 -15
  457. package/lib/chevre/service/transaction/placeOrder/publishOrderNumberIfNotExist.js +7 -16
  458. package/lib/chevre/service/transaction/placeOrder/start/factory.js +27 -7
  459. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +53 -60
  460. package/lib/chevre/service/transaction/placeOrder/start.js +14 -18
  461. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +13 -7
  462. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +176 -190
  463. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +75 -89
  464. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +40 -48
  465. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +52 -56
  466. package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +100 -104
  467. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +60 -80
  468. package/lib/chevre/service/transaction/returnOrder/preStart.js +42 -47
  469. package/lib/chevre/service/transaction/returnOrder.js +32 -37
  470. package/lib/chevre/service/transaction.js +75 -46
  471. package/lib/chevre/service/validation/validateEvent.js +2 -11
  472. package/lib/chevre/service/validation/validateOrder.js +7 -18
  473. package/lib/chevre/service.js +85 -131
  474. package/lib/chevre/settings/aggregation.js +4 -0
  475. package/lib/chevre/settings.js +7 -1
  476. package/lib/index.js +0 -1
  477. package/package.json +6 -11
  478. package/example/src/chevre/addEventBySchedule.ts +0 -46
  479. package/example/src/idaas/auth0/adminApplications.ts +0 -183
  480. package/example/src/idaas/auth0/getToken.ts +0 -55
  481. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +0 -84
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.AssetTransactionRepo = void 0;
13
4
  const moment = require("moment");
@@ -19,36 +10,32 @@ const settings_1 = require("../settings");
19
10
  * 資産取引リポジトリ
20
11
  */
21
12
  class AssetTransactionRepo {
13
+ // private化(2022-06-08~)
14
+ transactionModel;
22
15
  constructor(connection) {
23
16
  this.transactionModel = connection.model(assetTransaction_1.modelName, (0, assetTransaction_1.createSchema)());
24
17
  }
25
- // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
26
18
  static CREATE_MONGO_CONDITIONS(params) {
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, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36;
28
19
  const andConditions = [
29
20
  { typeOf: { $eq: params.typeOf } }
30
21
  ];
31
- const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
32
- // tslint:disable-next-line:no-single-line-block-comment
22
+ const projectIdEq = params.project?.id?.$eq;
33
23
  /* istanbul ignore else */
34
24
  if (typeof projectIdEq === 'string') {
35
25
  andConditions.push({ 'project.id': { $eq: projectIdEq } });
36
26
  }
37
- // tslint:disable-next-line:no-single-line-block-comment
38
27
  /* istanbul ignore else */
39
28
  if (params.startFrom !== undefined) {
40
29
  andConditions.push({
41
30
  startDate: { $gte: params.startFrom }
42
31
  });
43
32
  }
44
- // tslint:disable-next-line:no-single-line-block-comment
45
33
  /* istanbul ignore else */
46
34
  if (params.startThrough !== undefined) {
47
35
  andConditions.push({
48
36
  startDate: { $lte: params.startThrough }
49
37
  });
50
38
  }
51
- // tslint:disable-next-line:no-single-line-block-comment
52
39
  /* istanbul ignore else */
53
40
  if (params.endFrom !== undefined) {
54
41
  andConditions.push({
@@ -58,7 +45,6 @@ class AssetTransactionRepo {
58
45
  }
59
46
  });
60
47
  }
61
- // tslint:disable-next-line:no-single-line-block-comment
62
48
  /* istanbul ignore else */
63
49
  if (params.endThrough !== undefined) {
64
50
  andConditions.push({
@@ -68,25 +54,21 @@ class AssetTransactionRepo {
68
54
  }
69
55
  });
70
56
  }
71
- // tslint:disable-next-line:no-single-line-block-comment
72
57
  /* istanbul ignore else */
73
58
  if (Array.isArray(params.ids)) {
74
59
  andConditions.push({
75
60
  _id: { $in: params.ids }
76
61
  });
77
62
  }
78
- // tslint:disable-next-line:no-single-line-block-comment
79
63
  /* istanbul ignore else */
80
64
  if (Array.isArray(params.statuses)) {
81
65
  andConditions.push({ status: { $in: params.statuses } });
82
66
  }
83
- // tslint:disable-next-line:no-single-line-block-comment
84
67
  /* istanbul ignore else */
85
- const statusIn = (_c = params.status) === null || _c === void 0 ? void 0 : _c.$in;
68
+ const statusIn = params.status?.$in;
86
69
  if (Array.isArray(statusIn)) {
87
70
  andConditions.push({ status: { $in: statusIn } });
88
71
  }
89
- // tslint:disable-next-line:no-single-line-block-comment
90
72
  /* istanbul ignore else */
91
73
  if (params.agent !== undefined) {
92
74
  if (Array.isArray(params.agent.ids)) {
@@ -95,39 +77,37 @@ class AssetTransactionRepo {
95
77
  });
96
78
  }
97
79
  }
98
- const transactionNumberEq = (_d = params.transactionNumber) === null || _d === void 0 ? void 0 : _d.$eq;
80
+ const transactionNumberEq = params.transactionNumber?.$eq;
99
81
  if (typeof transactionNumberEq === 'string') {
100
82
  andConditions.push({ transactionNumber: { $eq: transactionNumberEq } });
101
83
  }
102
- const transactionNumberIn = (_e = params.transactionNumber) === null || _e === void 0 ? void 0 : _e.$in;
84
+ const transactionNumberIn = params.transactionNumber?.$in;
103
85
  if (Array.isArray(transactionNumberIn)) {
104
86
  andConditions.push({ transactionNumber: { $in: transactionNumberIn } });
105
87
  }
106
- const tasksExportActionStatusIn = (_g = (_f = params.tasksExportAction) === null || _f === void 0 ? void 0 : _f.actionStatus) === null || _g === void 0 ? void 0 : _g.$in;
107
- // tslint:disable-next-line:no-single-line-block-comment
88
+ const tasksExportActionStatusIn = params.tasksExportAction?.actionStatus?.$in;
108
89
  /* istanbul ignore else */
109
90
  if (Array.isArray(tasksExportActionStatusIn)) {
110
91
  andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $in: tasksExportActionStatusIn } });
111
92
  }
112
- const tasksExportActionStatusEq = (_j = (_h = params.tasksExportAction) === null || _h === void 0 ? void 0 : _h.actionStatus) === null || _j === void 0 ? void 0 : _j.$eq;
113
- // tslint:disable-next-line:no-single-line-block-comment
93
+ const tasksExportActionStatusEq = params.tasksExportAction?.actionStatus?.$eq;
114
94
  /* istanbul ignore else */
115
95
  if (typeof tasksExportActionStatusEq === 'string') {
116
96
  andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $eq: tasksExportActionStatusEq } });
117
97
  }
118
98
  switch (params.typeOf) {
119
99
  case factory.assetTransactionType.Pay:
120
- const objectAccountIdEq = (_l = (_k = params.object) === null || _k === void 0 ? void 0 : _k.accountId) === null || _l === void 0 ? void 0 : _l.$eq;
100
+ const objectAccountIdEq = params.object?.accountId?.$eq;
121
101
  if (typeof objectAccountIdEq === 'string') {
122
102
  andConditions.push({ 'object.accountId': { $exists: true, $eq: objectAccountIdEq } });
123
103
  }
124
- const objectTypeOfEq = (_o = (_m = params.object) === null || _m === void 0 ? void 0 : _m.typeOf) === null || _o === void 0 ? void 0 : _o.$eq;
104
+ const objectTypeOfEq = params.object?.typeOf?.$eq;
125
105
  if (typeof objectTypeOfEq === 'string') {
126
106
  andConditions.push({ 'object.typeOf': { $exists: true, $eq: objectTypeOfEq } });
127
107
  }
128
108
  break;
129
109
  case factory.assetTransactionType.Refund:
130
- const objectAccountIdEq4refund = (_q = (_p = params.object) === null || _p === void 0 ? void 0 : _p.accountId) === null || _q === void 0 ? void 0 : _q.$eq;
110
+ const objectAccountIdEq4refund = params.object?.accountId?.$eq;
131
111
  if (typeof objectAccountIdEq4refund === 'string') {
132
112
  andConditions.push({
133
113
  'object.accountId': {
@@ -136,13 +116,13 @@ class AssetTransactionRepo {
136
116
  }
137
117
  });
138
118
  }
139
- const objectPaymentMethodIdEq4refund = (_s = (_r = params.object) === null || _r === void 0 ? void 0 : _r.paymentMethodId) === null || _s === void 0 ? void 0 : _s.$eq;
119
+ const objectPaymentMethodIdEq4refund = params.object?.paymentMethodId?.$eq;
140
120
  if (typeof objectPaymentMethodIdEq4refund === 'string') {
141
121
  andConditions.push({
142
122
  'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq4refund }
143
123
  });
144
124
  }
145
- const objectPaymentMethodIdIn4refund = (_u = (_t = params.object) === null || _t === void 0 ? void 0 : _t.paymentMethodId) === null || _u === void 0 ? void 0 : _u.$in;
125
+ const objectPaymentMethodIdIn4refund = params.object?.paymentMethodId?.$in;
146
126
  if (Array.isArray(objectPaymentMethodIdIn4refund)) {
147
127
  andConditions.push({
148
128
  'object.paymentMethodId': { $exists: true, $in: objectPaymentMethodIdIn4refund }
@@ -150,7 +130,7 @@ class AssetTransactionRepo {
150
130
  }
151
131
  break;
152
132
  case factory.assetTransactionType.MoneyTransfer:
153
- const fromLocationIdentifierEq = (_x = (_w = (_v = params.object) === null || _v === void 0 ? void 0 : _v.fromLocation) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$eq;
133
+ const fromLocationIdentifierEq = params.object?.fromLocation?.identifier?.$eq;
154
134
  if (typeof fromLocationIdentifierEq === 'string') {
155
135
  andConditions.push({
156
136
  'object.fromLocation.identifier': {
@@ -159,7 +139,7 @@ class AssetTransactionRepo {
159
139
  }
160
140
  });
161
141
  }
162
- const toLocationIdentifierEq = (_0 = (_z = (_y = params.object) === null || _y === void 0 ? void 0 : _y.toLocation) === null || _z === void 0 ? void 0 : _z.identifier) === null || _0 === void 0 ? void 0 : _0.$eq;
142
+ const toLocationIdentifierEq = params.object?.toLocation?.identifier?.$eq;
163
143
  if (typeof toLocationIdentifierEq === 'string') {
164
144
  andConditions.push({
165
145
  'object.toLocation.identifier': {
@@ -168,7 +148,7 @@ class AssetTransactionRepo {
168
148
  }
169
149
  });
170
150
  }
171
- const pendingTransactionIdentifierEq = (_3 = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.pendingTransaction) === null || _2 === void 0 ? void 0 : _2.identifier) === null || _3 === void 0 ? void 0 : _3.$eq;
151
+ const pendingTransactionIdentifierEq = params.object?.pendingTransaction?.identifier?.$eq;
172
152
  if (typeof pendingTransactionIdentifierEq === 'string') {
173
153
  andConditions.push({
174
154
  'object.pendingTransaction.identifier': {
@@ -179,13 +159,13 @@ class AssetTransactionRepo {
179
159
  }
180
160
  break;
181
161
  case factory.assetTransactionType.CancelReservation:
182
- const objectReservationNumberIn4cancelReservation = (_5 = (_4 = params.object) === null || _4 === void 0 ? void 0 : _4.reservationNumber) === null || _5 === void 0 ? void 0 : _5.$in;
162
+ const objectReservationNumberIn4cancelReservation = params.object?.reservationNumber?.$in;
183
163
  if (Array.isArray(objectReservationNumberIn4cancelReservation)) {
184
164
  andConditions.push({
185
165
  'object.reservationNumber': { $exists: true, $in: objectReservationNumberIn4cancelReservation }
186
166
  });
187
167
  }
188
- const objectReservationNumberEq4cancelReservation = (_7 = (_6 = params.object) === null || _6 === void 0 ? void 0 : _6.reservationNumber) === null || _7 === void 0 ? void 0 : _7.$eq;
168
+ const objectReservationNumberEq4cancelReservation = params.object?.reservationNumber?.$eq;
189
169
  if (typeof objectReservationNumberEq4cancelReservation === 'string') {
190
170
  andConditions.push({
191
171
  'object.reservationNumber': { $exists: true, $eq: objectReservationNumberEq4cancelReservation }
@@ -193,11 +173,11 @@ class AssetTransactionRepo {
193
173
  }
194
174
  break;
195
175
  case factory.assetTransactionType.Reserve:
196
- const objectProviderIdEq = (_10 = (_9 = (_8 = params.object) === null || _8 === void 0 ? void 0 : _8.provider) === null || _9 === void 0 ? void 0 : _9.id) === null || _10 === void 0 ? void 0 : _10.$eq;
176
+ const objectProviderIdEq = params.object?.provider?.id?.$eq;
197
177
  if (typeof objectProviderIdEq === 'string') {
198
178
  andConditions.push({ 'object.provider.id': { $exists: true, $eq: objectProviderIdEq } });
199
179
  }
200
- const objectReservationForIdEq = (_13 = (_12 = (_11 = params.object) === null || _11 === void 0 ? void 0 : _11.reservationFor) === null || _12 === void 0 ? void 0 : _12.id) === null || _13 === void 0 ? void 0 : _13.$eq;
180
+ const objectReservationForIdEq = params.object?.reservationFor?.id?.$eq;
201
181
  if (typeof objectReservationForIdEq === 'string') {
202
182
  andConditions.push({
203
183
  'object.reservationFor.id': {
@@ -206,19 +186,19 @@ class AssetTransactionRepo {
206
186
  }
207
187
  });
208
188
  }
209
- const objectReservationNumberIn = (_15 = (_14 = params.object) === null || _14 === void 0 ? void 0 : _14.reservationNumber) === null || _15 === void 0 ? void 0 : _15.$in;
189
+ const objectReservationNumberIn = params.object?.reservationNumber?.$in;
210
190
  if (Array.isArray(objectReservationNumberIn)) {
211
191
  andConditions.push({
212
192
  'object.reservationNumber': { $exists: true, $in: objectReservationNumberIn }
213
193
  });
214
194
  }
215
- const objectReservationNumberEq = (_17 = (_16 = params.object) === null || _16 === void 0 ? void 0 : _16.reservationNumber) === null || _17 === void 0 ? void 0 : _17.$eq;
195
+ const objectReservationNumberEq = params.object?.reservationNumber?.$eq;
216
196
  if (typeof objectReservationNumberEq === 'string') {
217
197
  andConditions.push({
218
198
  'object.reservationNumber': { $exists: true, $eq: objectReservationNumberEq }
219
199
  });
220
200
  }
221
- const objectSubReservationIdIn = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.reservations) === null || _19 === void 0 ? void 0 : _19.id) === null || _20 === void 0 ? void 0 : _20.$in;
201
+ const objectSubReservationIdIn = params.object?.reservations?.id?.$in;
222
202
  if (Array.isArray(objectSubReservationIdIn)) {
223
203
  andConditions.push({
224
204
  'object.subReservation.id': {
@@ -253,7 +233,7 @@ class AssetTransactionRepo {
253
233
  }
254
234
  }
255
235
  }
256
- const objectUnderNameIdEq = (_23 = (_22 = (_21 = params.object) === null || _21 === void 0 ? void 0 : _21.underName) === null || _22 === void 0 ? void 0 : _22.id) === null || _23 === void 0 ? void 0 : _23.$eq;
236
+ const objectUnderNameIdEq = params.object?.underName?.id?.$eq;
257
237
  if (typeof objectUnderNameIdEq === 'string') {
258
238
  andConditions.push({
259
239
  'object.underName.id': {
@@ -262,7 +242,7 @@ class AssetTransactionRepo {
262
242
  }
263
243
  });
264
244
  }
265
- const objectSubReservationSeatNumberEq = (_28 = (_27 = (_26 = (_25 = (_24 = params.object) === null || _24 === void 0 ? void 0 : _24.reservations) === null || _25 === void 0 ? void 0 : _25.reservedTicket) === null || _26 === void 0 ? void 0 : _26.ticketedSeat) === null || _27 === void 0 ? void 0 : _27.seatNumber) === null || _28 === void 0 ? void 0 : _28.$eq;
245
+ const objectSubReservationSeatNumberEq = params.object?.reservations?.reservedTicket?.ticketedSeat?.seatNumber?.$eq;
266
246
  if (typeof objectSubReservationSeatNumberEq === 'string') {
267
247
  andConditions.push({
268
248
  'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
@@ -273,7 +253,7 @@ class AssetTransactionRepo {
273
253
  }
274
254
  break;
275
255
  case factory.assetTransactionType.RegisterService:
276
- const objectItemOfferedServiceOutputIdentifierEq = (_32 = (_31 = (_30 = (_29 = params.object) === null || _29 === void 0 ? void 0 : _29.itemOffered) === null || _30 === void 0 ? void 0 : _30.serviceOutput) === null || _31 === void 0 ? void 0 : _31.identifier) === null || _32 === void 0 ? void 0 : _32.$eq;
256
+ const objectItemOfferedServiceOutputIdentifierEq = params.object?.itemOffered?.serviceOutput?.identifier?.$eq;
277
257
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
278
258
  andConditions.push({
279
259
  'object.itemOffered.serviceOutput.identifier': {
@@ -282,7 +262,7 @@ class AssetTransactionRepo {
282
262
  }
283
263
  });
284
264
  }
285
- const objectItemOfferedServiceOutputIdentifierIn = (_36 = (_35 = (_34 = (_33 = params.object) === null || _33 === void 0 ? void 0 : _33.itemOffered) === null || _34 === void 0 ? void 0 : _34.serviceOutput) === null || _35 === void 0 ? void 0 : _35.identifier) === null || _36 === void 0 ? void 0 : _36.$in;
265
+ const objectItemOfferedServiceOutputIdentifierIn = params.object?.itemOffered?.serviceOutput?.identifier?.$in;
286
266
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
287
267
  andConditions.push({
288
268
  'object.itemOffered.serviceOutput.identifier': {
@@ -299,213 +279,223 @@ class AssetTransactionRepo {
299
279
  /**
300
280
  * 取引を開始する
301
281
  */
302
- start(params
282
+ async start(params
303
283
  // ): Promise<Pick<factory.assetTransaction.ITransaction<T>, 'id'>> {
304
284
  ) {
305
- return __awaiter(this, void 0, void 0, function* () {
306
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate: new Date(), endDate: undefined, tasksExportAction: {
307
- actionStatus: factory.actionStatusType.PotentialActionStatus
308
- } }))
309
- .then((doc) => doc.toObject());
310
- });
311
- }
312
- startWithMinimalResponse(params) {
313
- return __awaiter(this, void 0, void 0, function* () {
314
- var _a, _b;
315
- const { typeOf } = params;
316
- const startDate = new Date();
317
- const creatingTransaction = Object.assign(Object.assign({}, params), { typeOf, status: factory.transactionStatusType.InProgress, startDate,
318
- // endDate: undefined,
319
- tasksExportAction: {
320
- actionStatus: factory.actionStatusType.PotentialActionStatus
321
- } });
322
- const result = yield this.transactionModel.insertMany(creatingTransaction, { ordered: false, rawResult: true });
323
- const id = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
324
- if (typeof id !== 'string') {
325
- throw new factory.errors.Internal('assetTransaction not saved');
285
+ return this.transactionModel.create({
286
+ ...params,
287
+ typeOf: params.typeOf,
288
+ status: factory.transactionStatusType.InProgress,
289
+ startDate: new Date(),
290
+ endDate: undefined,
291
+ tasksExportAction: {
292
+ actionStatus: factory.actionStatusType.PotentialActionStatus
326
293
  }
327
- return { id, startDate };
328
- });
294
+ // tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported // discontinue(2024-06-20~)
295
+ })
296
+ .then((doc) => doc.toObject());
329
297
  }
330
- findById(params, inclusion) {
331
- return __awaiter(this, void 0, void 0, function* () {
332
- let projection = {};
333
- if (Array.isArray(inclusion) && inclusion.length > 0) {
334
- inclusion.forEach((field) => {
335
- projection[field] = 1;
336
- });
337
- }
338
- else {
339
- projection = {};
298
+ async startWithMinimalResponse(params) {
299
+ const { typeOf } = params;
300
+ const startDate = new Date();
301
+ const creatingTransaction = {
302
+ ...params,
303
+ typeOf,
304
+ status: factory.transactionStatusType.InProgress,
305
+ startDate,
306
+ // endDate: undefined,
307
+ tasksExportAction: {
308
+ actionStatus: factory.actionStatusType.PotentialActionStatus
340
309
  }
341
- const doc = yield this.transactionModel.findOne({
342
- _id: { $eq: params.id },
343
- typeOf: { $eq: params.typeOf }
344
- }, projection)
345
- .exec();
346
- if (doc === null) {
347
- throw new factory.errors.NotFound(this.transactionModel.modelName);
348
- }
349
- return doc.toObject();
350
- });
310
+ };
311
+ const result = await this.transactionModel.insertMany(creatingTransaction, { ordered: false, rawResult: true });
312
+ const id = result.insertedIds?.[0]?.toHexString();
313
+ if (typeof id !== 'string') {
314
+ throw new factory.errors.Internal('assetTransaction not saved');
315
+ }
316
+ return { id, startDate };
351
317
  }
352
- findByTransactionNumber(params, inclusion) {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- let projection = {};
355
- if (Array.isArray(inclusion) && inclusion.length > 0) {
356
- inclusion.forEach((field) => {
357
- projection[field] = 1;
358
- });
359
- }
360
- else {
361
- projection = {};
362
- }
363
- const doc = yield this.transactionModel.findOne({
364
- transactionNumber: { $eq: params.transactionNumber },
365
- typeOf: { $eq: params.typeOf }
366
- }, projection)
367
- .exec();
368
- if (doc === null) {
369
- throw new factory.errors.NotFound(this.transactionModel.modelName);
370
- }
371
- return doc.toObject();
372
- });
318
+ async findById(params, inclusion) {
319
+ let projection = {};
320
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
321
+ inclusion.forEach((field) => {
322
+ projection[field] = 1;
323
+ });
324
+ }
325
+ else {
326
+ projection = {};
327
+ }
328
+ const doc = await this.transactionModel.findOne({
329
+ _id: { $eq: params.id },
330
+ typeOf: { $eq: params.typeOf }
331
+ }, projection)
332
+ .exec();
333
+ if (doc === null) {
334
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
335
+ }
336
+ return doc.toObject();
373
337
  }
374
- addReservations(params) {
375
- return __awaiter(this, void 0, void 0, function* () {
376
- const doc = yield this.transactionModel.findOneAndUpdate({
377
- _id: { $eq: params.id },
378
- typeOf: { $eq: params.typeOf },
379
- status: { $eq: factory.transactionStatusType.InProgress }
380
- }, {
381
- $set: {
382
- 'object.acceptedOffer': params.object.acceptedOffer,
383
- // 'object.issuedThrough': params.object.issuedThrough, // start時保管へ移行(2024-07-01~)
384
- // 'object.reservationFor': params.object.reservationFor, // start時保管へ移行(2024-07-01~)
385
- 'object.subReservation': params.object.subReservation
386
- }
387
- }, { new: false, projection: { _id: 1 } })
388
- .exec();
389
- if (doc === null) {
390
- throw new factory.errors.NotFound(this.transactionModel.modelName);
338
+ async findByTransactionNumber(params, inclusion) {
339
+ let projection = {};
340
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
341
+ inclusion.forEach((field) => {
342
+ projection[field] = 1;
343
+ });
344
+ }
345
+ else {
346
+ projection = {};
347
+ }
348
+ const doc = await this.transactionModel.findOne({
349
+ transactionNumber: { $eq: params.transactionNumber },
350
+ typeOf: { $eq: params.typeOf }
351
+ }, projection)
352
+ .exec();
353
+ if (doc === null) {
354
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
355
+ }
356
+ return doc.toObject();
357
+ }
358
+ async addReservations(params) {
359
+ const doc = await this.transactionModel.findOneAndUpdate({
360
+ _id: { $eq: params.id },
361
+ typeOf: { $eq: params.typeOf },
362
+ status: { $eq: factory.transactionStatusType.InProgress }
363
+ }, {
364
+ $set: {
365
+ 'object.acceptedOffer': params.object.acceptedOffer,
366
+ // 'object.issuedThrough': params.object.issuedThrough, // start時保管へ移行(2024-07-01~)
367
+ // 'object.reservationFor': params.object.reservationFor, // start時保管へ移行(2024-07-01~)
368
+ 'object.subReservation': params.object.subReservation
391
369
  }
392
- // return doc.toObject();
393
- });
370
+ }, { new: false, projection: { _id: 1 } })
371
+ .exec();
372
+ if (doc === null) {
373
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
374
+ }
375
+ // return doc.toObject();
394
376
  }
395
377
  /**
396
378
  * 取引を確定する
397
379
  */
398
- confirm(params) {
399
- return __awaiter(this, void 0, void 0, function* () {
400
- var _a, _b, _c, _d;
401
- const doc = yield this.transactionModel.findOneAndUpdate({
402
- _id: { $eq: params.id },
403
- typeOf: { $eq: params.typeOf },
404
- status: { $eq: factory.transactionStatusType.InProgress }
405
- }, Object.assign(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')
380
+ async confirm(params) {
381
+ const doc = await this.transactionModel.findOneAndUpdate({
382
+ _id: { $eq: params.id },
383
+ typeOf: { $eq: params.typeOf },
384
+ status: { $eq: factory.transactionStatusType.InProgress }
385
+ }, {
386
+ status: factory.transactionStatusType.Confirmed, // ステータス変更
387
+ endDate: new Date(),
388
+ result: params.result, // resultを更新
389
+ potentialActions: params.potentialActions, // resultを更新
390
+ ...(typeof params.object?.underName?.typeOf === 'string')
406
391
  ? { 'object.underName': params.object.underName }
407
- : undefined), (typeof ((_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.paymentMethod) === null || _d === void 0 ? void 0 : _d.identifier) === 'string')
392
+ : undefined,
393
+ ...(typeof params.object?.paymentMethod?.identifier === 'string')
408
394
  ? { 'object.paymentMethod.identifier': params.object.paymentMethod.identifier }
409
- : undefined), {
410
- new: true,
411
- projection: { _id: 1 }
412
- })
413
- .exec();
414
- // NotFoundであれば取引状態確認
415
- if (doc === null) {
416
- const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id }, ['status']);
417
- if (transaction.status === factory.transactionStatusType.Confirmed) {
418
- // すでに確定済の場合スルー
419
- }
420
- else if (transaction.status === factory.transactionStatusType.Expired) {
421
- throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${params.id} already expired`);
422
- }
423
- else if (transaction.status === factory.transactionStatusType.Canceled) {
424
- throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${params.id} already canceled`);
425
- }
426
- else {
427
- throw new factory.errors.NotFound(this.transactionModel.modelName);
428
- }
395
+ : undefined
396
+ }, {
397
+ new: true,
398
+ projection: { _id: 1 }
399
+ })
400
+ .exec();
401
+ // NotFoundであれば取引状態確認
402
+ if (doc === null) {
403
+ const transaction = await this.findById({ typeOf: params.typeOf, id: params.id }, ['status']);
404
+ if (transaction.status === factory.transactionStatusType.Confirmed) {
405
+ // すでに確定済の場合スルー
429
406
  }
430
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
431
- id: params.id,
432
- typeOf: params.typeOf,
433
- status: factory.transactionStatusType.Confirmed
434
- });
407
+ else if (transaction.status === factory.transactionStatusType.Expired) {
408
+ throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${params.id} already expired`);
409
+ }
410
+ else if (transaction.status === factory.transactionStatusType.Canceled) {
411
+ throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${params.id} already canceled`);
412
+ }
413
+ else {
414
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
415
+ }
416
+ }
417
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
418
+ id: params.id,
419
+ typeOf: params.typeOf,
420
+ status: factory.transactionStatusType.Confirmed
435
421
  });
436
422
  }
437
423
  /**
438
424
  * 取引を開始&確定
439
425
  */
440
- startAndConfirm(params) {
441
- return __awaiter(this, void 0, void 0, function* () {
442
- const startDate = new Date();
443
- yield this.transactionModel.create(Object.assign(Object.assign({}, params), { _id: params.id, typeOf: params.typeOf, startDate, status: factory.transactionStatusType.Confirmed, tasksExportAction: {
444
- actionStatus: factory.actionStatusType.PotentialActionStatus
445
- },
446
- // tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, // discontinue(2024-06-20~)
447
- endDate: startDate, result: params.result, potentialActions: params.potentialActions }))
448
- .then((doc) => doc.toObject());
449
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
450
- id: params.id,
451
- typeOf: params.typeOf,
452
- status: factory.transactionStatusType.Confirmed
453
- });
454
- return { id: params.id };
426
+ async startAndConfirm(params) {
427
+ const startDate = new Date();
428
+ await this.transactionModel.create({
429
+ ...params,
430
+ _id: params.id,
431
+ typeOf: params.typeOf,
432
+ startDate,
433
+ status: factory.transactionStatusType.Confirmed,
434
+ tasksExportAction: {
435
+ actionStatus: factory.actionStatusType.PotentialActionStatus
436
+ },
437
+ // tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, // discontinue(2024-06-20~)
438
+ endDate: startDate,
439
+ result: params.result,
440
+ potentialActions: params.potentialActions
441
+ })
442
+ .then((doc) => doc.toObject());
443
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
444
+ id: params.id,
445
+ typeOf: params.typeOf,
446
+ status: factory.transactionStatusType.Confirmed
455
447
  });
448
+ return { id: params.id };
456
449
  }
457
- countPotentiallyExportTasks(params) {
458
- return __awaiter(this, void 0, void 0, function* () {
459
- const { endDate, limit } = params;
460
- const endDateLt = endDate === null || endDate === void 0 ? void 0 : endDate.$lt;
461
- if (!(endDateLt instanceof Date)) {
462
- throw new factory.errors.Argument('endDate.$lt', 'must be Date');
463
- }
464
- const query = this.transactionModel.countDocuments({
465
- status: {
466
- $in: [
467
- factory.transactionStatusType.Canceled,
468
- factory.transactionStatusType.Confirmed,
469
- factory.transactionStatusType.Expired
470
- ]
471
- },
472
- 'tasksExportAction.actionStatus': {
473
- $exists: true,
474
- $eq: factory.actionStatusType.PotentialActionStatus
475
- },
476
- endDate: { $exists: true, $lt: endDateLt }
477
- });
478
- if (typeof limit === 'number' && limit >= 0) {
479
- query.limit(limit);
480
- }
481
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
482
- .exec();
483
- return { count };
450
+ async countPotentiallyExportTasks(params) {
451
+ const { endDate, limit } = params;
452
+ const endDateLt = endDate?.$lt;
453
+ if (!(endDateLt instanceof Date)) {
454
+ throw new factory.errors.Argument('endDate.$lt', 'must be Date');
455
+ }
456
+ const query = this.transactionModel.countDocuments({
457
+ status: {
458
+ $in: [
459
+ factory.transactionStatusType.Canceled,
460
+ factory.transactionStatusType.Confirmed,
461
+ factory.transactionStatusType.Expired
462
+ ]
463
+ },
464
+ 'tasksExportAction.actionStatus': {
465
+ $exists: true,
466
+ $eq: factory.actionStatusType.PotentialActionStatus
467
+ },
468
+ endDate: { $exists: true, $lt: endDateLt }
484
469
  });
470
+ if (typeof limit === 'number' && limit >= 0) {
471
+ query.limit(limit);
472
+ }
473
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
474
+ .exec();
475
+ return { count };
485
476
  }
486
477
  /**
487
478
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
488
479
  */
489
- startExportTasks(params) {
490
- return __awaiter(this, void 0, void 0, function* () {
491
- var _a, _b, _c;
492
- const statusEq = (_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq;
493
- const endDateLt = (_b = params.endDate) === null || _b === void 0 ? void 0 : _b.$lt;
494
- if (typeof statusEq === 'string') {
495
- switch (statusEq) {
496
- case factory.transactionStatusType.InProgress:
497
- throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
498
- default:
499
- // no op
500
- }
501
- }
502
- if (!(endDateLt instanceof Date)) {
503
- throw new factory.errors.Argument('endDate.$lt', 'must be Date');
480
+ async startExportTasks(params) {
481
+ const statusEq = params.status?.$eq;
482
+ const endDateLt = params.endDate?.$lt;
483
+ if (typeof statusEq === 'string') {
484
+ switch (statusEq) {
485
+ case factory.transactionStatusType.InProgress:
486
+ throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
487
+ default:
488
+ // no op
504
489
  }
505
- // const typeOfIn = params.typeOf?.$in;
506
- const query = this.transactionModel.findOneAndUpdate(Object.assign({
507
- // ...(Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined,
508
- status: Object.assign({}, (typeof statusEq === 'string')
490
+ }
491
+ if (!(endDateLt instanceof Date)) {
492
+ throw new factory.errors.Argument('endDate.$lt', 'must be Date');
493
+ }
494
+ // const typeOfIn = params.typeOf?.$in;
495
+ const query = this.transactionModel.findOneAndUpdate({
496
+ // ...(Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined,
497
+ status: {
498
+ ...(typeof statusEq === 'string')
509
499
  ? { $eq: statusEq }
510
500
  : {
511
501
  $in: [
@@ -513,31 +503,34 @@ class AssetTransactionRepo {
513
503
  factory.transactionStatusType.Confirmed,
514
504
  factory.transactionStatusType.Expired
515
505
  ]
516
- }), 'tasksExportAction.actionStatus': {
517
- $exists: true,
518
- $eq: factory.actionStatusType.PotentialActionStatus
519
- }, endDate: { $exists: true, $lt: endDateLt } }, (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
520
- 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
521
- 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
522
- 'tasksExportAction.startDate': new Date()
523
- }, {
524
- new: true,
525
- projection: {
526
- // _id: 1,
527
- _id: 0,
528
- id: { $toString: '$_id' },
529
- typeOf: 1
530
- }
531
- });
532
- if (typeof ((_c = params.sort) === null || _c === void 0 ? void 0 : _c.endDate) === 'number') {
533
- query.sort(params.sort);
506
+ }
507
+ },
508
+ 'tasksExportAction.actionStatus': {
509
+ $exists: true,
510
+ $eq: factory.actionStatusType.PotentialActionStatus
511
+ },
512
+ endDate: { $exists: true, $lt: endDateLt },
513
+ ...(typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined
514
+ }, {
515
+ 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
516
+ 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
517
+ 'tasksExportAction.startDate': new Date()
518
+ }, {
519
+ new: true,
520
+ projection: {
521
+ // _id: 1,
522
+ _id: 0,
523
+ id: { $toString: '$_id' },
524
+ typeOf: 1
534
525
  }
535
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
536
- .lean()
537
- .exec()
538
- // tslint:disable-next-line:no-null-keyword
539
- .then((doc) => (doc === null) ? null : doc);
540
526
  });
527
+ if (typeof params.sort?.endDate === 'number') {
528
+ query.sort(params.sort);
529
+ }
530
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
531
+ .lean()
532
+ .exec()
533
+ .then((doc) => (doc === null) ? null : doc);
541
534
  }
542
535
  // discontinue(2025-03-10~)
543
536
  // public async reexportTasksByExportAction(params: {
@@ -595,418 +588,389 @@ class AssetTransactionRepo {
595
588
  * PotentialActionStatusに変更する
596
589
  * 2025-03-10~
597
590
  */
598
- reExportAction(params) {
599
- return __awaiter(this, void 0, void 0, function* () {
600
- const { startDate } = params;
601
- if (!(startDate.$lt instanceof Date)) {
602
- throw new factory.errors.Argument('startDate.$lt', 'must be Date');
591
+ async reExportAction(params) {
592
+ const { startDate } = params;
593
+ if (!(startDate.$lt instanceof Date)) {
594
+ throw new factory.errors.Argument('startDate.$lt', 'must be Date');
595
+ }
596
+ return this.transactionModel.updateMany({
597
+ 'tasksExportAction.actionStatus': {
598
+ $exists: true,
599
+ $eq: factory.actionStatusType.ActiveActionStatus
600
+ },
601
+ 'tasksExportAction.startDate': {
602
+ $exists: true,
603
+ $lt: startDate.$lt
603
604
  }
604
- return this.transactionModel.updateMany({
605
- 'tasksExportAction.actionStatus': {
606
- $exists: true,
607
- $eq: factory.actionStatusType.ActiveActionStatus
608
- },
609
- 'tasksExportAction.startDate': {
610
- $exists: true,
611
- $lt: startDate.$lt
612
- }
613
- }, {
614
- $set: {
615
- tasksExportAction: {
616
- actionStatus: factory.actionStatusType.PotentialActionStatus
617
- }
605
+ }, {
606
+ $set: {
607
+ tasksExportAction: {
608
+ actionStatus: factory.actionStatusType.PotentialActionStatus
618
609
  }
619
- })
620
- .exec();
621
- });
610
+ }
611
+ })
612
+ .exec();
622
613
  }
623
614
  /**
624
615
  * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
625
616
  */
626
- exportTasksMany(params) {
627
- return __awaiter(this, void 0, void 0, function* () {
628
- const delayedTransactions = yield this.transactionModel.find({
629
- status: { $in: params.status.$in },
630
- 'tasksExportAction.actionStatus': {
631
- $exists: true,
632
- $eq: factory.actionStatusType.PotentialActionStatus
633
- },
634
- endDate: {
635
- $exists: true,
636
- $lt: moment(params.now)
637
- .add(-params.delayInSeconds, 'seconds')
638
- .toDate()
639
- }
640
- })
641
- .select({
642
- _id: 0,
643
- id: { $toString: '$_id' },
644
- typeOf: 1,
645
- status: 1
646
- })
647
- .limit(params.limit)
648
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
649
- .lean()
650
- .exec();
651
- if (delayedTransactions.length > 0) {
652
- delayedTransactions.forEach((delayedTransaction) => {
653
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
654
- id: delayedTransaction.id,
655
- typeOf: delayedTransaction.typeOf,
656
- status: delayedTransaction.status
657
- });
658
- });
617
+ async exportTasksMany(params) {
618
+ const delayedTransactions = await this.transactionModel.find({
619
+ status: { $in: params.status.$in },
620
+ 'tasksExportAction.actionStatus': {
621
+ $exists: true,
622
+ $eq: factory.actionStatusType.PotentialActionStatus
623
+ },
624
+ endDate: {
625
+ $exists: true,
626
+ $lt: moment(params.now)
627
+ .add(-params.delayInSeconds, 'seconds')
628
+ .toDate()
659
629
  }
660
- return delayedTransactions;
661
- });
630
+ })
631
+ .select({
632
+ _id: 0,
633
+ id: { $toString: '$_id' },
634
+ typeOf: 1,
635
+ status: 1
636
+ })
637
+ .limit(params.limit)
638
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
639
+ .lean()
640
+ .exec();
641
+ if (delayedTransactions.length > 0) {
642
+ delayedTransactions.forEach((delayedTransaction) => {
643
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
644
+ id: delayedTransaction.id,
645
+ typeOf: delayedTransaction.typeOf,
646
+ status: delayedTransaction.status
647
+ });
648
+ });
649
+ }
650
+ return delayedTransactions;
662
651
  }
663
652
  /**
664
653
  * set task status exported by transaction id
665
654
  * IDでタスクをエクスポート済に変更する
666
655
  */
667
- setTasksExportedById(params) {
668
- return __awaiter(this, void 0, void 0, function* () {
669
- const endDate = new Date();
670
- yield this.transactionModel.updateOne({
671
- _id: { $eq: params.id },
672
- // remove dependency on tasksExportationStatus(2024-06-13~)
673
- // tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
674
- 'tasksExportAction.actionStatus': {
675
- $exists: true,
676
- $eq: factory.actionStatusType.ActiveActionStatus
677
- }
678
- }, {
679
- // tasksExportationStatus: factory.transactionTasksExportationStatus.Exported, // discontinue(2024-06-20~)
680
- // tasksExportedAt: endDate, // discontinue(2024-06-20~)
681
- 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
682
- 'tasksExportAction.endDate': endDate
683
- })
684
- .exec();
685
- });
656
+ async setTasksExportedById(params) {
657
+ const endDate = new Date();
658
+ await this.transactionModel.updateOne({
659
+ _id: { $eq: params.id },
660
+ // remove dependency on tasksExportationStatus(2024-06-13~)
661
+ // tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
662
+ 'tasksExportAction.actionStatus': {
663
+ $exists: true,
664
+ $eq: factory.actionStatusType.ActiveActionStatus
665
+ }
666
+ }, {
667
+ // tasksExportationStatus: factory.transactionTasksExportationStatus.Exported, // discontinue(2024-06-20~)
668
+ // tasksExportedAt: endDate, // discontinue(2024-06-20~)
669
+ 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
670
+ 'tasksExportAction.endDate': endDate
671
+ })
672
+ .exec();
686
673
  }
687
674
  /**
688
675
  * add(2025-03-17~)
689
676
  */
690
- countPotentiallyExpired(params) {
691
- return __awaiter(this, void 0, void 0, function* () {
692
- const { expires, limit } = params;
693
- const query = this.transactionModel.countDocuments({
694
- status: { $eq: factory.transactionStatusType.InProgress },
695
- expires: { $lt: expires.$lt }
696
- });
697
- if (typeof limit === 'number' && limit >= 0) {
698
- query.limit(limit);
699
- }
700
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
701
- .exec();
702
- return { count };
677
+ async countPotentiallyExpired(params) {
678
+ const { expires, limit } = params;
679
+ const query = this.transactionModel.countDocuments({
680
+ status: { $eq: factory.transactionStatusType.InProgress },
681
+ expires: { $lt: expires.$lt }
703
682
  });
683
+ if (typeof limit === 'number' && limit >= 0) {
684
+ query.limit(limit);
685
+ }
686
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
687
+ .exec();
688
+ return { count };
704
689
  }
705
690
  /**
706
691
  * add(2025-03-12~)
707
692
  */
708
- makeOneExpiredIfExists(params) {
709
- return __awaiter(this, void 0, void 0, function* () {
710
- const endDate = new Date();
711
- const sort = {
712
- expires: factory.sortType.Ascending
713
- };
714
- const doc = yield this.transactionModel.findOneAndUpdate({
715
- status: { $eq: factory.transactionStatusType.InProgress },
716
- expires: { $lt: params.expires.$lt }
717
- }, {
718
- status: factory.transactionStatusType.Expired,
719
- endDate
720
- }, {
721
- new: true,
722
- projection: {
723
- _id: 0,
724
- id: { $toString: '$_id' },
725
- typeOf: 1
726
- }
727
- })
728
- .sort(sort)
729
- .lean()
730
- .exec();
731
- if (doc === null) {
732
- // no op
733
- }
734
- else {
735
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
736
- id: doc.id,
737
- typeOf: doc.typeOf,
738
- status: factory.transactionStatusType.Expired
739
- });
740
- return doc;
693
+ async makeOneExpiredIfExists(params) {
694
+ const endDate = new Date();
695
+ const sort = {
696
+ expires: factory.sortType.Ascending
697
+ };
698
+ const doc = await this.transactionModel.findOneAndUpdate({
699
+ status: { $eq: factory.transactionStatusType.InProgress },
700
+ expires: { $lt: params.expires.$lt }
701
+ }, {
702
+ status: factory.transactionStatusType.Expired,
703
+ endDate
704
+ }, {
705
+ new: true,
706
+ projection: {
707
+ _id: 0,
708
+ id: { $toString: '$_id' },
709
+ typeOf: 1
741
710
  }
742
- });
711
+ })
712
+ .sort(sort)
713
+ .lean()
714
+ .exec();
715
+ if (doc === null) {
716
+ // no op
717
+ }
718
+ else {
719
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
720
+ id: doc.id,
721
+ typeOf: doc.typeOf,
722
+ status: factory.transactionStatusType.Expired
723
+ });
724
+ return doc;
725
+ }
743
726
  }
744
727
  /**
745
728
  * 取引を期限切れにする
746
729
  */
747
- makeExpired(params) {
748
- return __awaiter(this, void 0, void 0, function* () {
749
- // IDをemitしたいのでまずリスト検索(2023-04-27~)
750
- const expiringTransactions = yield this.transactionModel.find({
730
+ async makeExpired(params) {
731
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
732
+ const expiringTransactions = await this.transactionModel.find({
733
+ status: { $eq: factory.transactionStatusType.InProgress },
734
+ expires: { $lt: params.expires.$lt }
735
+ })
736
+ .select({
737
+ _id: 1,
738
+ typeOf: 1
739
+ })
740
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
741
+ .exec();
742
+ if (expiringTransactions.length > 0) {
743
+ // ステータスと期限を見て更新
744
+ await this.transactionModel.updateMany({
745
+ _id: { $in: expiringTransactions.map((t) => t.id) },
751
746
  status: { $eq: factory.transactionStatusType.InProgress },
752
747
  expires: { $lt: params.expires.$lt }
748
+ }, {
749
+ status: factory.transactionStatusType.Expired,
750
+ endDate: new Date()
753
751
  })
754
- .select({
755
- _id: 1,
756
- typeOf: 1
757
- })
758
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
759
752
  .exec();
760
- if (expiringTransactions.length > 0) {
761
- // ステータスと期限を見て更新
762
- yield this.transactionModel.updateMany({
763
- _id: { $in: expiringTransactions.map((t) => t.id) },
764
- status: { $eq: factory.transactionStatusType.InProgress },
765
- expires: { $lt: params.expires.$lt }
766
- }, {
767
- status: factory.transactionStatusType.Expired,
768
- endDate: new Date()
769
- })
770
- .exec();
771
- expiringTransactions.forEach((expiringTransaction) => {
772
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
773
- id: expiringTransaction.id,
774
- typeOf: expiringTransaction.typeOf,
775
- status: factory.transactionStatusType.Expired
776
- });
753
+ expiringTransactions.forEach((expiringTransaction) => {
754
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
755
+ id: expiringTransaction.id,
756
+ typeOf: expiringTransaction.typeOf,
757
+ status: factory.transactionStatusType.Expired
777
758
  });
778
- }
779
- });
759
+ });
760
+ }
780
761
  }
781
762
  /**
782
763
  * 取引を中止する
783
764
  */
784
- cancel(params) {
785
- return __awaiter(this, void 0, void 0, function* () {
786
- // 進行中ステータスの取引を中止する
787
- 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')
765
+ async cancel(params) {
766
+ // 進行中ステータスの取引を中止する
767
+ const doc = await this.transactionModel.findOneAndUpdate({
768
+ typeOf: { $eq: params.typeOf },
769
+ ...(typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined,
770
+ ...(typeof params.transactionNumber === 'string')
788
771
  ? { transactionNumber: { $eq: params.transactionNumber } }
789
- : undefined), { status: { $eq: factory.transactionStatusType.InProgress } }), {
790
- $set: {
791
- status: factory.transactionStatusType.Canceled,
792
- endDate: new Date()
793
- }
794
- }, {
795
- new: true,
796
- projection: { _id: 1 }
797
- })
798
- .exec();
799
- let result;
800
- // NotFoundであれば取引状態確認
801
- if (doc === null) {
802
- let transaction;
803
- if (typeof params.id === 'string') {
804
- transaction = yield this.findById({ typeOf: params.typeOf, id: params.id }, ['status']);
805
- }
806
- else if (typeof params.transactionNumber === 'string') {
807
- transaction = yield this.findByTransactionNumber({
808
- typeOf: params.typeOf,
809
- transactionNumber: params.transactionNumber
810
- }, ['status']);
811
- }
812
- else {
813
- throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
814
- }
815
- if (transaction.status === factory.transactionStatusType.Canceled) {
816
- // すでに中止済の場合スルー
817
- }
818
- else if (transaction.status === factory.transactionStatusType.Expired) {
819
- throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${transaction.id} already expired`);
820
- }
821
- else if (transaction.status === factory.transactionStatusType.Confirmed) {
822
- throw new factory.errors.Argument('Transaction id', `Confirmed transaction ${params.typeOf} ${transaction.id} unable to cancel`);
823
- }
824
- else {
825
- throw new factory.errors.NotFound(this.transactionModel.modelName);
826
- }
827
- result = { id: transaction.id };
772
+ : undefined,
773
+ status: { $eq: factory.transactionStatusType.InProgress }
774
+ }, {
775
+ $set: {
776
+ status: factory.transactionStatusType.Canceled,
777
+ endDate: new Date()
778
+ }
779
+ }, {
780
+ new: true,
781
+ projection: { _id: 1 }
782
+ })
783
+ .exec();
784
+ let result;
785
+ // NotFoundであれば取引状態確認
786
+ if (doc === null) {
787
+ let transaction;
788
+ if (typeof params.id === 'string') {
789
+ transaction = await this.findById({ typeOf: params.typeOf, id: params.id }, ['status']);
790
+ }
791
+ else if (typeof params.transactionNumber === 'string') {
792
+ transaction = await this.findByTransactionNumber({
793
+ typeOf: params.typeOf,
794
+ transactionNumber: params.transactionNumber
795
+ }, ['status']);
828
796
  }
829
797
  else {
830
- result = { id: doc.toObject().id };
798
+ throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
831
799
  }
832
- assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
833
- id: result.id,
834
- typeOf: params.typeOf,
835
- status: factory.transactionStatusType.Canceled
836
- });
837
- return result;
838
- });
839
- }
840
- count(params) {
841
- return __awaiter(this, void 0, void 0, function* () {
842
- const { limit } = params;
843
- const conditions = AssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
844
- const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
845
- if (typeof limit === 'number' && limit >= 0) {
846
- query.limit(limit);
800
+ if (transaction.status === factory.transactionStatusType.Canceled) {
801
+ // すでに中止済の場合スルー
847
802
  }
848
- const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
849
- .exec();
850
- return { count };
803
+ else if (transaction.status === factory.transactionStatusType.Expired) {
804
+ throw new factory.errors.Argument('Transaction id', `Transaction ${params.typeOf} ${transaction.id} already expired`);
805
+ }
806
+ else if (transaction.status === factory.transactionStatusType.Confirmed) {
807
+ throw new factory.errors.Argument('Transaction id', `Confirmed transaction ${params.typeOf} ${transaction.id} unable to cancel`);
808
+ }
809
+ else {
810
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
811
+ }
812
+ result = { id: transaction.id };
813
+ }
814
+ else {
815
+ result = { id: doc.toObject().id };
816
+ }
817
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
818
+ id: result.id,
819
+ typeOf: params.typeOf,
820
+ status: factory.transactionStatusType.Canceled
851
821
  });
822
+ return result;
823
+ }
824
+ async count(params) {
825
+ const { limit } = params;
826
+ const conditions = AssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
827
+ const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
828
+ if (typeof limit === 'number' && limit >= 0) {
829
+ query.limit(limit);
830
+ }
831
+ const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
832
+ .exec();
833
+ return { count };
852
834
  }
853
835
  /**
854
836
  * 取引を検索する
855
837
  */
856
- search(params, inclusion, exclusion) {
857
- return __awaiter(this, void 0, void 0, function* () {
858
- var _a;
859
- const conditions = AssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
860
- let projection = {};
861
- if (Array.isArray(inclusion) && inclusion.length > 0) {
862
- inclusion.forEach((field) => {
863
- projection[field] = 1;
838
+ async search(params, inclusion, exclusion) {
839
+ const conditions = AssetTransactionRepo.CREATE_MONGO_CONDITIONS(params);
840
+ let projection = {};
841
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
842
+ inclusion.forEach((field) => {
843
+ projection[field] = 1;
844
+ });
845
+ }
846
+ else {
847
+ projection = {
848
+ __v: 0,
849
+ createdAt: 0,
850
+ updatedAt: 0
851
+ };
852
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
853
+ exclusion.forEach((field) => {
854
+ projection[field] = 0;
864
855
  });
865
856
  }
866
- else {
867
- projection = {
868
- __v: 0,
869
- createdAt: 0,
870
- updatedAt: 0
871
- };
872
- if (Array.isArray(exclusion) && exclusion.length > 0) {
873
- exclusion.forEach((field) => {
874
- projection[field] = 0;
875
- });
876
- }
877
- }
878
- const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
879
- .select(projection);
880
- if (typeof params.limit === 'number' && params.limit > 0) {
881
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
882
- query.limit(params.limit)
883
- .skip(params.limit * (page - 1));
884
- }
885
- // tslint:disable-next-line:no-single-line-block-comment
886
- /* istanbul ignore else */
887
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.startDate) !== undefined) {
888
- query.sort({ startDate: params.sort.startDate });
889
- }
890
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
891
- .exec()
892
- .then((docs) => docs.map((doc) => doc.toObject()));
893
- });
857
+ }
858
+ const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
859
+ .select(projection);
860
+ if (typeof params.limit === 'number' && params.limit > 0) {
861
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
862
+ query.limit(params.limit)
863
+ .skip(params.limit * (page - 1));
864
+ }
865
+ /* istanbul ignore else */
866
+ if (params.sort?.startDate !== undefined) {
867
+ query.sort({ startDate: params.sort.startDate });
868
+ }
869
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
870
+ .exec()
871
+ .then((docs) => docs.map((doc) => doc.toObject()));
894
872
  }
895
873
  /**
896
874
  * 取引番号指定で削除する
897
875
  */
898
- deleteByTransactionNumber(params) {
899
- return __awaiter(this, void 0, void 0, function* () {
900
- return this.transactionModel.deleteMany({
901
- 'project.id': { $eq: params.project.id },
902
- transactionNumber: { $in: params.transactionNumbers },
903
- typeOf: { $eq: params.typeOf }
904
- })
905
- .exec();
906
- });
876
+ async deleteByTransactionNumber(params) {
877
+ return this.transactionModel.deleteMany({
878
+ 'project.id': { $eq: params.project.id },
879
+ transactionNumber: { $in: params.transactionNumbers },
880
+ typeOf: { $eq: params.typeOf }
881
+ })
882
+ .exec();
907
883
  }
908
884
  /**
909
885
  * プロジェクト指定で削除する
910
886
  */
911
- deleteByProject(params) {
912
- return __awaiter(this, void 0, void 0, function* () {
913
- yield this.transactionModel.deleteMany({
914
- 'project.id': { $eq: params.project.id }
915
- })
916
- .exec();
917
- });
887
+ async deleteByProject(params) {
888
+ await this.transactionModel.deleteMany({
889
+ 'project.id': { $eq: params.project.id }
890
+ })
891
+ .exec();
918
892
  }
919
893
  /**
920
894
  * 終了日時を一定期間過ぎたアクションを削除する
921
895
  */
922
- deleteEndDatePassedCertainPeriod(params) {
923
- return __awaiter(this, void 0, void 0, function* () {
924
- yield this.transactionModel.deleteMany({
925
- // 終了日時を一定期間過ぎたもの
926
- endDate: {
927
- $exists: true,
928
- $lt: params.$lt
929
- }
930
- })
931
- .exec();
932
- });
896
+ async deleteEndDatePassedCertainPeriod(params) {
897
+ await this.transactionModel.deleteMany({
898
+ // 終了日時を一定期間過ぎたもの
899
+ endDate: {
900
+ $exists: true,
901
+ $lt: params.$lt
902
+ }
903
+ })
904
+ .exec();
933
905
  }
934
906
  /**
935
907
  * 特定の取引を更新する(汎用)
936
908
  */
937
- findByIdAndUpdateInProgress(params) {
938
- return __awaiter(this, void 0, void 0, function* () {
939
- return this.transactionModel.findOneAndUpdate({
940
- _id: { $eq: params.id },
941
- status: { $eq: factory.transactionStatusType.InProgress }
942
- }, params.update, { new: true })
943
- .exec()
944
- .then((doc) => {
945
- if (doc === null) {
946
- throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
947
- }
948
- return doc.toObject();
949
- });
909
+ async findByIdAndUpdateInProgress(params) {
910
+ return this.transactionModel.findOneAndUpdate({
911
+ _id: { $eq: params.id },
912
+ status: { $eq: factory.transactionStatusType.InProgress }
913
+ }, params.update, { new: true })
914
+ .exec()
915
+ .then((doc) => {
916
+ if (doc === null) {
917
+ throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
918
+ }
919
+ return doc.toObject();
950
920
  });
951
921
  }
952
922
  /**
953
923
  * 互換性維持対応
954
924
  */
955
- migrateObjectReservationNumber(params) {
956
- return __awaiter(this, void 0, void 0, function* () {
957
- return this.transactionModel.findOneAndUpdate({
958
- typeOf: { $eq: factory.assetTransactionType.CancelReservation },
959
- _id: { $eq: params.id }
960
- }, {
961
- $set: {
962
- 'object.reservationNumber': params.object.reservationNumber,
963
- 'object.typeOf': factory.reservationType.ReservationPackage
964
- }
965
- }, {
966
- timestamps: false,
967
- new: true,
968
- projection: { _id: 1 }
969
- })
970
- .exec()
971
- .then((doc) => {
972
- if (doc === null) {
973
- throw new factory.errors.NotFound(this.transactionModel.modelName);
974
- }
975
- return doc.toObject();
976
- });
925
+ async migrateObjectReservationNumber(params) {
926
+ return this.transactionModel.findOneAndUpdate({
927
+ typeOf: { $eq: factory.assetTransactionType.CancelReservation },
928
+ _id: { $eq: params.id }
929
+ }, {
930
+ $set: {
931
+ 'object.reservationNumber': params.object.reservationNumber,
932
+ 'object.typeOf': factory.reservationType.ReservationPackage
933
+ }
934
+ }, {
935
+ timestamps: false,
936
+ new: true,
937
+ projection: { _id: 1 }
938
+ })
939
+ .exec()
940
+ .then((doc) => {
941
+ if (doc === null) {
942
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
943
+ }
944
+ return doc.toObject();
977
945
  });
978
946
  }
979
947
  /**
980
948
  * 互換性維持対応専用
981
949
  */
982
- fixReservedTicketIdentifier(params) {
983
- return __awaiter(this, void 0, void 0, function* () {
984
- const doc = yield this.transactionModel.findOneAndUpdate({
985
- transactionNumber: { $eq: params.transactionNumber },
986
- 'project.id': { $eq: params.project.id },
987
- typeOf: { $eq: factory.assetTransactionType.Pay }
988
- }, {
989
- $set: {
990
- 'object.paymentMethod.movieTickets': params.object.paymentMethod.movieTickets
991
- }
992
- }, {
993
- timestamps: false,
994
- new: true,
995
- projection: {
996
- _id: 1
997
- }
998
- })
999
- .exec();
1000
- if (doc === null) {
1001
- throw new factory.errors.NotFound(this.transactionModel.modelName);
950
+ async fixReservedTicketIdentifier(params) {
951
+ const doc = await this.transactionModel.findOneAndUpdate({
952
+ transactionNumber: { $eq: params.transactionNumber },
953
+ 'project.id': { $eq: params.project.id },
954
+ typeOf: { $eq: factory.assetTransactionType.Pay }
955
+ }, {
956
+ $set: {
957
+ 'object.paymentMethod.movieTickets': params.object.paymentMethod.movieTickets
1002
958
  }
1003
- });
959
+ }, {
960
+ timestamps: false,
961
+ new: true,
962
+ projection: {
963
+ _id: 1
964
+ }
965
+ })
966
+ .exec();
967
+ if (doc === null) {
968
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
969
+ }
1004
970
  }
1005
- findByIdAndDelete(params) {
1006
- return __awaiter(this, void 0, void 0, function* () {
1007
- yield this.transactionModel.findByIdAndDelete(params.id)
1008
- .exec();
1009
- });
971
+ async findByIdAndDelete(params) {
972
+ await this.transactionModel.findByIdAndDelete(params.id)
973
+ .exec();
1010
974
  }
1011
975
  getCursor(conditions, projection) {
1012
976
  return this.transactionModel.find(conditions, projection)
@@ -1014,161 +978,160 @@ class AssetTransactionRepo {
1014
978
  .sort({ startDate: factory.sortType.Descending })
1015
979
  .cursor();
1016
980
  }
1017
- unsetUnnecessaryFields(params) {
1018
- return __awaiter(this, void 0, void 0, function* () {
1019
- return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
1020
- .exec();
1021
- });
981
+ async unsetUnnecessaryFields(params) {
982
+ return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
983
+ .exec();
1022
984
  }
1023
- aggregateAssetTransaction(params) {
1024
- return __awaiter(this, void 0, void 0, function* () {
1025
- const statuses = yield Promise.all([
1026
- factory.transactionStatusType.Confirmed,
1027
- factory.transactionStatusType.Canceled,
1028
- factory.transactionStatusType.Expired
1029
- ].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
1030
- var _a, _b, _c, _d;
1031
- const matchConditions = Object.assign(Object.assign({ startDate: {
1032
- $gte: params.startFrom,
1033
- $lte: params.startThrough
1034
- }, typeOf: { $eq: params.typeOf }, status: { $eq: transactionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
985
+ async aggregateAssetTransaction(params) {
986
+ const statuses = await Promise.all([
987
+ factory.transactionStatusType.Confirmed,
988
+ factory.transactionStatusType.Canceled,
989
+ factory.transactionStatusType.Expired
990
+ ].map(async (transactionStatus) => {
991
+ const matchConditions = {
992
+ startDate: {
993
+ $gte: params.startFrom,
994
+ $lte: params.startThrough
995
+ },
996
+ typeOf: { $eq: params.typeOf },
997
+ status: { $eq: transactionStatus },
998
+ ...(typeof params.project?.id?.$ne === 'string')
1035
999
  ? { 'project.id': { $ne: params.project.id.$ne } }
1036
- : undefined), (typeof ((_d = (_c = params.project) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq) === 'string')
1000
+ : undefined,
1001
+ ...(typeof params.project?.id?.$eq === 'string')
1037
1002
  ? { 'project.id': { $eq: params.project.id.$eq } }
1038
- : undefined);
1039
- return this.agggregateByStatus({ matchConditions, status: transactionStatus });
1040
- })));
1041
- return { statuses };
1042
- });
1003
+ : undefined
1004
+ };
1005
+ return this.agggregateByStatus({ matchConditions, status: transactionStatus });
1006
+ }));
1007
+ return { statuses };
1043
1008
  }
1044
- // tslint:disable-next-line:max-func-body-length
1045
- agggregateByStatus(params) {
1046
- return __awaiter(this, void 0, void 0, function* () {
1047
- const matchConditions = params.matchConditions;
1048
- const transactionStatus = params.status;
1049
- const aggregations = yield this.transactionModel.aggregate([
1050
- {
1051
- $match: matchConditions
1052
- },
1053
- {
1054
- $project: {
1055
- duration: { $subtract: ['$endDate', '$startDate'] },
1056
- graceTime: {
1057
- $cond: {
1058
- if: { $eq: ['$typeOf', factory.assetTransactionType.Reserve] },
1059
- then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
1060
- else: 0
1061
- }
1062
- },
1063
- status: '$status',
1064
- startDate: '$startDate',
1065
- endDate: '$endDate',
1066
- typeOf: '$typeOf',
1067
- reservationCount: {
1068
- $cond: {
1069
- if: { $isArray: '$object.subReservation' },
1070
- then: { $size: '$object.subReservation' },
1071
- else: 0
1072
- }
1009
+ async agggregateByStatus(params) {
1010
+ const matchConditions = params.matchConditions;
1011
+ const transactionStatus = params.status;
1012
+ const aggregations = await this.transactionModel.aggregate([
1013
+ {
1014
+ $match: matchConditions
1015
+ },
1016
+ {
1017
+ $project: {
1018
+ duration: { $subtract: ['$endDate', '$startDate'] },
1019
+ graceTime: {
1020
+ $cond: {
1021
+ if: { $eq: ['$typeOf', factory.assetTransactionType.Reserve] },
1022
+ then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
1023
+ else: 0
1024
+ }
1025
+ },
1026
+ status: '$status',
1027
+ startDate: '$startDate',
1028
+ endDate: '$endDate',
1029
+ typeOf: '$typeOf',
1030
+ reservationCount: {
1031
+ $cond: {
1032
+ if: { $isArray: '$object.subReservation' },
1033
+ then: { $size: '$object.subReservation' },
1034
+ else: 0
1073
1035
  }
1074
- }
1075
- },
1076
- {
1077
- $group: {
1078
- _id: '$typeOf',
1079
- transactionCount: { $sum: 1 },
1080
- maxDuration: { $max: '$duration' },
1081
- minDuration: { $min: '$duration' },
1082
- avgDuration: { $avg: '$duration' },
1083
- reservationCount: { $sum: '$reservationCount' },
1084
- maxGraceTime: { $max: '$graceTime' },
1085
- minGraceTime: { $min: '$graceTime' },
1086
- avgGraceTime: { $avg: '$graceTime' }
1087
- }
1088
- },
1089
- {
1090
- $project: {
1091
- _id: 0,
1092
- transactionCount: '$transactionCount',
1093
- avgDuration: '$avgDuration',
1094
- maxDuration: '$maxDuration',
1095
- minDuration: '$minDuration',
1096
- reservationCount: '$reservationCount',
1097
- avgGraceTime: '$avgGraceTime',
1098
- maxGraceTime: '$maxGraceTime',
1099
- minGraceTime: '$minGraceTime'
1100
1036
  }
1101
1037
  }
1102
- ])
1103
- .exec();
1104
- // tslint:disable-next-line:no-magic-numbers
1105
- const percents = [50, 95, 99];
1106
- if (aggregations.length === 0) {
1107
- return {
1108
- status: transactionStatus,
1109
- aggregation: {
1110
- transactionCount: 0,
1111
- avgDuration: 0,
1112
- maxDuration: 0,
1113
- minDuration: 0,
1114
- percentilesDuration: percents.map((percent) => {
1115
- return {
1116
- name: String(percent),
1117
- value: 0
1118
- };
1119
- }),
1120
- reservationCount: 0,
1121
- avgGraceTime: 0,
1122
- maxGraceTime: 0,
1123
- minGraceTime: 0
1124
- }
1125
- };
1126
- }
1127
- const ranks4percentile = percents.map((percentile) => {
1128
- return {
1129
- percentile,
1130
- // tslint:disable-next-line:no-magic-numbers
1131
- rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
1132
- };
1133
- });
1134
- const aggregations2 = yield this.transactionModel.aggregate([
1135
- {
1136
- $match: matchConditions
1137
- },
1138
- {
1139
- $project: {
1140
- duration: { $subtract: ['$endDate', '$startDate'] },
1141
- status: '$status',
1142
- startDate: '$startDate',
1143
- endDate: '$endDate',
1144
- typeOf: '$typeOf'
1145
- }
1146
- },
1147
- { $sort: { duration: 1 } },
1148
- {
1149
- $group: {
1150
- _id: '$typeOf',
1151
- durations: { $push: '$duration' }
1152
- }
1153
- },
1154
- {
1155
- $project: {
1156
- _id: 0,
1157
- percentilesDuration: ranks4percentile.map((rank) => {
1158
- return {
1159
- name: String(rank.percentile),
1160
- value: { $arrayElemAt: ['$durations', rank.rank] }
1161
- };
1162
- })
1163
- }
1038
+ },
1039
+ {
1040
+ $group: {
1041
+ _id: '$typeOf',
1042
+ transactionCount: { $sum: 1 },
1043
+ maxDuration: { $max: '$duration' },
1044
+ minDuration: { $min: '$duration' },
1045
+ avgDuration: { $avg: '$duration' },
1046
+ reservationCount: { $sum: '$reservationCount' },
1047
+ maxGraceTime: { $max: '$graceTime' },
1048
+ minGraceTime: { $min: '$graceTime' },
1049
+ avgGraceTime: { $avg: '$graceTime' }
1164
1050
  }
1165
- ])
1166
- .exec();
1051
+ },
1052
+ {
1053
+ $project: {
1054
+ _id: 0,
1055
+ transactionCount: '$transactionCount',
1056
+ avgDuration: '$avgDuration',
1057
+ maxDuration: '$maxDuration',
1058
+ minDuration: '$minDuration',
1059
+ reservationCount: '$reservationCount',
1060
+ avgGraceTime: '$avgGraceTime',
1061
+ maxGraceTime: '$maxGraceTime',
1062
+ minGraceTime: '$minGraceTime'
1063
+ }
1064
+ }
1065
+ ])
1066
+ .exec();
1067
+ const percents = [50, 95, 99];
1068
+ if (aggregations.length === 0) {
1167
1069
  return {
1168
1070
  status: transactionStatus,
1169
- aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
1071
+ aggregation: {
1072
+ transactionCount: 0,
1073
+ avgDuration: 0,
1074
+ maxDuration: 0,
1075
+ minDuration: 0,
1076
+ percentilesDuration: percents.map((percent) => {
1077
+ return {
1078
+ name: String(percent),
1079
+ value: 0
1080
+ };
1081
+ }),
1082
+ reservationCount: 0,
1083
+ avgGraceTime: 0,
1084
+ maxGraceTime: 0,
1085
+ minGraceTime: 0
1086
+ }
1087
+ };
1088
+ }
1089
+ const ranks4percentile = percents.map((percentile) => {
1090
+ return {
1091
+ percentile,
1092
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
1170
1093
  };
1171
1094
  });
1095
+ const aggregations2 = await this.transactionModel.aggregate([
1096
+ {
1097
+ $match: matchConditions
1098
+ },
1099
+ {
1100
+ $project: {
1101
+ duration: { $subtract: ['$endDate', '$startDate'] },
1102
+ status: '$status',
1103
+ startDate: '$startDate',
1104
+ endDate: '$endDate',
1105
+ typeOf: '$typeOf'
1106
+ }
1107
+ },
1108
+ { $sort: { duration: 1 } },
1109
+ {
1110
+ $group: {
1111
+ _id: '$typeOf',
1112
+ durations: { $push: '$duration' }
1113
+ }
1114
+ },
1115
+ {
1116
+ $project: {
1117
+ _id: 0,
1118
+ percentilesDuration: ranks4percentile.map((rank) => {
1119
+ return {
1120
+ name: String(rank.percentile),
1121
+ value: { $arrayElemAt: ['$durations', rank.rank] }
1122
+ };
1123
+ })
1124
+ }
1125
+ }
1126
+ ])
1127
+ .exec();
1128
+ return {
1129
+ status: transactionStatus,
1130
+ aggregation: {
1131
+ ...aggregations[0],
1132
+ ...aggregations2[0]
1133
+ }
1134
+ };
1172
1135
  }
1173
1136
  }
1174
1137
  exports.AssetTransactionRepo = AssetTransactionRepo;