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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (513) hide show
  1. package/lib/chevre/credentials/customSearch.js +2 -0
  2. package/lib/chevre/credentials/lineNotify.js +4 -0
  3. package/lib/chevre/credentials/sendGrid.js +2 -0
  4. package/lib/chevre/credentials.js +15 -30
  5. package/lib/chevre/emailMessageBuilder.js +225 -250
  6. package/lib/chevre/errorHandler.js +38 -54
  7. package/lib/chevre/factory/event.js +69 -42
  8. package/lib/chevre/factory/transactionNumber.js +3 -1
  9. package/lib/chevre/index.js +15 -30
  10. package/lib/chevre/repo/acceptedOffer.js +178 -197
  11. package/lib/chevre/repo/acceptedPaymentMethod.js +131 -143
  12. package/lib/chevre/repo/account.js +196 -223
  13. package/lib/chevre/repo/accountTitle.js +9 -21
  14. package/lib/chevre/repo/accountTransaction.js +189 -189
  15. package/lib/chevre/repo/accountingReport.js +88 -107
  16. package/lib/chevre/repo/action.js +853 -880
  17. package/lib/chevre/repo/additionalProperty.js +65 -91
  18. package/lib/chevre/repo/advanceBookingRequirement.js +69 -90
  19. package/lib/chevre/repo/aggregateOffer.js +394 -427
  20. package/lib/chevre/repo/aggregateOrder.js +50 -62
  21. package/lib/chevre/repo/aggregateReservation.js +76 -89
  22. package/lib/chevre/repo/aggregation.js +42 -63
  23. package/lib/chevre/repo/assetTransaction.js +696 -716
  24. package/lib/chevre/repo/authorization.js +115 -127
  25. package/lib/chevre/repo/categoryCode.js +115 -143
  26. package/lib/chevre/repo/comment.js +74 -82
  27. package/lib/chevre/repo/concurrentLock.js +17 -29
  28. package/lib/chevre/repo/confirmationNumber.js +21 -33
  29. package/lib/chevre/repo/creativeWork.js +154 -176
  30. package/lib/chevre/repo/credentials.js +40 -51
  31. package/lib/chevre/repo/customer.js +65 -88
  32. package/lib/chevre/repo/customerType.js +52 -61
  33. package/lib/chevre/repo/emailMessage.js +52 -80
  34. package/lib/chevre/repo/event.d.ts +0 -15
  35. package/lib/chevre/repo/event.js +720 -744
  36. package/lib/chevre/repo/eventOffer.js +122 -125
  37. package/lib/chevre/repo/eventSellerMakesOffer.js +64 -76
  38. package/lib/chevre/repo/eventSeries.d.ts +1 -7
  39. package/lib/chevre/repo/eventSeries.js +258 -277
  40. package/lib/chevre/repo/identity.js +94 -106
  41. package/lib/chevre/repo/identityProvider.js +72 -95
  42. package/lib/chevre/repo/issuer.js +102 -135
  43. package/lib/chevre/repo/member.js +238 -258
  44. package/lib/chevre/repo/memberProgram.js +157 -177
  45. package/lib/chevre/repo/merchantReturnPolicy.js +62 -93
  46. package/lib/chevre/repo/message.js +122 -135
  47. package/lib/chevre/repo/mongoose/schemas/acceptedPaymentMethod.js +1 -1
  48. package/lib/chevre/repo/mongoose/schemas/account.js +1 -1
  49. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -1
  50. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
  51. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -1
  52. package/lib/chevre/repo/mongoose/schemas/action.js +1 -1
  53. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +1 -1
  54. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -1
  55. package/lib/chevre/repo/mongoose/schemas/advanceBookingRequirement.js +1 -1
  56. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +1 -1
  57. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +1 -1
  58. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +1 -1
  59. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -1
  60. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -1
  61. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
  62. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -1
  63. package/lib/chevre/repo/mongoose/schemas/civicStructure.js +1 -1
  64. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -1
  65. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -1
  66. package/lib/chevre/repo/mongoose/schemas/customerType.js +1 -1
  67. package/lib/chevre/repo/mongoose/schemas/event.js +1 -1
  68. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +1 -1
  69. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +41 -14
  70. package/lib/chevre/repo/mongoose/schemas/identity.js +1 -1
  71. package/lib/chevre/repo/mongoose/schemas/identityProvider.js +1 -1
  72. package/lib/chevre/repo/mongoose/schemas/issuer.js +1 -1
  73. package/lib/chevre/repo/mongoose/schemas/member/global.js +1 -1
  74. package/lib/chevre/repo/mongoose/schemas/member.js +1 -1
  75. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -1
  76. package/lib/chevre/repo/mongoose/schemas/message.js +1 -1
  77. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +1 -1
  78. package/lib/chevre/repo/mongoose/schemas/note.js +1 -1
  79. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -1
  80. package/lib/chevre/repo/mongoose/schemas/offerCatalogItem.js +1 -1
  81. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +1 -1
  82. package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
  83. package/lib/chevre/repo/mongoose/schemas/paymentService.js +1 -1
  84. package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +1 -1
  85. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +1 -1
  86. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.js +1 -1
  87. package/lib/chevre/repo/mongoose/schemas/place.js +1 -1
  88. package/lib/chevre/repo/mongoose/schemas/potentialAction.js +1 -1
  89. package/lib/chevre/repo/mongoose/schemas/product.js +1 -1
  90. package/lib/chevre/repo/mongoose/schemas/productModel.js +1 -1
  91. package/lib/chevre/repo/mongoose/schemas/productOffer.js +1 -1
  92. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
  93. package/lib/chevre/repo/mongoose/schemas/reserveInterface.js +1 -1
  94. package/lib/chevre/repo/mongoose/schemas/role.js +1 -1
  95. package/lib/chevre/repo/mongoose/schemas/schedule.js +1 -1
  96. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -1
  97. package/lib/chevre/repo/mongoose/schemas/sellerReturnPolicy.js +1 -1
  98. package/lib/chevre/repo/mongoose/schemas/service/availableHour.js +1 -1
  99. package/lib/chevre/repo/mongoose/schemas/setting.js +1 -1
  100. package/lib/chevre/repo/mongoose/schemas/task.js +1 -1
  101. package/lib/chevre/repo/mongoose/schemas/ticket.js +1 -1
  102. package/lib/chevre/repo/mongoose/schemas/transaction.js +1 -1
  103. package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +1 -1
  104. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -1
  105. package/lib/chevre/repo/mongoose/schemas/webSite.js +1 -1
  106. package/lib/chevre/repo/movieTicketType.js +68 -89
  107. package/lib/chevre/repo/note.js +143 -146
  108. package/lib/chevre/repo/noteAboutOrder.js +112 -113
  109. package/lib/chevre/repo/offer/unitPriceInCatalog.js +331 -313
  110. package/lib/chevre/repo/offerCatalog.js +302 -333
  111. package/lib/chevre/repo/offerCatalogItem.js +289 -316
  112. package/lib/chevre/repo/offerItemCondition.js +60 -85
  113. package/lib/chevre/repo/order.js +563 -572
  114. package/lib/chevre/repo/orderInTransaction.js +113 -136
  115. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  116. package/lib/chevre/repo/orderNumber.js +108 -122
  117. package/lib/chevre/repo/ownershipInfo.js +213 -233
  118. package/lib/chevre/repo/passport.js +94 -102
  119. package/lib/chevre/repo/paymentMethod/creditCard.js +153 -169
  120. package/lib/chevre/repo/paymentService.js +180 -199
  121. package/lib/chevre/repo/paymentServiceChannel.js +76 -99
  122. package/lib/chevre/repo/paymentServiceProvider.js +186 -201
  123. package/lib/chevre/repo/pendingReservation.js +275 -305
  124. package/lib/chevre/repo/permit.js +47 -42
  125. package/lib/chevre/repo/person.js +227 -247
  126. package/lib/chevre/repo/place/busStop.js +77 -103
  127. package/lib/chevre/repo/place/entranceGate.js +123 -128
  128. package/lib/chevre/repo/place/hasPOS.js +108 -120
  129. package/lib/chevre/repo/place/movieTheater.js +187 -219
  130. package/lib/chevre/repo/place/screeningRoom.js +340 -324
  131. package/lib/chevre/repo/place/seat.js +539 -475
  132. package/lib/chevre/repo/place/section.js +329 -292
  133. package/lib/chevre/repo/potentialAction.js +67 -86
  134. package/lib/chevre/repo/priceSpecification.js +103 -141
  135. package/lib/chevre/repo/product.js +204 -238
  136. package/lib/chevre/repo/productHasOfferCatalog.js +39 -50
  137. package/lib/chevre/repo/productModel.js +94 -126
  138. package/lib/chevre/repo/productOffer.js +119 -118
  139. package/lib/chevre/repo/project.js +123 -141
  140. package/lib/chevre/repo/projectMakesOffer.js +96 -108
  141. package/lib/chevre/repo/rateLimit/offer.js +43 -56
  142. package/lib/chevre/repo/reservation.js +370 -345
  143. package/lib/chevre/repo/reserveInterface.js +31 -42
  144. package/lib/chevre/repo/role.js +94 -112
  145. package/lib/chevre/repo/schedule.js +25 -36
  146. package/lib/chevre/repo/seller.js +115 -145
  147. package/lib/chevre/repo/sellerMakesOffer.js +95 -110
  148. package/lib/chevre/repo/sellerPaymentAccepted.js +92 -109
  149. package/lib/chevre/repo/sellerReturnPolicy.js +74 -96
  150. package/lib/chevre/repo/service/availableHour.js +27 -38
  151. package/lib/chevre/repo/serviceOutput.js +55 -66
  152. package/lib/chevre/repo/serviceOutputIdentifier.js +46 -57
  153. package/lib/chevre/repo/setting/jwt.js +40 -50
  154. package/lib/chevre/repo/setting.js +48 -48
  155. package/lib/chevre/repo/stockHolder.js +179 -197
  156. package/lib/chevre/repo/task.d.ts +1 -1
  157. package/lib/chevre/repo/task.js +615 -617
  158. package/lib/chevre/repo/telemetry.js +1 -0
  159. package/lib/chevre/repo/ticket.js +52 -65
  160. package/lib/chevre/repo/transaction.js +758 -795
  161. package/lib/chevre/repo/transactionNumber.js +67 -80
  162. package/lib/chevre/repo/transactionNumberCounter.js +69 -79
  163. package/lib/chevre/repo/transactionProcess.js +36 -47
  164. package/lib/chevre/repo/trip.js +145 -163
  165. package/lib/chevre/repo/webSite.js +90 -105
  166. package/lib/chevre/repository.js +455 -646
  167. package/lib/chevre/service/account.js +9 -18
  168. package/lib/chevre/service/accountTransaction/deposit.js +16 -17
  169. package/lib/chevre/service/accountTransaction/transfer.js +18 -19
  170. package/lib/chevre/service/accountTransaction/withdraw.js +16 -17
  171. package/lib/chevre/service/accountTransaction.js +4 -13
  172. package/lib/chevre/service/aggregation/event/aggregateOffers.js +63 -60
  173. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +52 -55
  174. package/lib/chevre/service/aggregation/event/findEventOffers.js +7 -17
  175. package/lib/chevre/service/aggregation/event/importFromCOA.js +4 -13
  176. package/lib/chevre/service/aggregation/project.js +10 -19
  177. package/lib/chevre/service/aggregation/system.js +182 -99
  178. package/lib/chevre/service/assetTransaction/cancelReservation/factory.js +31 -17
  179. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +17 -23
  180. package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.js +17 -15
  181. package/lib/chevre/service/assetTransaction/cancelReservation.js +7 -16
  182. package/lib/chevre/service/assetTransaction/cancelReservationCOA/factory.js +11 -4
  183. package/lib/chevre/service/assetTransaction/cancelReservationCOA.js +4 -13
  184. package/lib/chevre/service/assetTransaction/fixInformAction.d.ts +3 -0
  185. package/lib/chevre/service/assetTransaction/fixInformAction.js +9 -16
  186. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +13 -25
  187. package/lib/chevre/service/assetTransaction/moneyTransfer.js +101 -88
  188. package/lib/chevre/service/assetTransaction/pay/cancel.d.ts +12 -0
  189. package/lib/chevre/service/assetTransaction/pay/cancel.js +16 -0
  190. package/lib/chevre/service/assetTransaction/pay/check.d.ts +23 -0
  191. package/lib/chevre/service/assetTransaction/pay/check.js +27 -0
  192. package/lib/chevre/service/assetTransaction/pay/confirm.d.ts +24 -0
  193. package/lib/chevre/service/assetTransaction/pay/confirm.js +69 -0
  194. package/lib/chevre/service/assetTransaction/pay/exportTasksById.d.ts +18 -0
  195. package/lib/chevre/service/assetTransaction/pay/exportTasksById.js +102 -0
  196. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.d.ts +48 -0
  197. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +165 -0
  198. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.d.ts +20 -0
  199. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.js +49 -0
  200. package/lib/chevre/service/assetTransaction/pay/{account → start/account}/validation.d.ts +2 -2
  201. package/lib/chevre/service/assetTransaction/pay/{account → start/account}/validation.js +7 -17
  202. package/lib/chevre/service/assetTransaction/pay/{factory.d.ts → start/factory.d.ts} +1 -1
  203. package/lib/chevre/service/assetTransaction/pay/{factory.js → start/factory.js} +65 -37
  204. package/lib/chevre/service/assetTransaction/pay/{validateAcceptedPaymentMethodIfNeeded.d.ts → start/preStart/validateAcceptedPaymentMethodIfNeeded.d.ts} +4 -4
  205. package/lib/chevre/service/assetTransaction/pay/{validateAcceptedPaymentMethodIfNeeded.js → start/preStart/validateAcceptedPaymentMethodIfNeeded.js} +8 -21
  206. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateSeller.d.ts +8 -0
  207. package/lib/chevre/service/assetTransaction/pay/start/preStart/validateSeller.js +44 -0
  208. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +13 -0
  209. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +39 -0
  210. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.d.ts +29 -0
  211. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.js +31 -0
  212. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +42 -0
  213. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +22 -0
  214. package/lib/chevre/service/assetTransaction/pay/start.d.ts +60 -0
  215. package/lib/chevre/service/assetTransaction/pay/start.js +139 -0
  216. package/lib/chevre/service/assetTransaction/pay.d.ts +8 -170
  217. package/lib/chevre/service/assetTransaction/pay.js +16 -623
  218. package/lib/chevre/service/assetTransaction/refund/factory.js +36 -16
  219. package/lib/chevre/service/assetTransaction/refund/potentialActions.js +12 -21
  220. package/lib/chevre/service/assetTransaction/refund.js +35 -39
  221. package/lib/chevre/service/assetTransaction/registerService/factory.js +65 -28
  222. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +50 -41
  223. package/lib/chevre/service/assetTransaction/registerService.js +45 -52
  224. package/lib/chevre/service/assetTransaction/reserve/cancel.js +5 -14
  225. package/lib/chevre/service/assetTransaction/reserve/confirm/factory.js +15 -3
  226. package/lib/chevre/service/assetTransaction/reserve/confirm.js +21 -26
  227. package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +3 -12
  228. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +99 -79
  229. package/lib/chevre/service/assetTransaction/reserve/start/factory/createPointAward.js +17 -12
  230. package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.js +108 -70
  231. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +69 -30
  232. package/lib/chevre/service/assetTransaction/reserve/start/factory/price.js +29 -20
  233. package/lib/chevre/service/assetTransaction/reserve/start.js +91 -106
  234. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/fixExtendedEventOffer.js +5 -15
  235. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +41 -54
  236. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +42 -55
  237. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/verifyTicketTokenAsNeeded.js +7 -17
  238. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +15 -27
  239. package/lib/chevre/service/assetTransaction/reserveCOA/cancel.js +24 -24
  240. package/lib/chevre/service/assetTransaction/reserveCOA/factory.js +12 -4
  241. package/lib/chevre/service/assetTransaction/reserveCOA.js +4 -13
  242. package/lib/chevre/service/assetTransaction.js +17 -21
  243. package/lib/chevre/service/delivery/factory.js +3 -4
  244. package/lib/chevre/service/delivery/product/factory.js +16 -7
  245. package/lib/chevre/service/delivery/reservation/factory.js +14 -3
  246. package/lib/chevre/service/delivery.js +47 -49
  247. package/lib/chevre/service/event/processUpdateMovieTheater.js +21 -23
  248. package/lib/chevre/service/event/saveScreeningEventSeries.js +56 -37
  249. package/lib/chevre/service/event/saveScreeningEvents.js +14 -23
  250. package/lib/chevre/service/event.js +34 -27
  251. package/lib/chevre/service/iam.js +8 -17
  252. package/lib/chevre/service/moneyTransfer.js +128 -112
  253. package/lib/chevre/service/notification/factory.js +11 -8
  254. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +11 -15
  255. package/lib/chevre/service/notification/notifyByEmail.js +7 -17
  256. package/lib/chevre/service/notification/sendEmailMessage.js +23 -26
  257. package/lib/chevre/service/notification/triggerWebhook.js +58 -54
  258. package/lib/chevre/service/offer/any.js +6 -15
  259. package/lib/chevre/service/offer/event/authorize/factory.js +139 -61
  260. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +8 -18
  261. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +43 -27
  262. package/lib/chevre/service/offer/event/authorize.js +114 -68
  263. package/lib/chevre/service/offer/event/checkAvailability.js +5 -15
  264. package/lib/chevre/service/offer/event/importFromCOA/factory.js +9 -2
  265. package/lib/chevre/service/offer/event/importFromCOA.js +13 -19
  266. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +38 -39
  267. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +26 -38
  268. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.js +11 -22
  269. package/lib/chevre/service/offer/event/searchOfferCatalogItemAvailability.js +13 -24
  270. package/lib/chevre/service/offer/event/searchOfferCatalogItems.js +15 -22
  271. package/lib/chevre/service/offer/event/searchOffersByIds.js +24 -36
  272. package/lib/chevre/service/offer/event/searchPriceSpecs4event.js +5 -14
  273. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +4 -13
  274. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +6 -15
  275. package/lib/chevre/service/offer/event/voidTransaction.js +35 -39
  276. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +14 -20
  277. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +52 -40
  278. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/factory.js +5 -1
  279. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +34 -37
  280. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +45 -22
  281. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +67 -59
  282. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +16 -26
  283. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +8 -18
  284. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +42 -41
  285. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +22 -25
  286. package/lib/chevre/service/offer/factory.js +18 -7
  287. package/lib/chevre/service/offer/moneyTransfer/authorize.js +31 -36
  288. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +9 -18
  289. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +10 -19
  290. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +14 -24
  291. package/lib/chevre/service/offer/onEventChanged.js +69 -64
  292. package/lib/chevre/service/offer/product/factory.js +54 -29
  293. package/lib/chevre/service/offer/product/searchProductOffers.js +30 -23
  294. package/lib/chevre/service/offer/product.js +106 -80
  295. package/lib/chevre/service/offer.js +48 -44
  296. package/lib/chevre/service/order/confirmPayTransaction.js +28 -27
  297. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +54 -41
  298. package/lib/chevre/service/order/deleteOrder.js +28 -35
  299. package/lib/chevre/service/order/findPlaceOrderTransaction.js +3 -12
  300. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +64 -68
  301. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  302. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +1 -2
  303. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +3 -12
  304. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +11 -6
  305. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +5 -14
  306. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +1 -1
  307. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +22 -9
  308. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +5 -14
  309. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +23 -26
  310. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +13 -19
  311. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +5 -14
  312. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +24 -13
  313. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +23 -32
  314. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +8 -18
  315. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
  316. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +10 -9
  317. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +23 -28
  318. package/lib/chevre/service/order/onOrderUpdated/factory.js +3 -5
  319. package/lib/chevre/service/order/onOrderUpdated.js +13 -15
  320. package/lib/chevre/service/order/payOrder.js +3 -12
  321. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +9 -19
  322. package/lib/chevre/service/order/placeOrder/factory/orderedItem.js +31 -15
  323. package/lib/chevre/service/order/placeOrder/factory.js +35 -22
  324. package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +3 -12
  325. package/lib/chevre/service/order/placeOrder.js +12 -22
  326. package/lib/chevre/service/order/placeOrderWithoutTransaction.js +10 -18
  327. package/lib/chevre/service/order/returnOrder.js +27 -29
  328. package/lib/chevre/service/order/sendOrder.js +37 -36
  329. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +19 -25
  330. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +24 -37
  331. package/lib/chevre/service/payment/any/factory.js +106 -49
  332. package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +4 -13
  333. package/lib/chevre/service/payment/any/onPayActionCompleted.js +13 -18
  334. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.js +34 -37
  335. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.js +18 -24
  336. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +16 -16
  337. package/lib/chevre/service/payment/any/onRefundActionCompletedOrFailed.js +15 -20
  338. package/lib/chevre/service/payment/any/person2username.js +33 -45
  339. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +8 -18
  340. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +5 -15
  341. package/lib/chevre/service/payment/any.js +181 -137
  342. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +2 -2
  343. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.js +44 -24
  344. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3ds.js +6 -15
  345. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard3dsResult2recipe.js +5 -1
  346. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCardResult2recipe.js +10 -2
  347. package/lib/chevre/service/payment/creditCard/authorize.js +20 -22
  348. package/lib/chevre/service/payment/creditCard/factory.js +22 -4
  349. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +8 -18
  350. package/lib/chevre/service/payment/creditCard/payCreditCard.js +31 -36
  351. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +40 -49
  352. package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +33 -45
  353. package/lib/chevre/service/payment/creditCard/voidTransaction.js +15 -25
  354. package/lib/chevre/service/payment/faceToFace.js +14 -23
  355. package/lib/chevre/service/payment/factory/createPayObjectServiceOutput.js +44 -25
  356. package/lib/chevre/service/payment/factory.js +50 -23
  357. package/lib/chevre/service/payment/movieTicket/authorize.js +35 -28
  358. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +22 -25
  359. package/lib/chevre/service/payment/movieTicket/factory.js +33 -10
  360. package/lib/chevre/service/payment/movieTicket/getCredentials.js +5 -15
  361. package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +29 -40
  362. package/lib/chevre/service/payment/movieTicket/processPurchaseNumberAuth.js +8 -18
  363. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +60 -59
  364. package/lib/chevre/service/payment/movieTicket/validation.js +41 -36
  365. package/lib/chevre/service/payment/movieTicket/voidTransaction.js +8 -18
  366. package/lib/chevre/service/payment/paymentCard.js +87 -103
  367. package/lib/chevre/service/permit.js +36 -35
  368. package/lib/chevre/service/product.js +23 -27
  369. package/lib/chevre/service/project.js +22 -31
  370. package/lib/chevre/service/report/ownershipInfo.js +3 -4
  371. package/lib/chevre/service/report/telemetry.js +51 -55
  372. package/lib/chevre/service/reserve/cancelReservation.js +92 -90
  373. package/lib/chevre/service/reserve/checkInReservation.js +24 -29
  374. package/lib/chevre/service/reserve/confirmReservation.js +33 -38
  375. package/lib/chevre/service/reserve/factory.js +42 -20
  376. package/lib/chevre/service/reserve/findByCode.js +13 -18
  377. package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +18 -24
  378. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +17 -24
  379. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +38 -29
  380. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +45 -35
  381. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +37 -32
  382. package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +17 -23
  383. package/lib/chevre/service/reserve/searchByOrder.js +10 -19
  384. package/lib/chevre/service/reserve/useReservation.js +47 -32
  385. package/lib/chevre/service/reserve/verifyToken4reservation.js +7 -14
  386. package/lib/chevre/service/reserveCOA/cancelReservation.js +7 -16
  387. package/lib/chevre/service/reserveCOA/factory.js +5 -1
  388. package/lib/chevre/service/task/acceptCOAOffer.js +20 -24
  389. package/lib/chevre/service/task/aggregateOffers.js +3 -12
  390. package/lib/chevre/service/task/aggregateOnSystem.js +4 -14
  391. package/lib/chevre/service/task/aggregateScreeningEvent.js +3 -12
  392. package/lib/chevre/service/task/authorizePayment.js +9 -15
  393. package/lib/chevre/service/task/cancelMoneyTransfer.js +3 -12
  394. package/lib/chevre/service/task/cancelPendingReservation.js +10 -20
  395. package/lib/chevre/service/task/cancelReservation.js +3 -12
  396. package/lib/chevre/service/task/checkMovieTicket.js +16 -19
  397. package/lib/chevre/service/task/checkResource.js +7 -16
  398. package/lib/chevre/service/task/confirmMoneyTransfer.js +3 -12
  399. package/lib/chevre/service/task/confirmPayTransaction.js +6 -12
  400. package/lib/chevre/service/task/confirmRegisterService.js +3 -12
  401. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +24 -31
  402. package/lib/chevre/service/task/confirmReserveTransaction.js +48 -42
  403. package/lib/chevre/service/task/createAccountingReport.js +14 -20
  404. package/lib/chevre/service/task/deletePerson.js +48 -58
  405. package/lib/chevre/service/task/deleteTransaction.js +3 -12
  406. package/lib/chevre/service/task/givePointAward.js +3 -12
  407. package/lib/chevre/service/task/handleNotification.js +4 -14
  408. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +6 -16
  409. package/lib/chevre/service/task/importEventsFromCOA.js +6 -16
  410. package/lib/chevre/service/task/importOffersFromCOA.js +8 -18
  411. package/lib/chevre/service/task/invalidatePaymentUrl.js +6 -12
  412. package/lib/chevre/service/task/moneyTransfer.js +3 -12
  413. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +3 -12
  414. package/lib/chevre/service/task/onAuthorizationCreated.js +11 -18
  415. package/lib/chevre/service/task/onEventChanged.js +3 -12
  416. package/lib/chevre/service/task/onOrderPaymentCompleted.js +3 -12
  417. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +7 -16
  418. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +7 -16
  419. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +8 -17
  420. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +10 -19
  421. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +8 -17
  422. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +6 -15
  423. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +14 -23
  424. package/lib/chevre/service/task/onResourceDeleted.js +17 -26
  425. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +9 -21
  426. package/lib/chevre/service/task/onResourceUpdated/onCategoryCodeUpdated.js +3 -12
  427. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +11 -23
  428. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +13 -25
  429. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +9 -15
  430. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +21 -27
  431. package/lib/chevre/service/task/onResourceUpdated.js +113 -153
  432. package/lib/chevre/service/task/pay.js +8 -16
  433. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +4 -14
  434. package/lib/chevre/service/task/payment/payByTask.js +49 -38
  435. package/lib/chevre/service/task/payment/refundByTask.js +7 -17
  436. package/lib/chevre/service/task/payment/voidPaymentByTask.js +6 -15
  437. package/lib/chevre/service/task/placeOrder.js +6 -12
  438. package/lib/chevre/service/task/publishPaymentUrl.js +9 -14
  439. package/lib/chevre/service/task/refund.js +8 -16
  440. package/lib/chevre/service/task/registerService.js +3 -12
  441. package/lib/chevre/service/task/reserve.js +3 -12
  442. package/lib/chevre/service/task/returnMoneyTransfer.js +3 -12
  443. package/lib/chevre/service/task/returnOrder.js +6 -12
  444. package/lib/chevre/service/task/returnPayTransaction.js +54 -48
  445. package/lib/chevre/service/task/returnPointAward.js +3 -12
  446. package/lib/chevre/service/task/returnReserveTransaction.js +29 -30
  447. package/lib/chevre/service/task/sendEmailMessage.js +6 -13
  448. package/lib/chevre/service/task/sendOrder.js +12 -15
  449. package/lib/chevre/service/task/syncResourcesFromCOA.js +39 -40
  450. package/lib/chevre/service/task/triggerWebhook.js +6 -12
  451. package/lib/chevre/service/task/useReservation.js +11 -14
  452. package/lib/chevre/service/task/voidMoneyTransferTransaction.js +3 -12
  453. package/lib/chevre/service/task/voidPayTransaction.js +7 -12
  454. package/lib/chevre/service/task/voidPayment.js +3 -12
  455. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -12
  456. package/lib/chevre/service/task/voidReserveTransaction.js +10 -16
  457. package/lib/chevre/service/task.js +16 -22
  458. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +9 -20
  459. package/lib/chevre/service/taskHandler/onOperationFailed.js +20 -17
  460. package/lib/chevre/service/taskHandler.js +19 -21
  461. package/lib/chevre/service/transaction/deleteTransaction.js +104 -84
  462. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +15 -6
  463. package/lib/chevre/service/transaction/moneyTransfer/factory.js +13 -4
  464. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +12 -24
  465. package/lib/chevre/service/transaction/moneyTransfer.js +119 -96
  466. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +49 -51
  467. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +14 -25
  468. package/lib/chevre/service/transaction/placeOrder/confirm/publishCode.js +4 -14
  469. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateInvoiceReferencesOrder.js +3 -4
  470. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validateMovieTicket.js +3 -4
  471. package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +2 -3
  472. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +30 -45
  473. package/lib/chevre/service/transaction/placeOrder/confirm.js +75 -55
  474. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +31 -13
  475. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +6 -15
  476. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +6 -15
  477. package/lib/chevre/service/transaction/placeOrder/publishOrderNumberIfNotExist.js +7 -16
  478. package/lib/chevre/service/transaction/placeOrder/start/factory.js +27 -7
  479. package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +53 -59
  480. package/lib/chevre/service/transaction/placeOrder/start.js +14 -18
  481. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +13 -6
  482. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +176 -190
  483. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +77 -89
  484. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +40 -48
  485. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +52 -56
  486. package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +100 -102
  487. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +60 -80
  488. package/lib/chevre/service/transaction/returnOrder/preStart.js +42 -46
  489. package/lib/chevre/service/transaction/returnOrder.js +32 -36
  490. package/lib/chevre/service/transaction.js +75 -46
  491. package/lib/chevre/service/validation/validateEvent.js +2 -11
  492. package/lib/chevre/service/validation/validateOrder.js +7 -16
  493. package/lib/chevre/service.js +85 -128
  494. package/lib/chevre/settings/aggregation.js +4 -0
  495. package/lib/chevre/settings.js +7 -0
  496. package/package.json +8 -11
  497. package/example/src/chevre/addEventBySchedule.ts +0 -46
  498. package/example/src/chevre/orderNumber/decryptOrderNumber.ts +0 -14
  499. package/example/src/idaas/auth0/adminApplications.ts +0 -183
  500. package/example/src/idaas/auth0/getToken.ts +0 -55
  501. package/example/src/idaas/auth0/getTokenByPrivateKeyJWT.ts +0 -84
  502. package/lib/chevre/service/task/createEvent/createEvent.d.ts +0 -25
  503. package/lib/chevre/service/task/createEvent/createEvent.js +0 -45
  504. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.d.ts +0 -22
  505. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +0 -190
  506. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.d.ts +0 -15
  507. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.js +0 -118
  508. package/lib/chevre/service/task/createEvent/createEventBySchedule.d.ts +0 -25
  509. package/lib/chevre/service/task/createEvent/createEventBySchedule.js +0 -107
  510. package/lib/chevre/service/task/createEvent/createEventSeries.d.ts +0 -13
  511. package/lib/chevre/service/task/createEvent/createEventSeries.js +0 -118
  512. package/lib/chevre/service/task/createEvent.d.ts +0 -6
  513. package/lib/chevre/service/task/createEvent.js +0 -46
