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

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