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

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