@@ -1,24 +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
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.ActionRepo = void 0;
24
4
  const moment = require("moment");
@@ -57,23 +37,24 @@ const AVAILABLE_PROJECT_FIELDS = [
57
37
  * アクションリポジトリ
58
38
  */
59
39
  class ActionRepo {
40
+ actionModel;
41
+ actionRecipeModel;
60
42
  constructor(connection) {
61
43
  this.actionModel = connection.model(action_1.modelName, (0, action_1.createSchema)());
62
44
  this.actionRecipeModel = connection.model(actionRecipe_1.modelName, (0, actionRecipe_1.createSchema)());
63
45
  }
64
46
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
65
47
  static CREATE_MONGO_CONDITIONS(params) {
66
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76;
67
48
  const andConditions = [];
68
- const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
49
+ const idIn = params.id?.$in;
69
50
  if (Array.isArray(idIn)) {
70
51
  andConditions.push({ _id: { $in: idIn } });
71
52
  }
72
- const idNin = (_b = params.id) === null || _b === void 0 ? void 0 : _b.$nin;
53
+ const idNin = params.id?.$nin;
73
54
  if (Array.isArray(idNin)) {
74
55
  andConditions.push({ _id: { $nin: idNin } });
75
56
  }
76
- const projectIdEq = (_d = (_c = params.project) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
57
+ const projectIdEq = params.project?.id?.$eq;
77
58
  if (typeof projectIdEq === 'string') {
78
59
  andConditions.push({
79
60
  'project.id': {
@@ -81,7 +62,7 @@ class ActionRepo {
81
62
  }
82
63
  });
83
64
  }
84
- const agentTypeOfIn = (_f = (_e = params.agent) === null || _e === void 0 ? void 0 : _e.typeOf) === null || _f === void 0 ? void 0 : _f.$in;
65
+ const agentTypeOfIn = params.agent?.typeOf?.$in;
85
66
  if (Array.isArray(agentTypeOfIn)) {
86
67
  andConditions.push({
87
68
  'agent.typeOf': {
@@ -90,7 +71,7 @@ class ActionRepo {
90
71
  }
91
72
  });
92
73
  }
93
- const agentIdIn = (_h = (_g = params.agent) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$in;
74
+ const agentIdIn = params.agent?.id?.$in;
94
75
  if (Array.isArray(agentIdIn)) {
95
76
  andConditions.push({
96
77
  'agent.id': {
@@ -99,27 +80,27 @@ class ActionRepo {
99
80
  }
100
81
  });
101
82
  }
102
- const instrumentTransactionNumberEq = (_k = (_j = params.instrument) === null || _j === void 0 ? void 0 : _j.transactionNumber) === null || _k === void 0 ? void 0 : _k.$eq;
83
+ const instrumentTransactionNumberEq = params.instrument?.transactionNumber?.$eq;
103
84
  if (typeof instrumentTransactionNumberEq === 'string') {
104
85
  andConditions.push({ 'instrument.transactionNumber': { $exists: true, $eq: instrumentTransactionNumberEq } });
105
86
  }
106
- const instrumentTypeOfEq = (_m = (_l = params.instrument) === null || _l === void 0 ? void 0 : _l.typeOf) === null || _m === void 0 ? void 0 : _m.$eq;
87
+ const instrumentTypeOfEq = params.instrument?.typeOf?.$eq;
107
88
  if (typeof instrumentTypeOfEq === 'string') {
108
89
  andConditions.push({ 'instrument.typeOf': { $exists: true, $eq: instrumentTypeOfEq } });
109
90
  }
110
- const instrumentIdentifierEq = (_p = (_o = params.instrument) === null || _o === void 0 ? void 0 : _o.identifier) === null || _p === void 0 ? void 0 : _p.$eq;
91
+ const instrumentIdentifierEq = params.instrument?.identifier?.$eq;
111
92
  if (typeof instrumentIdentifierEq === 'string') {
112
93
  andConditions.push({ 'instrument.identifier': { $exists: true, $eq: instrumentIdentifierEq } });
113
94
  }
114
- const instrumentIdEq = (_r = (_q = params.instrument) === null || _q === void 0 ? void 0 : _q.id) === null || _r === void 0 ? void 0 : _r.$eq;
95
+ const instrumentIdEq = params.instrument?.id?.$eq;
115
96
  if (typeof instrumentIdEq === 'string') {
116
97
  andConditions.push({ 'instrument.id': { $exists: true, $eq: instrumentIdEq } });
117
98
  }
118
- const instrumentOrderNumberEq = (_t = (_s = params.instrument) === null || _s === void 0 ? void 0 : _s.orderNumber) === null || _t === void 0 ? void 0 : _t.$eq;
99
+ const instrumentOrderNumberEq = params.instrument?.orderNumber?.$eq;
119
100
  if (typeof instrumentOrderNumberEq === 'string') {
120
101
  andConditions.push({ 'instrument.orderNumber': { $exists: true, $eq: instrumentOrderNumberEq } });
121
102
  }
122
- const locationIdEq = (_v = (_u = params.location) === null || _u === void 0 ? void 0 : _u.id) === null || _v === void 0 ? void 0 : _v.$eq;
103
+ const locationIdEq = params.location?.id?.$eq;
123
104
  if (typeof locationIdEq === 'string') {
124
105
  andConditions.push({
125
106
  'location.id': {
@@ -128,7 +109,7 @@ class ActionRepo {
128
109
  }
129
110
  });
130
111
  }
131
- const locationIdentifierEq = (_x = (_w = params.location) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$eq;
112
+ const locationIdentifierEq = params.location?.identifier?.$eq;
132
113
  if (typeof locationIdentifierEq === 'string') {
133
114
  andConditions.push({
134
115
  'location.identifier': {
@@ -137,7 +118,7 @@ class ActionRepo {
137
118
  }
138
119
  });
139
120
  }
140
- const objectMovieTicketsIdentifierEq = (_0 = (_z = (_y = params.object) === null || _y === void 0 ? void 0 : _y.movieTickets) === null || _z === void 0 ? void 0 : _z.identifier) === null || _0 === void 0 ? void 0 : _0.$eq;
121
+ const objectMovieTicketsIdentifierEq = params.object?.movieTickets?.identifier?.$eq;
141
122
  if (typeof objectMovieTicketsIdentifierEq === 'string') {
142
123
  andConditions.push({
143
124
  'object.movieTickets.identifier': {
@@ -146,7 +127,7 @@ class ActionRepo {
146
127
  }
147
128
  });
148
129
  }
149
- const objectMovieTicketsServiceOutputReservationForIdEq = (_5 = (_4 = (_3 = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.movieTickets) === null || _2 === void 0 ? void 0 : _2.serviceOutput) === null || _3 === void 0 ? void 0 : _3.reservationFor) === null || _4 === void 0 ? void 0 : _4.id) === null || _5 === void 0 ? void 0 : _5.$eq;
130
+ const objectMovieTicketsServiceOutputReservationForIdEq = params.object?.movieTickets?.serviceOutput?.reservationFor?.id?.$eq;
150
131
  if (typeof objectMovieTicketsServiceOutputReservationForIdEq === 'string') {
151
132
  andConditions.push({
152
133
  'object.movieTickets.serviceOutput.reservationFor.id': {
@@ -155,7 +136,7 @@ class ActionRepo {
155
136
  }
156
137
  });
157
138
  }
158
- const objectPaymentMethodIdEq = (_7 = (_6 = params.object) === null || _6 === void 0 ? void 0 : _6.paymentMethodId) === null || _7 === void 0 ? void 0 : _7.$eq;
139
+ const objectPaymentMethodIdEq = params.object?.paymentMethodId?.$eq;
159
140
  if (typeof objectPaymentMethodIdEq === 'string') {
160
141
  andConditions.push({
161
142
  'object.paymentMethodId': {
@@ -164,7 +145,7 @@ class ActionRepo {
164
145
  }
165
146
  });
166
147
  }
167
- const objectObjectPaymentMethodIdEq = (_10 = (_9 = (_8 = params.object) === null || _8 === void 0 ? void 0 : _8.object) === null || _9 === void 0 ? void 0 : _9.paymentMethodId) === null || _10 === void 0 ? void 0 : _10.$eq;
148
+ const objectObjectPaymentMethodIdEq = params.object?.object?.paymentMethodId?.$eq;
168
149
  if (typeof objectObjectPaymentMethodIdEq === 'string') {
169
150
  andConditions.push({
170
151
  'object.object.paymentMethodId': {
@@ -173,7 +154,7 @@ class ActionRepo {
173
154
  }
174
155
  });
175
156
  }
176
- const objectReservationForIdEq = (_13 = (_12 = (_11 = params.object) === null || _11 === void 0 ? void 0 : _11.reservationFor) === null || _12 === void 0 ? void 0 : _12.id) === null || _13 === void 0 ? void 0 : _13.$eq;
157
+ const objectReservationForIdEq = params.object?.reservationFor?.id?.$eq;
177
158
  if (typeof objectReservationForIdEq === 'string') {
178
159
  andConditions.push({
179
160
  'object.reservationFor.id': {
@@ -182,7 +163,7 @@ class ActionRepo {
182
163
  }
183
164
  });
184
165
  }
185
- const objectReservationNumberEq = (_15 = (_14 = params.object) === null || _14 === void 0 ? void 0 : _14.reservationNumber) === null || _15 === void 0 ? void 0 : _15.$eq;
166
+ const objectReservationNumberEq = params.object?.reservationNumber?.$eq;
186
167
  if (typeof objectReservationNumberEq === 'string') {
187
168
  andConditions.push({
188
169
  'object.reservationNumber': {
@@ -191,7 +172,7 @@ class ActionRepo {
191
172
  }
192
173
  });
193
174
  }
194
- const objectReservationNumberIn = (_17 = (_16 = params.object) === null || _16 === void 0 ? void 0 : _16.reservationNumber) === null || _17 === void 0 ? void 0 : _17.$in;
175
+ const objectReservationNumberIn = params.object?.reservationNumber?.$in;
195
176
  if (Array.isArray(objectReservationNumberIn)) {
196
177
  andConditions.push({
197
178
  'object.reservationNumber': {
@@ -200,7 +181,7 @@ class ActionRepo {
200
181
  }
201
182
  });
202
183
  }
203
- const objectPaymentMethodAccountIdEq = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.paymentMethod) === null || _19 === void 0 ? void 0 : _19.accountId) === null || _20 === void 0 ? void 0 : _20.$eq;
184
+ const objectPaymentMethodAccountIdEq = params.object?.paymentMethod?.accountId?.$eq;
204
185
  if (typeof objectPaymentMethodAccountIdEq === 'string') {
205
186
  andConditions.push({
206
187
  'object.paymentMethod.accountId': {
@@ -209,7 +190,7 @@ class ActionRepo {
209
190
  }
210
191
  });
211
192
  }
212
- const objectPaymentMethodPaymentMethodIdEq = (_23 = (_22 = (_21 = params.object) === null || _21 === void 0 ? void 0 : _21.paymentMethod) === null || _22 === void 0 ? void 0 : _22.paymentMethodId) === null || _23 === void 0 ? void 0 : _23.$eq;
193
+ const objectPaymentMethodPaymentMethodIdEq = params.object?.paymentMethod?.paymentMethodId?.$eq;
213
194
  if (typeof objectPaymentMethodPaymentMethodIdEq === 'string') {
214
195
  andConditions.push({
215
196
  'object.paymentMethod.paymentMethodId': {
@@ -218,7 +199,7 @@ class ActionRepo {
218
199
  }
219
200
  });
220
201
  }
221
- const objectPaymentMethodPaymentMethodIdIn = (_26 = (_25 = (_24 = params.object) === null || _24 === void 0 ? void 0 : _24.paymentMethod) === null || _25 === void 0 ? void 0 : _25.paymentMethodId) === null || _26 === void 0 ? void 0 : _26.$in;
202
+ const objectPaymentMethodPaymentMethodIdIn = params.object?.paymentMethod?.paymentMethodId?.$in;
222
203
  if (Array.isArray(objectPaymentMethodPaymentMethodIdIn)) {
223
204
  andConditions.push({
224
205
  'object.paymentMethod.paymentMethodId': {
@@ -227,7 +208,7 @@ class ActionRepo {
227
208
  }
228
209
  });
229
210
  }
230
- const objectPaymentMethodTypeOfEq = (_29 = (_28 = (_27 = params.object) === null || _27 === void 0 ? void 0 : _27.paymentMethod) === null || _28 === void 0 ? void 0 : _28.typeOf) === null || _29 === void 0 ? void 0 : _29.$eq;
211
+ const objectPaymentMethodTypeOfEq = params.object?.paymentMethod?.typeOf?.$eq;
231
212
  if (typeof objectPaymentMethodTypeOfEq === 'string') {
232
213
  andConditions.push({
233
214
  'object.paymentMethod.typeOf': {
@@ -236,7 +217,7 @@ class ActionRepo {
236
217
  }
237
218
  });
238
219
  }
239
- const objectTypeOfEq = (_31 = (_30 = params.object) === null || _30 === void 0 ? void 0 : _30.typeOf) === null || _31 === void 0 ? void 0 : _31.$eq;
220
+ const objectTypeOfEq = params.object?.typeOf?.$eq;
240
221
  if (typeof objectTypeOfEq === 'string') {
241
222
  andConditions.push({
242
223
  'object.typeOf': {
@@ -245,7 +226,7 @@ class ActionRepo {
245
226
  }
246
227
  });
247
228
  }
248
- const objectTypeOfIn = (_33 = (_32 = params.object) === null || _32 === void 0 ? void 0 : _32.typeOf) === null || _33 === void 0 ? void 0 : _33.$in;
229
+ const objectTypeOfIn = params.object?.typeOf?.$in;
249
230
  if (Array.isArray(objectTypeOfIn)) {
250
231
  andConditions.push({
251
232
  'object.typeOf': {
@@ -254,7 +235,7 @@ class ActionRepo {
254
235
  }
255
236
  });
256
237
  }
257
- const objectIdEq = (_35 = (_34 = params.object) === null || _34 === void 0 ? void 0 : _34.id) === null || _35 === void 0 ? void 0 : _35.$eq;
238
+ const objectIdEq = params.object?.id?.$eq;
258
239
  if (typeof objectIdEq === 'string') {
259
240
  andConditions.push({
260
241
  'object.id': {
@@ -263,7 +244,7 @@ class ActionRepo {
263
244
  }
264
245
  });
265
246
  }
266
- const objectIdIn = (_37 = (_36 = params.object) === null || _36 === void 0 ? void 0 : _36.id) === null || _37 === void 0 ? void 0 : _37.$in;
247
+ const objectIdIn = params.object?.id?.$in;
267
248
  if (Array.isArray(objectIdIn)) {
268
249
  andConditions.push({
269
250
  'object.id': {
@@ -272,7 +253,7 @@ class ActionRepo {
272
253
  }
273
254
  });
274
255
  }
275
- const objectOrderNumberIn = (_39 = (_38 = params.object) === null || _38 === void 0 ? void 0 : _38.orderNumber) === null || _39 === void 0 ? void 0 : _39.$in;
256
+ const objectOrderNumberIn = params.object?.orderNumber?.$in;
276
257
  if (Array.isArray(objectOrderNumberIn)) {
277
258
  andConditions.push({
278
259
  'object.orderNumber': {
@@ -281,7 +262,7 @@ class ActionRepo {
281
262
  }
282
263
  });
283
264
  }
284
- const objectEventIdIn = (_42 = (_41 = (_40 = params.object) === null || _40 === void 0 ? void 0 : _40.event) === null || _41 === void 0 ? void 0 : _41.id) === null || _42 === void 0 ? void 0 : _42.$in;
265
+ const objectEventIdIn = params.object?.event?.id?.$in;
285
266
  if (Array.isArray(objectEventIdIn)) {
286
267
  andConditions.push({
287
268
  'object.event.id': {
@@ -301,7 +282,7 @@ class ActionRepo {
301
282
  // }
302
283
  // });
303
284
  // }
304
- const objectTransactionNumberEq = (_44 = (_43 = params.object) === null || _43 === void 0 ? void 0 : _43.transactionNumber) === null || _44 === void 0 ? void 0 : _44.$eq;
285
+ const objectTransactionNumberEq = params.object?.transactionNumber?.$eq;
305
286
  if (typeof objectTransactionNumberEq === 'string') {
306
287
  andConditions.push({ 'object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
307
288
  }
@@ -311,14 +292,14 @@ class ActionRepo {
311
292
  });
312
293
  }
313
294
  else {
314
- const typeOfEq = (_45 = params.typeOf) === null || _45 === void 0 ? void 0 : _45.$eq;
295
+ const typeOfEq = params.typeOf?.$eq;
315
296
  if (typeof typeOfEq === 'string') {
316
297
  andConditions.push({
317
298
  typeOf: { $eq: typeOfEq }
318
299
  });
319
300
  }
320
301
  }
321
- const actionStatusIn = (_46 = params.actionStatus) === null || _46 === void 0 ? void 0 : _46.$in;
302
+ const actionStatusIn = params.actionStatus?.$in;
322
303
  if (Array.isArray(actionStatusIn)) {
323
304
  andConditions.push({
324
305
  actionStatus: { $in: actionStatusIn }
@@ -341,7 +322,7 @@ class ActionRepo {
341
322
  startDate: { $lte: startDateLte }
342
323
  });
343
324
  }
344
- const fromLocationTypeOfIn = (_48 = (_47 = params.fromLocation) === null || _47 === void 0 ? void 0 : _47.typeOf) === null || _48 === void 0 ? void 0 : _48.$in;
325
+ const fromLocationTypeOfIn = params.fromLocation?.typeOf?.$in;
345
326
  if (Array.isArray(fromLocationTypeOfIn)) {
346
327
  andConditions.push({
347
328
  'fromLocation.typeOf': {
@@ -350,7 +331,7 @@ class ActionRepo {
350
331
  }
351
332
  });
352
333
  }
353
- const fromLocationAccountNumberIn = (_50 = (_49 = params.fromLocation) === null || _49 === void 0 ? void 0 : _49.accountNumber) === null || _50 === void 0 ? void 0 : _50.$in;
334
+ const fromLocationAccountNumberIn = params.fromLocation?.accountNumber?.$in;
354
335
  if (Array.isArray(fromLocationAccountNumberIn)) {
355
336
  andConditions.push({
356
337
  'fromLocation.accountNumber': {
@@ -359,7 +340,7 @@ class ActionRepo {
359
340
  }
360
341
  });
361
342
  }
362
- const fromLocationAccountTypeIn = (_52 = (_51 = params.fromLocation) === null || _51 === void 0 ? void 0 : _51.accountType) === null || _52 === void 0 ? void 0 : _52.$in;
343
+ const fromLocationAccountTypeIn = params.fromLocation?.accountType?.$in;
363
344
  if (Array.isArray(fromLocationAccountTypeIn)) {
364
345
  andConditions.push({
365
346
  'fromLocation.accountType': {
@@ -368,7 +349,7 @@ class ActionRepo {
368
349
  }
369
350
  });
370
351
  }
371
- const toLocationTypeOfIn = (_54 = (_53 = params.toLocation) === null || _53 === void 0 ? void 0 : _53.typeOf) === null || _54 === void 0 ? void 0 : _54.$in;
352
+ const toLocationTypeOfIn = params.toLocation?.typeOf?.$in;
372
353
  if (Array.isArray(toLocationTypeOfIn)) {
373
354
  andConditions.push({
374
355
  'toLocation.typeOf': {
@@ -377,7 +358,7 @@ class ActionRepo {
377
358
  }
378
359
  });
379
360
  }
380
- const toLocationAccountNumberIn = (_56 = (_55 = params.toLocation) === null || _55 === void 0 ? void 0 : _55.accountNumber) === null || _56 === void 0 ? void 0 : _56.$in;
361
+ const toLocationAccountNumberIn = params.toLocation?.accountNumber?.$in;
381
362
  if (Array.isArray(toLocationAccountNumberIn)) {
382
363
  andConditions.push({
383
364
  'toLocation.accountNumber': {
@@ -386,7 +367,7 @@ class ActionRepo {
386
367
  }
387
368
  });
388
369
  }
389
- const toLocationAccountTypeIn = (_58 = (_57 = params.toLocation) === null || _57 === void 0 ? void 0 : _57.accountType) === null || _58 === void 0 ? void 0 : _58.$in;
370
+ const toLocationAccountTypeIn = params.toLocation?.accountType?.$in;
390
371
  if (Array.isArray(toLocationAccountTypeIn)) {
391
372
  andConditions.push({
392
373
  'toLocation.accountType': {
@@ -395,7 +376,7 @@ class ActionRepo {
395
376
  }
396
377
  });
397
378
  }
398
- const purposeTypeOfIn = (_60 = (_59 = params.purpose) === null || _59 === void 0 ? void 0 : _59.typeOf) === null || _60 === void 0 ? void 0 : _60.$in;
379
+ const purposeTypeOfIn = params.purpose?.typeOf?.$in;
399
380
  if (Array.isArray(purposeTypeOfIn)) {
400
381
  andConditions.push({
401
382
  'purpose.typeOf': {
@@ -404,7 +385,7 @@ class ActionRepo {
404
385
  }
405
386
  });
406
387
  }
407
- const purposeIdIn = (_62 = (_61 = params.purpose) === null || _61 === void 0 ? void 0 : _61.id) === null || _62 === void 0 ? void 0 : _62.$in;
388
+ const purposeIdIn = params.purpose?.id?.$in;
408
389
  if (Array.isArray(purposeIdIn)) {
409
390
  andConditions.push({
410
391
  'purpose.id': {
@@ -413,7 +394,7 @@ class ActionRepo {
413
394
  }
414
395
  });
415
396
  }
416
- const purposeOrderNumberIn = (_64 = (_63 = params.purpose) === null || _63 === void 0 ? void 0 : _63.orderNumber) === null || _64 === void 0 ? void 0 : _64.$in;
397
+ const purposeOrderNumberIn = params.purpose?.orderNumber?.$in;
417
398
  if (Array.isArray(purposeOrderNumberIn)) {
418
399
  andConditions.push({
419
400
  'purpose.orderNumber': {
@@ -422,7 +403,7 @@ class ActionRepo {
422
403
  }
423
404
  });
424
405
  }
425
- const resultTypeOfIn = (_66 = (_65 = params.result) === null || _65 === void 0 ? void 0 : _65.typeOf) === null || _66 === void 0 ? void 0 : _66.$in;
406
+ const resultTypeOfIn = params.result?.typeOf?.$in;
426
407
  if (Array.isArray(resultTypeOfIn)) {
427
408
  andConditions.push({
428
409
  'result.typeOf': {
@@ -431,7 +412,7 @@ class ActionRepo {
431
412
  }
432
413
  });
433
414
  }
434
- const resultIdIn = (_68 = (_67 = params.result) === null || _67 === void 0 ? void 0 : _67.id) === null || _68 === void 0 ? void 0 : _68.$in;
415
+ const resultIdIn = params.result?.id?.$in;
435
416
  if (Array.isArray(resultIdIn)) {
436
417
  andConditions.push({
437
418
  'result.id': {
@@ -440,7 +421,7 @@ class ActionRepo {
440
421
  }
441
422
  });
442
423
  }
443
- const resultOrderNumberIn = (_70 = (_69 = params.result) === null || _69 === void 0 ? void 0 : _69.orderNumber) === null || _70 === void 0 ? void 0 : _70.$in;
424
+ const resultOrderNumberIn = params.result?.orderNumber?.$in;
444
425
  if (Array.isArray(resultOrderNumberIn)) {
445
426
  andConditions.push({
446
427
  'result.orderNumber': {
@@ -449,7 +430,7 @@ class ActionRepo {
449
430
  }
450
431
  });
451
432
  }
452
- const resultCodeIn = (_72 = (_71 = params.result) === null || _71 === void 0 ? void 0 : _71.code) === null || _72 === void 0 ? void 0 : _72.$in;
433
+ const resultCodeIn = params.result?.code?.$in;
453
434
  if (Array.isArray(resultCodeIn)) {
454
435
  andConditions.push({
455
436
  'result.code': {
@@ -459,11 +440,11 @@ class ActionRepo {
459
440
  });
460
441
  }
461
442
  // sameAs(2024-04-23~)
462
- const sameAsIdEq = (_74 = (_73 = params.sameAs) === null || _73 === void 0 ? void 0 : _73.id) === null || _74 === void 0 ? void 0 : _74.$eq;
443
+ const sameAsIdEq = params.sameAs?.id?.$eq;
463
444
  if (typeof sameAsIdEq === 'string') {
464
445
  andConditions.push({ 'sameAs.id': { $exists: true, $eq: sameAsIdEq } });
465
446
  }
466
- const aboutOrderNumberEq = (_76 = (_75 = params.about) === null || _75 === void 0 ? void 0 : _75.orderNumber) === null || _76 === void 0 ? void 0 : _76.$eq;
447
+ const aboutOrderNumberEq = params.about?.orderNumber?.$eq;
467
448
  if (typeof aboutOrderNumberEq === 'string') {
468
449
  andConditions.push({ 'about.orderNumber': { $exists: true, $eq: aboutOrderNumberEq } });
469
450
  }
@@ -472,404 +453,396 @@ class ActionRepo {
472
453
  /**
473
454
  * アクション検索
474
455
  */
475
- search(params, inclusion) {
476
- return __awaiter(this, void 0, void 0, function* () {
477
- var _a;
478
- const conditions = ActionRepo.CREATE_MONGO_CONDITIONS(params);
479
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
480
- if (Array.isArray(inclusion) && inclusion.length > 0) {
481
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
482
- }
483
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
484
- const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
485
- if (typeof params.limit === 'number' && params.limit > 0) {
486
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
487
- query.limit(params.limit)
488
- .skip(params.limit * (page - 1));
489
- }
490
- // tslint:disable-next-line:no-single-line-block-comment
491
- /* istanbul ignore else */
492
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.startDate) !== undefined) {
493
- query.sort({ startDate: params.sort.startDate });
494
- }
495
- // const explainResult = await (<any>query).explain();
496
- // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
497
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
498
- .lean() // 2024-08-26~
499
- .exec();
500
- });
456
+ async search(params, inclusion) {
457
+ const conditions = ActionRepo.CREATE_MONGO_CONDITIONS(params);
458
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
459
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
460
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
461
+ }
462
+ const projection = {
463
+ _id: 0,
464
+ id: { $toString: '$_id' },
465
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
466
+ };
467
+ const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
468
+ if (typeof params.limit === 'number' && params.limit > 0) {
469
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
470
+ query.limit(params.limit)
471
+ .skip(params.limit * (page - 1));
472
+ }
473
+ // tslint:disable-next-line:no-single-line-block-comment
474
+ /* istanbul ignore else */
475
+ if (params.sort?.startDate !== undefined) {
476
+ query.sort({ startDate: params.sort.startDate });
477
+ }
478
+ // const explainResult = await (<any>query).explain();
479
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
480
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
481
+ .lean() // 2024-08-26~
482
+ .exec();
501
483
  }
502
484
  /**
503
485
  * アクション開始
504
486
  */
505
- start(attributes, options) {
506
- return __awaiter(this, void 0, void 0, function* () {
507
- var _a, _b;
508
- const startDate = new Date();
509
- const creatingAction = Object.assign(Object.assign({}, attributes), { actionStatus: factory.actionStatusType.ActiveActionStatus, startDate });
510
- // reimplemnt with insertMany(2024-08-29~)
511
- const result = yield this.actionModel.insertMany(creatingAction, { rawResult: true });
512
- const id = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
513
- if (typeof id !== 'string') {
514
- throw new factory.errors.Internal('action not saved');
515
- }
516
- // add recipe(2024-06-09~)
517
- const savingRecipe = options === null || options === void 0 ? void 0 : options.recipe;
518
- if ((savingRecipe === null || savingRecipe === void 0 ? void 0 : savingRecipe.typeOf) === 'Recipe') {
519
- yield this.upsertRecipe(Object.assign(Object.assign({}, savingRecipe), { recipeFor: { id, typeOf: creatingAction.typeOf } }));
520
- }
521
- return { id, startDate, typeOf: creatingAction.typeOf };
522
- });
487
+ async start(attributes, options) {
488
+ const startDate = new Date();
489
+ const creatingAction = {
490
+ ...attributes,
491
+ actionStatus: factory.actionStatusType.ActiveActionStatus,
492
+ startDate
493
+ };
494
+ // reimplemnt with insertMany(2024-08-29~)
495
+ const result = await this.actionModel.insertMany(creatingAction, { rawResult: true });
496
+ const id = result.insertedIds?.[0]?.toHexString();
497
+ if (typeof id !== 'string') {
498
+ throw new factory.errors.Internal('action not saved');
499
+ }
500
+ // add recipe(2024-06-09~)
501
+ const savingRecipe = options?.recipe;
502
+ if (savingRecipe?.typeOf === 'Recipe') {
503
+ await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf } });
504
+ }
505
+ return { id, startDate, typeOf: creatingAction.typeOf };
523
506
  }
524
- completeWithVoid(params) {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- var _a;
527
- if (((_a = params.recipe) === null || _a === void 0 ? void 0 : _a.typeOf) === 'Recipe') {
528
- yield this.upsertRecipe(Object.assign(Object.assign({}, params.recipe), { recipeFor: { id: params.id, typeOf: params.typeOf } }));
529
- }
530
- const doc = yield this.actionModel.findOneAndUpdate({
531
- _id: { $eq: params.id },
532
- typeOf: { $eq: params.typeOf }
533
- }, {
534
- $set: {
535
- actionStatus: factory.actionStatusType.CompletedActionStatus,
536
- result: params.result,
537
- endDate: new Date()
538
- }
539
- }, { new: false, projection: { _id: 1 } })
540
- .lean()
541
- .exec();
542
- if (doc === null) {
543
- throw new factory.errors.NotFound(this.actionModel.modelName);
507
+ async completeWithVoid(params) {
508
+ if (params.recipe?.typeOf === 'Recipe') {
509
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
510
+ }
511
+ const doc = await this.actionModel.findOneAndUpdate({
512
+ _id: { $eq: params.id },
513
+ typeOf: { $eq: params.typeOf }
514
+ }, {
515
+ $set: {
516
+ actionStatus: factory.actionStatusType.CompletedActionStatus,
517
+ result: params.result,
518
+ endDate: new Date()
544
519
  }
545
- });
520
+ }, { new: false, projection: { _id: 1 } })
521
+ .lean()
522
+ .exec();
523
+ if (doc === null) {
524
+ throw new factory.errors.NotFound(this.actionModel.modelName);
525
+ }
546
526
  }
547
527
  /**
548
528
  * アクション取消
549
529
  */
550
- cancelWithVoid(params) {
551
- return __awaiter(this, void 0, void 0, function* () {
552
- const cancelDate = new Date();
553
- const cancelAction = (params.cancelAction !== undefined)
554
- ? Object.assign(Object.assign({}, params.cancelAction), { endTime: cancelDate, typeOf: factory.actionType.CancelAction }) : undefined;
555
- const doc = yield this.actionModel.findOneAndUpdate({
556
- _id: { $eq: params.id },
557
- typeOf: { $eq: params.typeOf },
558
- actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
559
- }, {
560
- $set: Object.assign({ actionStatus: factory.actionStatusType.CanceledActionStatus }, (cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
561
- )
562
- }, { new: false, projection: { _id: 1 } })
563
- .lean()
564
- .exec();
565
- if (doc === null) {
566
- // 既にCanceledActionStatusであればok
567
- const existingAction = yield this.findById({ id: params.id, typeOf: params.typeOf }, ['actionStatus'], []);
568
- if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
569
- throw new factory.errors.NotFound(this.actionModel.modelName);
570
- }
530
+ async cancelWithVoid(params) {
531
+ const cancelDate = new Date();
532
+ const cancelAction = (params.cancelAction !== undefined)
533
+ ? {
534
+ ...params.cancelAction,
535
+ endTime: cancelDate,
536
+ typeOf: factory.actionType.CancelAction
571
537
  }
572
- // endDateが存在しなければセット(2024-04-22~)
573
- yield this.actionModel.updateOne({
574
- _id: { $eq: params.id },
575
- endDate: { $exists: false }
576
- }, { $set: { endDate: cancelDate } })
577
- .exec();
578
- });
538
+ : undefined;
539
+ const doc = await this.actionModel.findOneAndUpdate({
540
+ _id: { $eq: params.id },
541
+ typeOf: { $eq: params.typeOf },
542
+ actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
543
+ }, {
544
+ $set: {
545
+ actionStatus: factory.actionStatusType.CanceledActionStatus,
546
+ ...(cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
547
+ }
548
+ }, { new: false, projection: { _id: 1 } })
549
+ .lean()
550
+ .exec();
551
+ if (doc === null) {
552
+ // 既にCanceledActionStatusであればok
553
+ const existingAction = await this.findById({ id: params.id, typeOf: params.typeOf }, ['actionStatus'], []);
554
+ if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
555
+ throw new factory.errors.NotFound(this.actionModel.modelName);
556
+ }
557
+ }
558
+ // endDateが存在しなければセット(2024-04-22~)
559
+ await this.actionModel.updateOne({
560
+ _id: { $eq: params.id },
561
+ endDate: { $exists: false }
562
+ }, { $set: { endDate: cancelDate } })
563
+ .exec();
579
564
  }
580
565
  /**
581
566
  * アクション失敗
582
567
  */
583
- giveUp(params) {
584
- return __awaiter(this, void 0, void 0, function* () {
585
- var _a;
586
- const actionError = (Array.isArray(params.error))
587
- ? params.error.map((e) => (Object.assign(Object.assign({}, e), { message: e.message, name: e.name })))
588
- : Object.assign(Object.assign({}, params.error), { message: params.error.message, name: params.error.name });
589
- if (((_a = params.recipe) === null || _a === void 0 ? void 0 : _a.typeOf) === 'Recipe') {
590
- yield this.upsertRecipe(Object.assign(Object.assign({}, params.recipe), { recipeFor: { id: params.id, typeOf: params.typeOf } }));
591
- }
592
- const doc = yield this.actionModel.findOneAndUpdate({
593
- typeOf: { $eq: params.typeOf },
594
- _id: { $eq: params.id }
595
- }, {
596
- $set: {
597
- actionStatus: factory.actionStatusType.FailedActionStatus,
598
- error: actionError,
599
- endDate: new Date()
600
- }
601
- }, { new: true, projection: { _id: 1 } })
602
- .lean()
603
- .exec();
604
- if (doc === null) {
605
- throw new factory.errors.NotFound(this.actionModel.modelName);
568
+ async giveUp(params) {
569
+ const actionError = (Array.isArray(params.error))
570
+ ? params.error.map((e) => ({ ...e, message: e.message, name: e.name }))
571
+ : { ...params.error, message: params.error.message, name: params.error.name };
572
+ if (params.recipe?.typeOf === 'Recipe') {
573
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
574
+ }
575
+ const doc = await this.actionModel.findOneAndUpdate({
576
+ typeOf: { $eq: params.typeOf },
577
+ _id: { $eq: params.id }
578
+ }, {
579
+ $set: {
580
+ actionStatus: factory.actionStatusType.FailedActionStatus,
581
+ error: actionError,
582
+ endDate: new Date()
606
583
  }
607
- });
584
+ }, { new: true, projection: { _id: 1 } })
585
+ .lean()
586
+ .exec();
587
+ if (doc === null) {
588
+ throw new factory.errors.NotFound(this.actionModel.modelName);
589
+ }
608
590
  }
609
591
  /**
610
592
  * アクション再開
611
593
  */
612
- reStart(params) {
613
- return __awaiter(this, void 0, void 0, function* () {
614
- var _a;
615
- const doc = yield this.actionModel.findOneAndUpdate({
616
- _id: { $eq: params.id },
617
- typeOf: { $eq: params.typeOf },
618
- actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
619
- }, {
620
- $set: {
621
- actionStatus: factory.actionStatusType.ActiveActionStatus,
622
- startDate: new Date()
623
- },
624
- $unset: { endDate: 1 }
625
- }, { new: false, projection: { _id: 1 } })
626
- .lean()
627
- .exec();
628
- if (doc === null) {
629
- throw new factory.errors.NotFound(this.actionModel.modelName);
630
- }
631
- // add recipe(2024-06-09~)
632
- if (((_a = params.recipe) === null || _a === void 0 ? void 0 : _a.typeOf) === 'Recipe') {
633
- yield this.upsertRecipe(Object.assign(Object.assign({}, params.recipe), { recipeFor: { id: params.id, typeOf: params.typeOf } }));
634
- }
635
- });
594
+ async reStart(params) {
595
+ const doc = await this.actionModel.findOneAndUpdate({
596
+ _id: { $eq: params.id },
597
+ typeOf: { $eq: params.typeOf },
598
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
599
+ }, {
600
+ $set: {
601
+ actionStatus: factory.actionStatusType.ActiveActionStatus,
602
+ startDate: new Date()
603
+ },
604
+ $unset: { endDate: 1 }
605
+ }, { new: false, projection: { _id: 1 } })
606
+ .lean()
607
+ .exec();
608
+ if (doc === null) {
609
+ throw new factory.errors.NotFound(this.actionModel.modelName);
610
+ }
611
+ // add recipe(2024-06-09~)
612
+ if (params.recipe?.typeOf === 'Recipe') {
613
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
614
+ }
636
615
  }
637
616
  /**
638
617
  * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
639
618
  */
640
- giveUpStartDatePassedCertainPeriod(params) {
641
- return __awaiter(this, void 0, void 0, function* () {
642
- var _a;
643
- return this.actionModel.updateMany(Object.assign({ actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus },
644
- // 一定期間過ぎたもの
645
- startDate: { $lt: params.startDate.$lt } }, (typeof ((_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { _id: { $eq: params.id.$eq } } : undefined), {
646
- actionStatus: factory.actionStatusType.FailedActionStatus,
647
- error: params.error,
648
- endDate: new Date()
649
- })
650
- .exec();
651
- });
619
+ async giveUpStartDatePassedCertainPeriod(params) {
620
+ return this.actionModel.updateMany({
621
+ actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus },
622
+ // 一定期間過ぎたもの
623
+ startDate: { $lt: params.startDate.$lt },
624
+ ...(typeof params.id?.$eq === 'string') ? { _id: { $eq: params.id.$eq } } : undefined
625
+ }, {
626
+ actionStatus: factory.actionStatusType.FailedActionStatus,
627
+ error: params.error,
628
+ endDate: new Date()
629
+ })
630
+ .exec();
652
631
  }
653
- findById(params, inclusion, exclusion) {
654
- return __awaiter(this, void 0, void 0, function* () {
655
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
656
- if (Array.isArray(inclusion) && inclusion.length > 0) {
657
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
658
- }
659
- else {
660
- if (Array.isArray(exclusion) && exclusion.length > 0) {
661
- positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
662
- }
663
- }
664
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
665
- const doc = yield this.actionModel.findOne({
666
- typeOf: { $eq: params.typeOf },
667
- _id: { $eq: params.id }
668
- }, projection)
669
- .lean() // 2024-08-26~
670
- .exec();
671
- if (doc === null) {
672
- throw new factory.errors.NotFound(this.actionModel.modelName);
632
+ async findById(params, inclusion, exclusion) {
633
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
634
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
635
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
636
+ }
637
+ else {
638
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
639
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
673
640
  }
674
- return doc;
675
- });
641
+ }
642
+ const projection = {
643
+ _id: 0,
644
+ id: { $toString: '$_id' },
645
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
646
+ };
647
+ const doc = await this.actionModel.findOne({
648
+ typeOf: { $eq: params.typeOf },
649
+ _id: { $eq: params.id }
650
+ }, projection)
651
+ .lean() // 2024-08-26~
652
+ .exec();
653
+ if (doc === null) {
654
+ throw new factory.errors.NotFound(this.actionModel.modelName);
655
+ }
656
+ return doc;
676
657
  }
677
- findPayAction(params) {
678
- return __awaiter(this, void 0, void 0, function* () {
679
- var _a, _b;
680
- const payActions = yield this.search({
681
- limit: 1,
682
- page: 1,
683
- actionStatus: (Array.isArray((_a = params.actionStatus) === null || _a === void 0 ? void 0 : _a.$in))
684
- ? { $in: (_b = params.actionStatus) === null || _b === void 0 ? void 0 : _b.$in }
685
- : { $in: [factory.actionStatusType.CompletedActionStatus] },
686
- project: { id: { $eq: params.project.id } },
687
- typeOf: { $eq: factory.actionType.PayAction },
688
- object: { paymentMethod: { paymentMethodId: { $eq: params.paymentMethodId } } }
689
- }, []);
690
- return payActions.shift();
691
- });
658
+ async findPayAction(params) {
659
+ const payActions = await this.search({
660
+ limit: 1,
661
+ page: 1,
662
+ actionStatus: (Array.isArray(params.actionStatus?.$in))
663
+ ? { $in: params.actionStatus?.$in }
664
+ : { $in: [factory.actionStatusType.CompletedActionStatus] },
665
+ project: { id: { $eq: params.project.id } },
666
+ typeOf: { $eq: factory.actionType.PayAction },
667
+ object: { paymentMethod: { paymentMethodId: { $eq: params.paymentMethodId } } }
668
+ }, []);
669
+ return payActions.shift();
692
670
  }
693
671
  /**
694
672
  * 取引に対するアクションを検索する
695
673
  */
696
674
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
697
- searchByPurpose(params) {
698
- return __awaiter(this, void 0, void 0, function* () {
699
- var _a, _b, _c, _d, _e, _f;
700
- const andConditions = [
701
- { 'purpose.typeOf': { $exists: true, $eq: params.purpose.typeOf } },
702
- { 'purpose.id': { $exists: true, $eq: params.purpose.id } }
703
- ];
704
- // const idNin = params.id?.$nin;
705
- // if (Array.isArray(idNin)) {
706
- // andConditions.push({ _id: { $nin: idNin } });
707
- // }
708
- const objectPaymentMethodIdEq = (_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.paymentMethodId) === null || _b === void 0 ? void 0 : _b.$eq;
709
- if (typeof objectPaymentMethodIdEq === 'string') {
710
- andConditions.push({ 'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq } });
711
- }
712
- const objectTypeOfEq = (_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.typeOf) === null || _d === void 0 ? void 0 : _d.$eq;
713
- if (typeof objectTypeOfEq === 'string') {
714
- andConditions.push({ 'object.typeOf': { $exists: true, $eq: objectTypeOfEq } });
715
- }
716
- if (typeof params.typeOf === 'string') {
717
- andConditions.push({ typeOf: { $eq: params.typeOf } });
718
- }
719
- const actionStatusEq = (_e = params.actionStatus) === null || _e === void 0 ? void 0 : _e.$eq;
720
- if (typeof actionStatusEq === 'string') {
721
- andConditions.push({ actionStatus: { $eq: actionStatusEq } });
722
- }
723
- const positiveProjectionFields = [
724
- 'project',
725
- 'actionStatus',
726
- 'typeOf',
727
- 'description',
728
- 'agent',
729
- 'recipient',
730
- 'result',
731
- 'error',
732
- 'object',
733
- 'startDate',
734
- 'endDate',
735
- 'purpose',
736
- 'potentialActions',
737
- 'instrument',
738
- 'location',
739
- 'sameAs',
740
- 'cancelAction',
741
- 'identifier'
742
- ];
743
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
744
- const query = this.actionModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
745
- if (typeof ((_f = params.sort) === null || _f === void 0 ? void 0 : _f.startDate) === 'number') {
746
- query.sort({ startDate: params.sort.startDate });
747
- }
748
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
749
- .lean()
750
- .exec();
751
- // return <Promise<IAction4transaction<T>[]>><Promise<unknown[]>>this.search<T>(
752
- // {
753
- // purpose: {
754
- // id: { $in: [params.purpose.id] },
755
- // typeOf: { $in: [params.purpose.typeOf] }
756
- // },
757
- // object: {
758
- // ...(typeof params.object?.typeOf?.$eq === 'string')
759
- // ? { typeOf: { $eq: params.object.typeOf.$eq } }
760
- // : undefined,
761
- // ...(typeof params.object?.paymentMethodId?.$eq === 'string')
762
- // ? { paymentMethodId: { $eq: params.object.paymentMethodId.$eq } }
763
- // : undefined
764
- // },
765
- // ...(typeof params.actionStatus?.$eq === 'string') ? { actionStatus: { $in: [params.actionStatus.$eq] } } : undefined,
766
- // ...(typeof params.typeOf === 'string') ? { typeOf: { $eq: params.typeOf } } : undefined,
767
- // ...(Array.isArray(params.id?.$nin)) ? { id: { $nin: params.id?.$nin } } : undefined,
768
- // ...(typeof params.sort?.startDate === 'number') ? { sort: params.sort } : undefined
769
- // },
770
- // [],
771
- // []
772
- // );
773
- });
675
+ async searchByPurpose(params) {
676
+ const andConditions = [
677
+ { 'purpose.typeOf': { $exists: true, $eq: params.purpose.typeOf } },
678
+ { 'purpose.id': { $exists: true, $eq: params.purpose.id } }
679
+ ];
680
+ // const idNin = params.id?.$nin;
681
+ // if (Array.isArray(idNin)) {
682
+ // andConditions.push({ _id: { $nin: idNin } });
683
+ // }
684
+ const objectPaymentMethodIdEq = params.object?.paymentMethodId?.$eq;
685
+ if (typeof objectPaymentMethodIdEq === 'string') {
686
+ andConditions.push({ 'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq } });
687
+ }
688
+ const objectTypeOfEq = params.object?.typeOf?.$eq;
689
+ if (typeof objectTypeOfEq === 'string') {
690
+ andConditions.push({ 'object.typeOf': { $exists: true, $eq: objectTypeOfEq } });
691
+ }
692
+ if (typeof params.typeOf === 'string') {
693
+ andConditions.push({ typeOf: { $eq: params.typeOf } });
694
+ }
695
+ const actionStatusEq = params.actionStatus?.$eq;
696
+ if (typeof actionStatusEq === 'string') {
697
+ andConditions.push({ actionStatus: { $eq: actionStatusEq } });
698
+ }
699
+ const positiveProjectionFields = [
700
+ 'project',
701
+ 'actionStatus',
702
+ 'typeOf',
703
+ 'description',
704
+ 'agent',
705
+ 'recipient',
706
+ 'result',
707
+ 'error',
708
+ 'object',
709
+ 'startDate',
710
+ 'endDate',
711
+ 'purpose',
712
+ 'potentialActions',
713
+ 'instrument',
714
+ 'location',
715
+ 'sameAs',
716
+ 'cancelAction',
717
+ 'identifier'
718
+ ];
719
+ const projection = {
720
+ _id: 0,
721
+ id: { $toString: '$_id' },
722
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
723
+ };
724
+ const query = this.actionModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
725
+ if (typeof params.sort?.startDate === 'number') {
726
+ query.sort({ startDate: params.sort.startDate });
727
+ }
728
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
729
+ .lean()
730
+ .exec();
731
+ // return <Promise<IAction4transaction<T>[]>><Promise<unknown[]>>this.search<T>(
732
+ // {
733
+ // purpose: {
734
+ // id: { $in: [params.purpose.id] },
735
+ // typeOf: { $in: [params.purpose.typeOf] }
736
+ // },
737
+ // object: {
738
+ // ...(typeof params.object?.typeOf?.$eq === 'string')
739
+ // ? { typeOf: { $eq: params.object.typeOf.$eq } }
740
+ // : undefined,
741
+ // ...(typeof params.object?.paymentMethodId?.$eq === 'string')
742
+ // ? { paymentMethodId: { $eq: params.object.paymentMethodId.$eq } }
743
+ // : undefined
744
+ // },
745
+ // ...(typeof params.actionStatus?.$eq === 'string') ? { actionStatus: { $in: [params.actionStatus.$eq] } } : undefined,
746
+ // ...(typeof params.typeOf === 'string') ? { typeOf: { $eq: params.typeOf } } : undefined,
747
+ // ...(Array.isArray(params.id?.$nin)) ? { id: { $nin: params.id?.$nin } } : undefined,
748
+ // ...(typeof params.sort?.startDate === 'number') ? { sort: params.sort } : undefined
749
+ // },
750
+ // [],
751
+ // []
752
+ // );
774
753
  }
775
754
  /**
776
755
  * 注文番号から、注文に対するアクションを検索する
777
756
  */
778
- searchByOrderNumber(params) {
779
- return __awaiter(this, void 0, void 0, function* () {
780
- var _a;
781
- const filter = {
782
- $or: [
783
- { 'object.orderNumber': { $exists: true, $eq: params.orderNumber } },
784
- { 'purpose.orderNumber': { $exists: true, $eq: params.orderNumber } },
785
- // consider inform returnAction(2025-01-22~)
786
- { 'about.orderNumber': { $exists: true, $eq: params.orderNumber } },
787
- // consider reserveAction,cancelReservationAction(2025-02-17~)
788
- { 'instrument.orderNumber': { $exists: true, $eq: params.orderNumber } }
789
- ]
790
- };
791
- const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1]))));
792
- const query = this.actionModel.find(filter, projection);
793
- // .select({ __v: 0, createdAt: 0, updatedAt: 0 });
794
- // tslint:disable-next-line:no-single-line-block-comment
795
- /* istanbul ignore else */
796
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.startDate) !== undefined) {
797
- query.sort({ startDate: params.sort.startDate });
798
- }
799
- return query
800
- .lean() // 2024-08-26~
801
- .exec();
802
- });
757
+ async searchByOrderNumber(params) {
758
+ const filter = {
759
+ $or: [
760
+ { 'object.orderNumber': { $exists: true, $eq: params.orderNumber } },
761
+ { 'purpose.orderNumber': { $exists: true, $eq: params.orderNumber } },
762
+ // consider inform returnAction(2025-01-22~)
763
+ { 'about.orderNumber': { $exists: true, $eq: params.orderNumber } },
764
+ // consider reserveAction,cancelReservationAction(2025-02-17~)
765
+ { 'instrument.orderNumber': { $exists: true, $eq: params.orderNumber } }
766
+ ]
767
+ };
768
+ const projection = {
769
+ _id: 0,
770
+ id: { $toString: '$_id' },
771
+ ...Object.fromEntries(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1])))
772
+ };
773
+ const query = this.actionModel.find(filter, projection);
774
+ // .select({ __v: 0, createdAt: 0, updatedAt: 0 });
775
+ // tslint:disable-next-line:no-single-line-block-comment
776
+ /* istanbul ignore else */
777
+ if (params.sort?.startDate !== undefined) {
778
+ query.sort({ startDate: params.sort.startDate });
779
+ }
780
+ return query
781
+ .lean() // 2024-08-26~
782
+ .exec();
803
783
  }
804
- searchBySameAs(params) {
805
- return __awaiter(this, void 0, void 0, function* () {
806
- var _a;
807
- const projection = {
808
- _id: 0,
809
- id: { $toString: '$_id' },
810
- actionStatus: 1,
811
- error: 1,
812
- purpose: 1
813
- };
814
- const query = this.actionModel.find(Object.assign({ typeOf: { $eq: params.typeOf.$eq }, 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq } }, (typeof ((_a = params.purpose) === null || _a === void 0 ? void 0 : _a.id.$eq) === 'string')
784
+ async searchBySameAs(params) {
785
+ const projection = {
786
+ _id: 0,
787
+ id: { $toString: '$_id' },
788
+ actionStatus: 1,
789
+ error: 1,
790
+ purpose: 1
791
+ };
792
+ const query = this.actionModel.find({
793
+ typeOf: { $eq: params.typeOf.$eq },
794
+ 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq },
795
+ ...(typeof params.purpose?.id.$eq === 'string')
815
796
  ? { 'purpose.id': { $exists: true, $eq: params.purpose.id.$eq } }
816
- : undefined), projection)
817
- // .select({ _id: 1, actionStatus: 1, error: 1, purpose: 1 })
818
- .limit(1);
819
- return query
820
- .lean() // 2024-08-26~
821
- .exec();
822
- });
797
+ : undefined
798
+ }, projection)
799
+ // .select({ _id: 1, actionStatus: 1, error: 1, purpose: 1 })
800
+ .limit(1);
801
+ return query
802
+ .lean() // 2024-08-26~
803
+ .exec();
823
804
  }
824
- deleteByProject(params) {
825
- return __awaiter(this, void 0, void 0, function* () {
826
- yield this.actionModel.deleteMany({
827
- 'project.id': { $eq: params.project.id }
828
- })
829
- .exec();
830
- });
805
+ async deleteByProject(params) {
806
+ await this.actionModel.deleteMany({
807
+ 'project.id': { $eq: params.project.id }
808
+ })
809
+ .exec();
831
810
  }
832
- reCompleteAuthorizeEventOfferAction(params) {
833
- return __awaiter(this, void 0, void 0, function* () {
834
- return this.actionModel.findOneAndUpdate({
835
- // typeOf: factory.actionType.AuthorizeAction,
836
- _id: { $eq: params.id },
837
- // ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
838
- // actionStatus: factory.actionStatusType.CompletedActionStatus
839
- actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus }
840
- }, {
841
- $set: {
842
- actionStatus: factory.actionStatusType.CompletedActionStatus,
843
- object: params.object,
844
- result: params.result,
845
- endDate: new Date()
846
- }
847
- }, { new: true, projection: { _id: 1 } })
848
- .lean()
849
- .exec()
850
- .then((doc) => {
851
- if (doc === null) {
852
- throw new factory.errors.NotFound(this.actionModel.modelName);
853
- }
854
- });
811
+ async reCompleteAuthorizeEventOfferAction(params) {
812
+ return this.actionModel.findOneAndUpdate({
813
+ // typeOf: factory.actionType.AuthorizeAction,
814
+ _id: { $eq: params.id },
815
+ // ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
816
+ // actionStatus: factory.actionStatusType.CompletedActionStatus
817
+ actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus }
818
+ }, {
819
+ $set: {
820
+ actionStatus: factory.actionStatusType.CompletedActionStatus,
821
+ object: params.object,
822
+ result: params.result,
823
+ endDate: new Date()
824
+ }
825
+ }, { new: true, projection: { _id: 1 } })
826
+ .lean()
827
+ .exec()
828
+ .then((doc) => {
829
+ if (doc === null) {
830
+ throw new factory.errors.NotFound(this.actionModel.modelName);
831
+ }
855
832
  });
856
833
  }
857
- updateById(params) {
858
- return __awaiter(this, void 0, void 0, function* () {
859
- yield this.actionModel.updateOne({ _id: { $eq: params.id } }, params.update)
860
- .exec();
861
- });
834
+ async updateById(params) {
835
+ await this.actionModel.updateOne({ _id: { $eq: params.id } }, params.update)
836
+ .exec();
862
837
  }
863
- findByIdAndUpdate(params) {
864
- return __awaiter(this, void 0, void 0, function* () {
865
- yield this.actionModel.findOneAndUpdate({ _id: { $eq: params.id } }, params.update, { projection: { _id: 1 } })
866
- .lean()
867
- .exec()
868
- .then((doc) => {
869
- if (doc === null) {
870
- throw new factory.errors.NotFound(this.actionModel.modelName);
871
- }
872
- });
838
+ async findByIdAndUpdate(params) {
839
+ await this.actionModel.findOneAndUpdate({ _id: { $eq: params.id } }, params.update, { projection: { _id: 1 } })
840
+ .lean()
841
+ .exec()
842
+ .then((doc) => {
843
+ if (doc === null) {
844
+ throw new factory.errors.NotFound(this.actionModel.modelName);
845
+ }
873
846
  });
874
847
  }
875
848
  /**
@@ -932,158 +905,148 @@ class ActionRepo {
932
905
  // ])
933
906
  // .exec();
934
907
  // }
935
- searchYkknInfoByCheckRecipe(filter) {
936
- return __awaiter(this, void 0, void 0, function* () {
937
- const filterQuery = {
938
- _id: { $eq: filter.id },
939
- 'project.id': { $eq: filter.project.id },
940
- 'purpose.id': { $exists: true, $eq: filter.purpose.id },
941
- typeOf: { $eq: factory.actionType.CheckAction },
942
- actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
943
- };
944
- const actionDoc = yield this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
945
- .exec();
946
- if (actionDoc === null) {
947
- throw new factory.errors.NotFound(this.actionModel.modelName);
948
- }
949
- const filterQuery4recipe = {
950
- 'recipeFor.id': { $eq: filter.id }
951
- };
952
- const projectStage = {
953
- _id: 0,
954
- knyknrNo: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.knyknrNo',
955
- ykknshTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.ykknshTyp',
956
- eishhshkTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.eishhshkTyp',
957
- ykknKnshbtsmiNum: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.ykknKnshbtsmiNum',
958
- knshknhmbiUnip: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.knshknhmbiUnip',
959
- kijUnip: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.kijUnip'
960
- };
961
- const aggregate = this.actionRecipeModel.aggregate([
962
- { $unwind: '$step' },
963
- { $unwind: '$step.itemListElement' },
964
- { $unwind: '$step.itemListElement.itemListElement' },
965
- { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut' },
966
- { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo' },
967
- { $match: filterQuery4recipe },
968
- { $project: projectStage }
969
- ]);
970
- if (typeof filter.limit === 'number' && filter.limit > 0) {
971
- const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
972
- aggregate.limit(filter.limit * page)
973
- .skip(filter.limit * (page - 1));
974
- }
975
- return aggregate
976
- .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
977
- .exec();
978
- });
908
+ async searchYkknInfoByCheckRecipe(filter) {
909
+ const filterQuery = {
910
+ _id: { $eq: filter.id },
911
+ 'project.id': { $eq: filter.project.id },
912
+ 'purpose.id': { $exists: true, $eq: filter.purpose.id },
913
+ typeOf: { $eq: factory.actionType.CheckAction },
914
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
915
+ };
916
+ const actionDoc = await this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
917
+ .exec();
918
+ if (actionDoc === null) {
919
+ throw new factory.errors.NotFound(this.actionModel.modelName);
920
+ }
921
+ const filterQuery4recipe = {
922
+ 'recipeFor.id': { $eq: filter.id }
923
+ };
924
+ const projectStage = {
925
+ _id: 0,
926
+ knyknrNo: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.knyknrNo',
927
+ ykknshTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.ykknshTyp',
928
+ eishhshkTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.eishhshkTyp',
929
+ ykknKnshbtsmiNum: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.ykknKnshbtsmiNum',
930
+ knshknhmbiUnip: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.knshknhmbiUnip',
931
+ kijUnip: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo.kijUnip'
932
+ };
933
+ const aggregate = this.actionRecipeModel.aggregate([
934
+ { $unwind: '$step' },
935
+ { $unwind: '$step.itemListElement' },
936
+ { $unwind: '$step.itemListElement.itemListElement' },
937
+ { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut' },
938
+ { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo' },
939
+ { $match: filterQuery4recipe },
940
+ { $project: projectStage }
941
+ ]);
942
+ if (typeof filter.limit === 'number' && filter.limit > 0) {
943
+ const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
944
+ aggregate.limit(filter.limit * page)
945
+ .skip(filter.limit * (page - 1));
946
+ }
947
+ return aggregate
948
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
949
+ .exec();
979
950
  }
980
- searchMkknInfoByCheckRecipe(filter) {
981
- return __awaiter(this, void 0, void 0, function* () {
982
- const filterQuery = {
983
- _id: { $eq: filter.id },
984
- 'project.id': { $eq: filter.project.id },
985
- 'purpose.id': { $exists: true, $eq: filter.purpose.id },
986
- typeOf: { $eq: factory.actionType.CheckAction },
987
- actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
988
- };
989
- const actionDoc = this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
990
- .exec();
991
- if (actionDoc === null) {
992
- throw new factory.errors.NotFound(this.actionModel.modelName);
993
- }
994
- const filterQuery4recipe = {
995
- 'recipeFor.id': { $eq: filter.id }
996
- };
997
- const projectStage = {
998
- _id: 0,
999
- knyknrNo: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.knyknrNo',
1000
- mkknshTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkknshTyp',
1001
- mkknKnshbtsmiNum: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkknKnshbtsmiNum',
1002
- mkjyTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkjyTyp',
1003
- yykDt: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.yykDt',
1004
- shyJeiDt: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyJeiDt',
1005
- shyStCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyStCd',
1006
- shyScrnCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyScrnCd',
1007
- shySkhnCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shySkhnCd',
1008
- shySkhnNm: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shySkhnNm'
1009
- };
1010
- const aggregate = this.actionRecipeModel.aggregate([
1011
- { $unwind: '$step' },
1012
- { $unwind: '$step.itemListElement' },
1013
- { $unwind: '$step.itemListElement.itemListElement' },
1014
- { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut' },
1015
- { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo' },
1016
- { $match: filterQuery4recipe },
1017
- { $project: projectStage }
1018
- ]);
1019
- if (typeof filter.limit === 'number' && filter.limit > 0) {
1020
- const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
1021
- aggregate.limit(filter.limit * page)
1022
- .skip(filter.limit * (page - 1));
1023
- }
1024
- return aggregate
1025
- .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
1026
- .exec();
1027
- });
951
+ async searchMkknInfoByCheckRecipe(filter) {
952
+ const filterQuery = {
953
+ _id: { $eq: filter.id },
954
+ 'project.id': { $eq: filter.project.id },
955
+ 'purpose.id': { $exists: true, $eq: filter.purpose.id },
956
+ typeOf: { $eq: factory.actionType.CheckAction },
957
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
958
+ };
959
+ const actionDoc = this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
960
+ .exec();
961
+ if (actionDoc === null) {
962
+ throw new factory.errors.NotFound(this.actionModel.modelName);
963
+ }
964
+ const filterQuery4recipe = {
965
+ 'recipeFor.id': { $eq: filter.id }
966
+ };
967
+ const projectStage = {
968
+ _id: 0,
969
+ knyknrNo: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.knyknrNo',
970
+ mkknshTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkknshTyp',
971
+ mkknKnshbtsmiNum: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkknKnshbtsmiNum',
972
+ mkjyTyp: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.mkjyTyp',
973
+ yykDt: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.yykDt',
974
+ shyJeiDt: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyJeiDt',
975
+ shyStCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyStCd',
976
+ shyScrnCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shyScrnCd',
977
+ shySkhnCd: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shySkhnCd',
978
+ shySkhnNm: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo.shySkhnNm'
979
+ };
980
+ const aggregate = this.actionRecipeModel.aggregate([
981
+ { $unwind: '$step' },
982
+ { $unwind: '$step.itemListElement' },
983
+ { $unwind: '$step.itemListElement.itemListElement' },
984
+ { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut' },
985
+ { $unwind: '$step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo' },
986
+ { $match: filterQuery4recipe },
987
+ { $project: projectStage }
988
+ ]);
989
+ if (typeof filter.limit === 'number' && filter.limit > 0) {
990
+ const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
991
+ aggregate.limit(filter.limit * page)
992
+ .skip(filter.limit * (page - 1));
993
+ }
994
+ return aggregate
995
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
996
+ .exec();
1028
997
  }
1029
998
  /**
1030
999
  * 開始日時を一定期間過ぎたアクションを削除する
1031
1000
  */
1032
- deleteStartDatePassedCertainPeriod(params) {
1033
- return __awaiter(this, void 0, void 0, function* () {
1034
- return this.actionModel.deleteMany({
1035
- startDate: {
1036
- $lt: params.$lt
1037
- }
1038
- })
1039
- .exec();
1040
- });
1001
+ async deleteStartDatePassedCertainPeriod(params) {
1002
+ return this.actionModel.deleteMany({
1003
+ startDate: {
1004
+ $lt: params.$lt
1005
+ }
1006
+ })
1007
+ .exec();
1041
1008
  }
1042
1009
  /**
1043
1010
  * 終了日時を一定期間過ぎたアクションを削除する
1044
1011
  * 作成日時を一定期間過ぎたアクションレシピも削除する
1045
1012
  */
1046
- deleteEndDatePassedCertainPeriod(params) {
1047
- return __awaiter(this, void 0, void 0, function* () {
1048
- const { $lt } = params;
1049
- if ($lt instanceof Date) {
1050
- yield this.actionModel.deleteMany({
1051
- // 終了日時を一定期間過ぎたもの
1052
- endDate: { $exists: true, $lt }
1053
- })
1054
- .exec();
1055
- // clean actionRecipes(2025-01-10~)
1056
- const dateCreatedLt = moment($lt)
1057
- .add(-1, 'day') // レシピ作成とアクション終了の時間差を考慮
1058
- .toDate();
1059
- yield this.actionRecipeModel.deleteMany({
1060
- dateCreated: { $lt: dateCreatedLt }
1061
- })
1062
- .exec();
1063
- }
1064
- });
1013
+ async deleteEndDatePassedCertainPeriod(params) {
1014
+ const { $lt } = params;
1015
+ if ($lt instanceof Date) {
1016
+ await this.actionModel.deleteMany({
1017
+ // 終了日時を一定期間過ぎたもの
1018
+ endDate: { $exists: true, $lt }
1019
+ })
1020
+ .exec();
1021
+ // clean actionRecipes(2025-01-10~)
1022
+ const dateCreatedLt = moment($lt)
1023
+ .add(-1, 'day') // レシピ作成とアクション終了の時間差を考慮
1024
+ .toDate();
1025
+ await this.actionRecipeModel.deleteMany({
1026
+ dateCreated: { $lt: dateCreatedLt }
1027
+ })
1028
+ .exec();
1029
+ }
1065
1030
  }
1066
1031
  /**
1067
1032
  * 取引からアクションを削除する
1068
1033
  */
1069
- deleteByPurpose(params) {
1070
- return __awaiter(this, void 0, void 0, function* () {
1071
- return this.actionModel.deleteMany({
1072
- 'project.id': { $eq: params.project.id },
1073
- typeOf: { $in: params.typeOf.$in },
1074
- 'purpose.id': { $exists: true, $eq: params.purpose.id },
1075
- 'purpose.typeOf': { $exists: true, $eq: params.purpose.typeOf }
1076
- })
1077
- .exec()
1078
- .then((result) => {
1079
- return {
1080
- // n: result?.n,
1081
- // opTime: result.opTime,
1082
- // ok: result?.ok,
1083
- // operationTime,
1084
- deletedCount: result === null || result === void 0 ? void 0 : result.deletedCount
1085
- };
1086
- });
1034
+ async deleteByPurpose(params) {
1035
+ return this.actionModel.deleteMany({
1036
+ 'project.id': { $eq: params.project.id },
1037
+ typeOf: { $in: params.typeOf.$in },
1038
+ 'purpose.id': { $exists: true, $eq: params.purpose.id },
1039
+ 'purpose.typeOf': { $exists: true, $eq: params.purpose.typeOf }
1040
+ })
1041
+ .exec()
1042
+ .then((result) => {
1043
+ return {
1044
+ // n: result?.n,
1045
+ // opTime: result.opTime,
1046
+ // ok: result?.ok,
1047
+ // operationTime,
1048
+ deletedCount: result?.deletedCount
1049
+ };
1087
1050
  });
1088
1051
  }
1089
1052
  // public async saveRecipeWithDateCreated(savingRecipe: IRecipeAsDocument & {
@@ -1109,359 +1072,369 @@ class ActionRepo {
1109
1072
  // )
1110
1073
  // .exec();
1111
1074
  // }
1112
- saveActionWithEndDate(savingAction) {
1113
- return __awaiter(this, void 0, void 0, function* () {
1114
- const { sameAs, typeOf, project, agent, object } = savingAction, updateFields = __rest(savingAction, ["sameAs", "typeOf", "project", "agent", "object"]);
1115
- const filter = {
1116
- 'project.id': { $eq: project.id },
1117
- // 'agent.id': { $exists: true, $eq: agent.id },
1118
- // 'object.typeOf': { $exists: true, $eq: object.typeOf },
1119
- 'object.paymentMethodId': { $exists: true, $eq: object.paymentMethodId },
1120
- typeOf: { $eq: typeOf },
1121
- 'sameAs.id': { $exists: true, $eq: sameAs.id }
1122
- };
1123
- const setOnInsert = { typeOf, project, agent, object, sameAs };
1124
- const setKeys = updateFields;
1125
- const update = {
1126
- $setOnInsert: setOnInsert,
1127
- $set: setKeys
1128
- };
1129
- return this.actionModel.updateOne(filter, update, {
1130
- upsert: true,
1131
- includeResultMetadata: true
1132
- })
1133
- .exec();
1134
- });
1075
+ async saveActionWithEndDate(savingAction) {
1076
+ const { sameAs, typeOf, project, agent, object, ...updateFields } = savingAction;
1077
+ const filter = {
1078
+ 'project.id': { $eq: project.id },
1079
+ // 'agent.id': { $exists: true, $eq: agent.id },
1080
+ // 'object.typeOf': { $exists: true, $eq: object.typeOf },
1081
+ 'object.paymentMethodId': { $exists: true, $eq: object.paymentMethodId },
1082
+ typeOf: { $eq: typeOf },
1083
+ 'sameAs.id': { $exists: true, $eq: sameAs.id }
1084
+ };
1085
+ const setOnInsert = { typeOf, project, agent, object, sameAs };
1086
+ const setKeys = updateFields;
1087
+ const update = {
1088
+ $setOnInsert: setOnInsert,
1089
+ $set: setKeys
1090
+ };
1091
+ return this.actionModel.updateOne(filter, update, {
1092
+ upsert: true,
1093
+ includeResultMetadata: true
1094
+ })
1095
+ .exec();
1135
1096
  }
1136
- findRecipeByAction(params) {
1137
- return __awaiter(this, void 0, void 0, function* () {
1138
- return this.actionRecipeModel.findOne({
1139
- 'project.id': { $eq: params.project.id },
1140
- 'recipeFor.id': { $eq: params.recipeFor.id }
1141
- }, { step: 1, recipeCategory: 1 }
1142
- // { lean: true }
1143
- )
1144
- .lean()
1145
- .exec();
1146
- // if (result === null) {
1147
- // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
1148
- // }
1149
- // return result;
1150
- });
1097
+ async findRecipeByAction(params) {
1098
+ return this.actionRecipeModel.findOne({
1099
+ 'project.id': { $eq: params.project.id },
1100
+ 'recipeFor.id': { $eq: params.recipeFor.id }
1101
+ }, { step: 1, recipeCategory: 1 }
1102
+ // { lean: true }
1103
+ )
1104
+ .lean()
1105
+ .exec();
1106
+ // if (result === null) {
1107
+ // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
1108
+ // }
1109
+ // return result;
1151
1110
  }
1152
- findIMinimizedPurchaseNumberAuthResultByCheckMovieTicketRecipe(params) {
1153
- return __awaiter(this, void 0, void 0, function* () {
1154
- var _a, _b, _c;
1155
- const recipe = yield this.actionRecipeModel.findOne({
1156
- 'project.id': { $eq: params.project.id },
1157
- 'recipeFor.id': { $eq: params.recipeFor.id }
1158
- }, {
1159
- project: 0,
1160
- typeOf: 0,
1161
- recipeCategory: 0,
1162
- recipeFor: 0,
1163
- dateCreated: 0,
1164
- dateModified: 0,
1165
- 'step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo': 0,
1166
- 'step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo': 0
1167
- }, { lean: true })
1168
- .exec();
1169
- return (_c = (_b = (_a = recipe === null || recipe === void 0 ? void 0 : recipe.step[0]) === null || _a === void 0 ? void 0 : _a.itemListElement[0]) === null || _b === void 0 ? void 0 : _b.itemListElement[0]) === null || _c === void 0 ? void 0 : _c.afterMedia;
1170
- });
1111
+ async findIMinimizedPurchaseNumberAuthResultByCheckMovieTicketRecipe(params) {
1112
+ const recipe = await this.actionRecipeModel.findOne({
1113
+ 'project.id': { $eq: params.project.id },
1114
+ 'recipeFor.id': { $eq: params.recipeFor.id }
1115
+ }, {
1116
+ project: 0,
1117
+ typeOf: 0,
1118
+ recipeCategory: 0,
1119
+ recipeFor: 0,
1120
+ dateCreated: 0,
1121
+ dateModified: 0,
1122
+ 'step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.ykknInfo': 0,
1123
+ 'step.itemListElement.itemListElement.afterMedia.knyknrNoInfoOut.mkknInfo': 0
1124
+ }, { lean: true })
1125
+ .exec();
1126
+ return recipe?.step[0]?.itemListElement[0]?.itemListElement[0]?.afterMedia;
1171
1127
  }
1172
- aggregateAuthorizeEventServiceOfferAction(params) {
1173
- return __awaiter(this, void 0, void 0, function* () {
1174
- const statuses = yield Promise.all([
1175
- factory.actionStatusType.CompletedActionStatus,
1176
- factory.actionStatusType.CanceledActionStatus,
1177
- factory.actionStatusType.FailedActionStatus
1178
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1179
- var _a, _b;
1180
- const matchConditions = Object.assign({ startDate: {
1181
- $gte: params.startFrom,
1182
- $lte: params.startThrough
1183
- }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
1184
- $exists: true,
1185
- $eq: factory.action.authorize.offer.eventService.ObjectType.SeatReservation
1186
- } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1128
+ async aggregateAuthorizeEventServiceOfferAction(params) {
1129
+ const statuses = await Promise.all([
1130
+ factory.actionStatusType.CompletedActionStatus,
1131
+ factory.actionStatusType.CanceledActionStatus,
1132
+ factory.actionStatusType.FailedActionStatus
1133
+ ].map(async (actionStatus) => {
1134
+ const matchConditions = {
1135
+ startDate: {
1136
+ $gte: params.startFrom,
1137
+ $lte: params.startThrough
1138
+ },
1139
+ typeOf: { $eq: params.typeOf },
1140
+ actionStatus: { $eq: actionStatus },
1141
+ 'object.typeOf': {
1142
+ $exists: true,
1143
+ $eq: factory.action.authorize.offer.eventService.ObjectType.SeatReservation
1144
+ },
1145
+ ...(typeof params.project?.id?.$ne === 'string')
1187
1146
  ? { 'project.id': { $ne: params.project.id.$ne } }
1188
- : undefined);
1189
- return this.agggregateByStatus({ matchConditions, actionStatus });
1190
- })));
1191
- return { statuses };
1192
- });
1147
+ : undefined
1148
+ };
1149
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1150
+ }));
1151
+ return { statuses };
1193
1152
  }
1194
- aggregateAuthorizePaymentAction(params) {
1195
- return __awaiter(this, void 0, void 0, function* () {
1196
- const statuses = yield Promise.all([
1197
- factory.actionStatusType.CompletedActionStatus,
1198
- factory.actionStatusType.CanceledActionStatus,
1199
- factory.actionStatusType.FailedActionStatus
1200
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1201
- var _a, _b;
1202
- const matchConditions = Object.assign({ startDate: {
1203
- $gte: params.startFrom,
1204
- $lte: params.startThrough
1205
- }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
1206
- $exists: true,
1207
- $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
1208
- } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1153
+ async aggregateAuthorizePaymentAction(params) {
1154
+ const statuses = await Promise.all([
1155
+ factory.actionStatusType.CompletedActionStatus,
1156
+ factory.actionStatusType.CanceledActionStatus,
1157
+ factory.actionStatusType.FailedActionStatus
1158
+ ].map(async (actionStatus) => {
1159
+ const matchConditions = {
1160
+ startDate: {
1161
+ $gte: params.startFrom,
1162
+ $lte: params.startThrough
1163
+ },
1164
+ typeOf: { $eq: params.typeOf },
1165
+ actionStatus: { $eq: actionStatus },
1166
+ 'object.typeOf': {
1167
+ $exists: true,
1168
+ $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
1169
+ },
1170
+ ...(typeof params.project?.id?.$ne === 'string')
1209
1171
  ? { 'project.id': { $ne: params.project.id.$ne } }
1210
- : undefined);
1211
- return this.agggregateByStatus({ matchConditions, actionStatus });
1212
- })));
1213
- return { statuses };
1214
- });
1172
+ : undefined
1173
+ };
1174
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1175
+ }));
1176
+ return { statuses };
1215
1177
  }
1216
- aggregateAuthorizeOrderAction(params) {
1217
- return __awaiter(this, void 0, void 0, function* () {
1218
- const statuses = yield Promise.all([
1219
- factory.actionStatusType.CompletedActionStatus,
1220
- factory.actionStatusType.CanceledActionStatus,
1221
- factory.actionStatusType.FailedActionStatus
1222
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1223
- var _a, _b;
1224
- const matchConditions = Object.assign({ startDate: {
1225
- $gte: params.startFrom,
1226
- $lte: params.startThrough
1227
- }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
1228
- $exists: true,
1229
- $eq: factory.order.OrderType.Order
1230
- } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1178
+ async aggregateAuthorizeOrderAction(params) {
1179
+ const statuses = await Promise.all([
1180
+ factory.actionStatusType.CompletedActionStatus,
1181
+ factory.actionStatusType.CanceledActionStatus,
1182
+ factory.actionStatusType.FailedActionStatus
1183
+ ].map(async (actionStatus) => {
1184
+ const matchConditions = {
1185
+ startDate: {
1186
+ $gte: params.startFrom,
1187
+ $lte: params.startThrough
1188
+ },
1189
+ typeOf: { $eq: params.typeOf },
1190
+ actionStatus: { $eq: actionStatus },
1191
+ 'object.typeOf': {
1192
+ $exists: true,
1193
+ $eq: factory.order.OrderType.Order
1194
+ },
1195
+ ...(typeof params.project?.id?.$ne === 'string')
1231
1196
  ? { 'project.id': { $ne: params.project.id.$ne } }
1232
- : undefined);
1233
- return this.agggregateByStatus({ matchConditions, actionStatus });
1234
- })));
1235
- return { statuses };
1236
- });
1197
+ : undefined
1198
+ };
1199
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1200
+ }));
1201
+ return { statuses };
1237
1202
  }
1238
- aggregateCancelReservationAction(params) {
1239
- return __awaiter(this, void 0, void 0, function* () {
1240
- const statuses = yield Promise.all([
1241
- factory.actionStatusType.CompletedActionStatus,
1242
- factory.actionStatusType.CanceledActionStatus,
1243
- factory.actionStatusType.FailedActionStatus
1244
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1245
- var _a, _b;
1246
- const matchConditions = Object.assign({ startDate: {
1247
- $gte: params.startFrom,
1248
- $lte: params.startThrough
1249
- }, typeOf: { $eq: factory.actionType.CancelAction }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
1250
- $exists: true,
1251
- $in: [
1252
- factory.reservationType.BusReservation,
1253
- factory.reservationType.EventReservation,
1254
- factory.reservationType.ReservationPackage
1255
- ]
1256
- } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1203
+ async aggregateCancelReservationAction(params) {
1204
+ const statuses = await Promise.all([
1205
+ factory.actionStatusType.CompletedActionStatus,
1206
+ factory.actionStatusType.CanceledActionStatus,
1207
+ factory.actionStatusType.FailedActionStatus
1208
+ ].map(async (actionStatus) => {
1209
+ const matchConditions = {
1210
+ startDate: {
1211
+ $gte: params.startFrom,
1212
+ $lte: params.startThrough
1213
+ },
1214
+ typeOf: { $eq: factory.actionType.CancelAction },
1215
+ actionStatus: { $eq: actionStatus },
1216
+ 'object.typeOf': {
1217
+ $exists: true,
1218
+ $in: [
1219
+ factory.reservationType.BusReservation,
1220
+ factory.reservationType.EventReservation,
1221
+ factory.reservationType.ReservationPackage
1222
+ ]
1223
+ },
1224
+ ...(typeof params.project?.id?.$ne === 'string')
1257
1225
  ? { 'project.id': { $ne: params.project.id.$ne } }
1258
- : undefined);
1259
- return this.agggregateByStatus({ matchConditions, actionStatus });
1260
- })));
1261
- return { statuses };
1262
- });
1226
+ : undefined
1227
+ };
1228
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1229
+ }));
1230
+ return { statuses };
1263
1231
  }
1264
1232
  /**
1265
1233
  * アクションタイプによる汎用的な集計
1266
1234
  */
1267
- aggregateByTypeOf(params) {
1268
- return __awaiter(this, void 0, void 0, function* () {
1269
- const statuses = yield Promise.all([
1270
- factory.actionStatusType.CompletedActionStatus,
1271
- factory.actionStatusType.CanceledActionStatus,
1272
- factory.actionStatusType.FailedActionStatus
1273
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1274
- var _a, _b;
1275
- const matchConditions = Object.assign({ startDate: {
1276
- $gte: params.startFrom,
1277
- $lte: params.startThrough
1278
- }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1235
+ async aggregateByTypeOf(params) {
1236
+ const statuses = await Promise.all([
1237
+ factory.actionStatusType.CompletedActionStatus,
1238
+ factory.actionStatusType.CanceledActionStatus,
1239
+ factory.actionStatusType.FailedActionStatus
1240
+ ].map(async (actionStatus) => {
1241
+ const matchConditions = {
1242
+ startDate: {
1243
+ $gte: params.startFrom,
1244
+ $lte: params.startThrough
1245
+ },
1246
+ typeOf: { $eq: params.typeOf },
1247
+ actionStatus: { $eq: actionStatus },
1248
+ ...(typeof params.project?.id?.$ne === 'string')
1279
1249
  ? { 'project.id': { $ne: params.project.id.$ne } }
1280
- : undefined);
1281
- return this.agggregateByStatus({ matchConditions, actionStatus });
1282
- })));
1283
- return { statuses };
1284
- });
1250
+ : undefined
1251
+ };
1252
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1253
+ }));
1254
+ return { statuses };
1285
1255
  }
1286
- aggregateCheckMovieTicketAction(params) {
1287
- return __awaiter(this, void 0, void 0, function* () {
1288
- const statuses = yield Promise.all([
1289
- factory.actionStatusType.CompletedActionStatus,
1290
- factory.actionStatusType.CanceledActionStatus,
1291
- factory.actionStatusType.FailedActionStatus
1292
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1293
- var _a, _b;
1294
- const matchConditions = Object.assign({ startDate: {
1295
- $gte: params.startFrom,
1296
- $lte: params.startThrough
1297
- }, typeOf: { $eq: factory.actionType.CheckAction }, 'object.typeOf': {
1298
- $exists: true,
1299
- $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
1300
- }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1256
+ async aggregateCheckMovieTicketAction(params) {
1257
+ const statuses = await Promise.all([
1258
+ factory.actionStatusType.CompletedActionStatus,
1259
+ factory.actionStatusType.CanceledActionStatus,
1260
+ factory.actionStatusType.FailedActionStatus
1261
+ ].map(async (actionStatus) => {
1262
+ const matchConditions = {
1263
+ startDate: {
1264
+ $gte: params.startFrom,
1265
+ $lte: params.startThrough
1266
+ },
1267
+ typeOf: { $eq: factory.actionType.CheckAction },
1268
+ 'object.typeOf': {
1269
+ $exists: true,
1270
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
1271
+ },
1272
+ actionStatus: { $eq: actionStatus },
1273
+ ...(typeof params.project?.id?.$ne === 'string')
1301
1274
  ? { 'project.id': { $ne: params.project.id.$ne } }
1302
- : undefined);
1303
- return this.agggregateByStatus({ matchConditions, actionStatus });
1304
- })));
1305
- return { statuses };
1306
- });
1275
+ : undefined
1276
+ };
1277
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1278
+ }));
1279
+ return { statuses };
1307
1280
  }
1308
- aggregatePayMovieTicketAction(params) {
1309
- return __awaiter(this, void 0, void 0, function* () {
1310
- const statuses = yield Promise.all([
1311
- factory.actionStatusType.CompletedActionStatus,
1312
- factory.actionStatusType.CanceledActionStatus,
1313
- factory.actionStatusType.FailedActionStatus
1314
- ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
1315
- var _a, _b;
1316
- const matchConditions = Object.assign({ startDate: {
1317
- $gte: params.startFrom,
1318
- $lte: params.startThrough
1319
- }, typeOf: { $eq: factory.actionType.PayAction }, 'object.typeOf': {
1320
- $exists: true,
1321
- $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
1322
- }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
1281
+ async aggregatePayMovieTicketAction(params) {
1282
+ const statuses = await Promise.all([
1283
+ factory.actionStatusType.CompletedActionStatus,
1284
+ factory.actionStatusType.CanceledActionStatus,
1285
+ factory.actionStatusType.FailedActionStatus
1286
+ ].map(async (actionStatus) => {
1287
+ const matchConditions = {
1288
+ startDate: {
1289
+ $gte: params.startFrom,
1290
+ $lte: params.startThrough
1291
+ },
1292
+ typeOf: { $eq: factory.actionType.PayAction },
1293
+ 'object.typeOf': {
1294
+ $exists: true,
1295
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
1296
+ },
1297
+ actionStatus: { $eq: actionStatus },
1298
+ ...(typeof params.project?.id?.$ne === 'string')
1323
1299
  ? { 'project.id': { $ne: params.project.id.$ne } }
1324
- : undefined);
1325
- return this.agggregateByStatus({ matchConditions, actionStatus });
1326
- })));
1327
- return { statuses };
1328
- });
1300
+ : undefined
1301
+ };
1302
+ return this.agggregateByStatus({ matchConditions, actionStatus });
1303
+ }));
1304
+ return { statuses };
1329
1305
  }
1330
1306
  getCursor(conditions, projection) {
1331
1307
  return this.actionModel.find(conditions, projection)
1332
1308
  .sort({ startDate: factory.sortType.Descending })
1333
1309
  .cursor();
1334
1310
  }
1335
- unsetUnnecessaryFields(params) {
1336
- return __awaiter(this, void 0, void 0, function* () {
1337
- return this.actionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
1338
- .exec();
1339
- });
1311
+ async unsetUnnecessaryFields(params) {
1312
+ return this.actionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
1313
+ .exec();
1340
1314
  }
1341
1315
  // tslint:disable-next-line:max-func-body-length
1342
- agggregateByStatus(params) {
1343
- return __awaiter(this, void 0, void 0, function* () {
1344
- const aggregations = yield this.actionModel.aggregate([
1345
- { $match: params.matchConditions },
1346
- {
1347
- $project: {
1348
- duration: { $subtract: ['$endDate', '$startDate'] },
1349
- actionStatus: '$actionStatus',
1350
- startDate: '$startDate',
1351
- endDate: '$endDate',
1352
- typeOf: '$typeOf'
1353
- }
1354
- },
1355
- {
1356
- $group: {
1357
- _id: '$typeOf',
1358
- actionCount: { $sum: 1 },
1359
- maxDuration: { $max: '$duration' },
1360
- minDuration: { $min: '$duration' },
1361
- avgDuration: { $avg: '$duration' }
1362
- }
1363
- },
1364
- {
1365
- $project: {
1366
- _id: 0,
1367
- actionCount: '$actionCount',
1368
- avgDuration: '$avgDuration',
1369
- maxDuration: '$maxDuration',
1370
- minDuration: '$minDuration'
1371
- }
1316
+ async agggregateByStatus(params) {
1317
+ const aggregations = await this.actionModel.aggregate([
1318
+ { $match: params.matchConditions },
1319
+ {
1320
+ $project: {
1321
+ duration: { $subtract: ['$endDate', '$startDate'] },
1322
+ actionStatus: '$actionStatus',
1323
+ startDate: '$startDate',
1324
+ endDate: '$endDate',
1325
+ typeOf: '$typeOf'
1372
1326
  }
1373
- ])
1374
- .exec();
1375
- // tslint:disable-next-line:no-magic-numbers
1376
- const percents = [50, 95, 99];
1377
- if (aggregations.length === 0) {
1378
- return {
1379
- status: params.actionStatus,
1380
- aggregation: {
1381
- actionCount: 0,
1382
- avgDuration: 0,
1383
- maxDuration: 0,
1384
- minDuration: 0,
1385
- percentilesDuration: percents.map((percent) => {
1386
- return {
1387
- name: String(percent),
1388
- value: 0
1389
- };
1390
- })
1391
- }
1392
- };
1393
- }
1394
- const ranks4percentile = percents.map((percentile) => {
1395
- return {
1396
- percentile,
1397
- // tslint:disable-next-line:no-magic-numbers
1398
- rank: Math.floor(aggregations[0].actionCount * percentile / 100)
1399
- };
1400
- });
1401
- const aggregations2 = yield this.actionModel.aggregate([
1402
- {
1403
- $match: params.matchConditions
1404
- },
1405
- {
1406
- $project: {
1407
- duration: { $subtract: ['$endDate', '$startDate'] },
1408
- actionStatus: '$actionStatus',
1409
- startDate: '$startDate',
1410
- endDate: '$endDate',
1411
- typeOf: '$typeOf'
1412
- }
1413
- },
1414
- { $sort: { duration: 1 } },
1415
- {
1416
- $group: {
1417
- _id: '$typeOf',
1418
- durations: { $push: '$duration' }
1419
- }
1420
- },
1421
- {
1422
- $project: {
1423
- _id: 0,
1424
- avgSmallDuration: '$avgSmallDuration',
1425
- avgMediumDuration: '$avgMediumDuration',
1426
- avgLargeDuration: '$avgLargeDuration',
1427
- percentilesDuration: ranks4percentile.map((rank) => {
1428
- return {
1429
- name: String(rank.percentile),
1430
- value: { $arrayElemAt: ['$durations', rank.rank] }
1431
- };
1432
- })
1433
- }
1327
+ },
1328
+ {
1329
+ $group: {
1330
+ _id: '$typeOf',
1331
+ actionCount: { $sum: 1 },
1332
+ maxDuration: { $max: '$duration' },
1333
+ minDuration: { $min: '$duration' },
1334
+ avgDuration: { $avg: '$duration' }
1434
1335
  }
1435
- ])
1436
- .exec();
1336
+ },
1337
+ {
1338
+ $project: {
1339
+ _id: 0,
1340
+ actionCount: '$actionCount',
1341
+ avgDuration: '$avgDuration',
1342
+ maxDuration: '$maxDuration',
1343
+ minDuration: '$minDuration'
1344
+ }
1345
+ }
1346
+ ])
1347
+ .exec();
1348
+ // tslint:disable-next-line:no-magic-numbers
1349
+ const percents = [50, 95, 99];
1350
+ if (aggregations.length === 0) {
1437
1351
  return {
1438
1352
  status: params.actionStatus,
1439
- aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
1440
- };
1441
- });
1442
- }
1443
- upsertRecipe(savingRecipe) {
1444
- return __awaiter(this, void 0, void 0, function* () {
1445
- const dateModified = new Date();
1446
- const { typeOf, project, recipeCategory, recipeFor, step } = savingRecipe;
1447
- const filter = {
1448
- 'recipeFor.id': { $eq: recipeFor.id }
1449
- };
1450
- const setOnInsert = {
1451
- project, typeOf, recipeCategory, recipeFor,
1452
- dateCreated: dateModified
1353
+ aggregation: {
1354
+ actionCount: 0,
1355
+ avgDuration: 0,
1356
+ maxDuration: 0,
1357
+ minDuration: 0,
1358
+ percentilesDuration: percents.map((percent) => {
1359
+ return {
1360
+ name: String(percent),
1361
+ value: 0
1362
+ };
1363
+ })
1364
+ }
1453
1365
  };
1454
- const setKeys = { step, dateModified };
1455
- const update = {
1456
- $setOnInsert: setOnInsert,
1457
- $set: setKeys
1366
+ }
1367
+ const ranks4percentile = percents.map((percentile) => {
1368
+ return {
1369
+ percentile,
1370
+ // tslint:disable-next-line:no-magic-numbers
1371
+ rank: Math.floor(aggregations[0].actionCount * percentile / 100)
1458
1372
  };
1459
- return this.actionRecipeModel.updateOne(filter, update, {
1460
- upsert: true,
1461
- includeResultMetadata: true
1462
- })
1463
- .exec();
1464
1373
  });
1374
+ const aggregations2 = await this.actionModel.aggregate([
1375
+ {
1376
+ $match: params.matchConditions
1377
+ },
1378
+ {
1379
+ $project: {
1380
+ duration: { $subtract: ['$endDate', '$startDate'] },
1381
+ actionStatus: '$actionStatus',
1382
+ startDate: '$startDate',
1383
+ endDate: '$endDate',
1384
+ typeOf: '$typeOf'
1385
+ }
1386
+ },
1387
+ { $sort: { duration: 1 } },
1388
+ {
1389
+ $group: {
1390
+ _id: '$typeOf',
1391
+ durations: { $push: '$duration' }
1392
+ }
1393
+ },
1394
+ {
1395
+ $project: {
1396
+ _id: 0,
1397
+ avgSmallDuration: '$avgSmallDuration',
1398
+ avgMediumDuration: '$avgMediumDuration',
1399
+ avgLargeDuration: '$avgLargeDuration',
1400
+ percentilesDuration: ranks4percentile.map((rank) => {
1401
+ return {
1402
+ name: String(rank.percentile),
1403
+ value: { $arrayElemAt: ['$durations', rank.rank] }
1404
+ };
1405
+ })
1406
+ }
1407
+ }
1408
+ ])
1409
+ .exec();
1410
+ return {
1411
+ status: params.actionStatus,
1412
+ aggregation: {
1413
+ ...aggregations[0],
1414
+ ...aggregations2[0]
1415
+ }
1416
+ };
1417
+ }
1418
+ async upsertRecipe(savingRecipe) {
1419
+ const dateModified = new Date();
1420
+ const { typeOf, project, recipeCategory, recipeFor, step } = savingRecipe;
1421
+ const filter = {
1422
+ 'recipeFor.id': { $eq: recipeFor.id }
1423
+ };
1424
+ const setOnInsert = {
1425
+ project, typeOf, recipeCategory, recipeFor,
1426
+ dateCreated: dateModified
1427
+ };
1428
+ const setKeys = { step, dateModified };
1429
+ const update = {
1430
+ $setOnInsert: setOnInsert,
1431
+ $set: setKeys
1432
+ };
1433
+ return this.actionRecipeModel.updateOne(filter, update, {
1434
+ upsert: true,
1435
+ includeResultMetadata: true
1436
+ })
1437
+ .exec();
1465
1438
  }
1466
1439
  }
1467
1440
  exports.ActionRepo = ActionRepo;