@chevre/domain 23.2.0-alpha.60 → 23.2.0-alpha.62

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