@chevre/domain 22.9.0-alpha.10 → 22.9.0-alpha.100

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 (306) hide show
  1. package/example/src/chevre/aggregation/aggregateOrderOfCustomer.ts +124 -0
  2. package/example/src/chevre/aggregation/aggregateOrderOfSeatByRoyalCustomers.ts +172 -0
  3. package/example/src/chevre/checkPaymentServiceUniqueness.ts +79 -0
  4. package/example/src/chevre/countPotentiallyExportTasks.ts +42 -0
  5. package/example/src/chevre/countTransactions.ts +30 -0
  6. package/example/src/chevre/createTaskIfNotExistByAlternateName.ts +57 -0
  7. package/example/src/chevre/deleteRunsAtPassedCertainPeriod.ts +23 -9
  8. package/example/src/chevre/executeOneTask.ts +41 -0
  9. package/example/src/chevre/{aggregateAllEvents2.ts → executeTaskIfExists.ts} +19 -10
  10. package/example/src/chevre/findExecutableTask.ts +50 -0
  11. package/example/src/chevre/investigateEvents.ts +86 -0
  12. package/example/src/chevre/investigateTransaction.ts +31 -19
  13. package/example/src/chevre/makeExpiredManyTasks.ts +27 -0
  14. package/example/src/chevre/makeTransactionExpired.ts +28 -0
  15. package/example/src/chevre/migrateIdentities.ts +82 -0
  16. package/example/src/chevre/notifyAbortedTasksByEmail.ts +56 -0
  17. package/example/src/chevre/notifyByEmail.ts +43 -0
  18. package/example/src/chevre/publishConfimationNumber.ts +27 -0
  19. package/example/src/chevre/reExportAction.ts +40 -0
  20. package/example/src/chevre/reIndex.ts +1 -2
  21. package/example/src/chevre/recreateRefundTasks.ts +187 -0
  22. package/example/src/chevre/saveWebSite.ts +59 -0
  23. package/example/src/chevre/searchAuthorizations.ts +4 -3
  24. package/example/src/chevre/searchPaymentServices.ts +1 -1
  25. package/example/src/chevre/sendEmailMessage.ts +60 -0
  26. package/example/src/chevre/sendGrid/filterEmailActivity.ts +2 -4
  27. package/example/src/chevre/stockHolder/getSize.ts +70 -0
  28. package/example/src/chevre/stockHolder/playAroundStockHolder.ts +247 -0
  29. package/example/src/chevre/transaction/startExportTasks.ts +4 -3
  30. package/example/src/chevre/unsetUnnecessaryFields.ts +4 -8
  31. package/example/src/moment.ts +19 -18
  32. package/example/src/mongoConnectionList.ts +81 -0
  33. package/example/src/redisClientList.ts +80 -0
  34. package/lib/chevre/credentials/sendGrid.d.ts +13 -0
  35. package/lib/chevre/credentials/sendGrid.js +4 -1
  36. package/lib/chevre/eventEmitter/task.d.ts +2 -1
  37. package/lib/chevre/repo/action.d.ts +13 -98
  38. package/lib/chevre/repo/action.js +54 -41
  39. package/lib/chevre/repo/advanceBookingRequirement.d.ts +37 -0
  40. package/lib/chevre/repo/advanceBookingRequirement.js +130 -0
  41. package/lib/chevre/repo/aggregateOffer.d.ts +2 -14
  42. package/lib/chevre/repo/aggregateOffer.js +94 -124
  43. package/lib/chevre/repo/aggregateOrder.d.ts +38 -0
  44. package/lib/chevre/repo/aggregateOrder.js +173 -0
  45. package/lib/chevre/repo/assetTransaction.d.ts +53 -11
  46. package/lib/chevre/repo/assetTransaction.js +209 -54
  47. package/lib/chevre/repo/authorization.d.ts +2 -1
  48. package/lib/chevre/repo/authorization.js +25 -19
  49. package/lib/chevre/repo/identity.d.ts +5 -5
  50. package/lib/chevre/repo/identityProvider.d.ts +27 -2
  51. package/lib/chevre/repo/identityProvider.js +11 -4
  52. package/lib/chevre/repo/mongoose/schemas/action.d.ts +3 -1
  53. package/lib/chevre/repo/mongoose/schemas/action.js +41 -1
  54. package/lib/chevre/repo/mongoose/schemas/advanceBookingRequirement.d.ts +10 -0
  55. package/lib/chevre/repo/mongoose/schemas/advanceBookingRequirement.js +84 -0
  56. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +9 -3
  57. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.d.ts +23 -0
  58. package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +78 -0
  59. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +22 -2
  60. package/lib/chevre/repo/mongoose/schemas/authorization.js +9 -0
  61. package/lib/chevre/repo/mongoose/schemas/identity.d.ts +1 -1
  62. package/lib/chevre/repo/mongoose/schemas/identityProvider.js +0 -4
  63. package/lib/chevre/repo/mongoose/schemas/paymentService.js +16 -0
  64. package/lib/chevre/repo/mongoose/schemas/paymentServiceChannel.js +1 -2
  65. package/lib/chevre/repo/mongoose/schemas/pendingReservation.d.ts +29 -0
  66. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +106 -0
  67. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.d.ts +24 -0
  68. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.js +100 -0
  69. package/lib/chevre/repo/mongoose/schemas/{interface.d.ts → reserveInterface.d.ts} +1 -1
  70. package/lib/chevre/repo/mongoose/schemas/{interface.js → reserveInterface.js} +2 -2
  71. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
  72. package/lib/chevre/repo/mongoose/schemas/setting.js +8 -2
  73. package/lib/chevre/repo/mongoose/schemas/task.js +53 -9
  74. package/lib/chevre/repo/mongoose/schemas/transaction.js +19 -0
  75. package/lib/chevre/repo/mongoose/schemas/webSite.d.ts +10 -0
  76. package/lib/chevre/repo/mongoose/schemas/webSite.js +69 -0
  77. package/lib/chevre/repo/offer.d.ts +1 -3
  78. package/lib/chevre/repo/offer.js +6 -387
  79. package/lib/chevre/repo/order.d.ts +61 -0
  80. package/lib/chevre/repo/order.js +181 -31
  81. package/lib/chevre/repo/paymentService.d.ts +4 -3
  82. package/lib/chevre/repo/paymentService.js +87 -28
  83. package/lib/chevre/repo/paymentServiceChannel.d.ts +5 -1
  84. package/lib/chevre/repo/paymentServiceChannel.js +6 -5
  85. package/lib/chevre/repo/pendingReservation.d.ts +47 -0
  86. package/lib/chevre/repo/pendingReservation.js +397 -0
  87. package/lib/chevre/repo/pendingReservation2.d.ts +35 -0
  88. package/lib/chevre/repo/pendingReservation2.js +201 -0
  89. package/lib/chevre/repo/potentialAction.d.ts +30 -1
  90. package/lib/chevre/repo/potentialAction.js +8 -1
  91. package/lib/chevre/repo/{interface.d.ts → reserveInterface.d.ts} +3 -4
  92. package/lib/chevre/repo/{interface.js → reserveInterface.js} +11 -13
  93. package/lib/chevre/repo/seller.d.ts +16 -16
  94. package/lib/chevre/repo/stockHolder.d.ts +10 -84
  95. package/lib/chevre/repo/stockHolder.js +64 -22
  96. package/lib/chevre/repo/stockHolderAbstract.d.ts +74 -0
  97. package/lib/chevre/repo/stockHolderAbstract.js +9 -0
  98. package/lib/chevre/repo/task.d.ts +107 -31
  99. package/lib/chevre/repo/task.js +376 -156
  100. package/lib/chevre/repo/transaction.d.ts +56 -12
  101. package/lib/chevre/repo/transaction.js +218 -53
  102. package/lib/chevre/repo/webSite.d.ts +45 -0
  103. package/lib/chevre/repo/webSite.js +165 -0
  104. package/lib/chevre/repository.d.ts +20 -5
  105. package/lib/chevre/repository.js +54 -15
  106. package/lib/chevre/service/assetTransaction/cancelReservation/factory.d.ts +3 -1
  107. package/lib/chevre/service/assetTransaction/cancelReservation/factory.js +51 -59
  108. package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +28 -0
  109. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +106 -0
  110. package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.d.ts +6 -0
  111. package/lib/chevre/service/assetTransaction/cancelReservation/startAndConfirm.js +52 -0
  112. package/lib/chevre/service/assetTransaction/cancelReservation.d.ts +6 -23
  113. package/lib/chevre/service/assetTransaction/cancelReservation.js +5 -130
  114. package/lib/chevre/service/assetTransaction/fixInformAction.d.ts +6 -1
  115. package/lib/chevre/service/assetTransaction/fixInformAction.js +18 -10
  116. package/lib/chevre/service/assetTransaction/pay/factory.d.ts +7 -1
  117. package/lib/chevre/service/assetTransaction/pay/factory.js +13 -3
  118. package/lib/chevre/service/assetTransaction/pay.d.ts +10 -20
  119. package/lib/chevre/service/assetTransaction/pay.js +12 -39
  120. package/lib/chevre/service/assetTransaction/refund/factory.d.ts +6 -1
  121. package/lib/chevre/service/assetTransaction/refund/factory.js +13 -11
  122. package/lib/chevre/service/assetTransaction/refund/potentialActions.d.ts +1 -1
  123. package/lib/chevre/service/assetTransaction/refund/potentialActions.js +37 -33
  124. package/lib/chevre/service/assetTransaction/refund.js +2 -1
  125. package/lib/chevre/service/assetTransaction/reserve/confirm.d.ts +2 -0
  126. package/lib/chevre/service/assetTransaction/reserve/exportTasksById.d.ts +1 -2
  127. package/lib/chevre/service/assetTransaction/reserve/exportTasksById.js +1 -3
  128. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.d.ts +2 -0
  129. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +58 -14
  130. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.d.ts +1 -0
  131. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +3 -2
  132. package/lib/chevre/service/assetTransaction/reserve/start.d.ts +6 -0
  133. package/lib/chevre/service/assetTransaction/reserve/start.js +15 -6
  134. package/lib/chevre/service/assetTransaction/reserveCOA/cancel.d.ts +26 -0
  135. package/lib/chevre/service/assetTransaction/reserveCOA/cancel.js +112 -0
  136. package/lib/chevre/service/assetTransaction.d.ts +11 -12
  137. package/lib/chevre/service/assetTransaction.js +23 -18
  138. package/lib/chevre/service/notification/factory.d.ts +8 -0
  139. package/lib/chevre/service/notification/factory.js +25 -3
  140. package/lib/chevre/service/notification/notifyByEmail.d.ts +12 -0
  141. package/lib/chevre/service/notification/notifyByEmail.js +93 -0
  142. package/lib/chevre/service/notification/sendEmailMessage.d.ts +20 -0
  143. package/lib/chevre/service/notification/sendEmailMessage.js +136 -0
  144. package/lib/chevre/service/notification/triggerWebhook.d.ts +14 -0
  145. package/lib/chevre/service/notification/triggerWebhook.js +213 -0
  146. package/lib/chevre/service/notification.d.ts +4 -42
  147. package/lib/chevre/service/notification.js +7 -339
  148. package/lib/chevre/service/offer/any.d.ts +1 -9
  149. package/lib/chevre/service/offer/any.js +1 -8
  150. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +3 -0
  151. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +4 -1
  152. package/lib/chevre/service/offer/event/authorize.d.ts +2 -0
  153. package/lib/chevre/service/offer/event/authorize.js +10 -3
  154. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.d.ts +14 -0
  155. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +5 -89
  156. package/lib/chevre/service/offer/event/voidTransaction.d.ts +3 -0
  157. package/lib/chevre/service/offer/event/voidTransaction.js +8 -6
  158. package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +3 -0
  159. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +5 -3
  160. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +4 -0
  161. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +12 -0
  162. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +0 -4
  163. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +13 -1
  164. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -1
  165. package/lib/chevre/service/offer/moneyTransfer/authorize.js +9 -2
  166. package/lib/chevre/service/offer/onEventChanged.js +16 -7
  167. package/lib/chevre/service/offer/product.js +1 -1
  168. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  169. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +2 -2
  170. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +1 -1
  171. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +31 -23
  172. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +31 -23
  173. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +7 -5
  174. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -1
  175. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +9 -3
  176. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +56 -37
  177. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +6 -3
  178. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +7 -7
  179. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +31 -23
  180. package/lib/chevre/service/order/onOrderUpdated/factory.js +30 -23
  181. package/lib/chevre/service/payment/any/factory.d.ts +20 -14
  182. package/lib/chevre/service/payment/any/factory.js +47 -16
  183. package/lib/chevre/service/payment/any/fixOrderAsNeeded.d.ts +20 -0
  184. package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +41 -0
  185. package/lib/chevre/service/payment/any/{onPaid.d.ts → onPayActionCompleted.d.ts} +2 -5
  186. package/lib/chevre/service/payment/any/{onPaid.js → onPayActionCompleted.js} +35 -10
  187. package/lib/chevre/service/payment/any/onPaymentStatusChanged.d.ts +2 -2
  188. package/lib/chevre/service/payment/any/{onRefund.d.ts → onRefundActionCompletedOrFailed.d.ts} +4 -2
  189. package/lib/chevre/service/payment/any/{onRefund.js → onRefundActionCompletedOrFailed.js} +48 -29
  190. package/lib/chevre/service/payment/any.d.ts +19 -7
  191. package/lib/chevre/service/payment/any.js +180 -89
  192. package/lib/chevre/service/payment/creditCard/authorize.js +4 -2
  193. package/lib/chevre/service/payment/creditCard/factory.d.ts +1 -0
  194. package/lib/chevre/service/payment/creditCard/factory.js +2 -2
  195. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.d.ts +1 -0
  196. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +8 -6
  197. package/lib/chevre/service/payment/creditCard/gmoError.d.ts +8 -1
  198. package/lib/chevre/service/payment/creditCard/gmoError.js +7 -0
  199. package/lib/chevre/service/payment/creditCard/payCreditCard.js +8 -4
  200. package/lib/chevre/service/payment/creditCard/refundCreditCard.d.ts +3 -4
  201. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +118 -64
  202. package/lib/chevre/service/payment/creditCard/voidTransaction.js +4 -2
  203. package/lib/chevre/service/payment/faceToFace.js +5 -5
  204. package/lib/chevre/service/payment/factory.d.ts +1 -1
  205. package/lib/chevre/service/payment/factory.js +32 -37
  206. package/lib/chevre/service/payment/movieTicket/authorize.js +35 -17
  207. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  208. package/lib/chevre/service/payment/movieTicket/factory.js +9 -13
  209. package/lib/chevre/service/payment/movieTicket/payMovieTicket.d.ts +5 -1
  210. package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +14 -12
  211. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.d.ts +4 -1
  212. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +16 -17
  213. package/lib/chevre/service/payment/movieTicket/voidTransaction.js +7 -2
  214. package/lib/chevre/service/payment/paymentCard.js +5 -6
  215. package/lib/chevre/service/report/telemetry.js +6 -3
  216. package/lib/chevre/service/reserve/cancelReservation.d.ts +1 -1
  217. package/lib/chevre/service/reserve/cancelReservation.js +17 -23
  218. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  219. package/lib/chevre/service/reserve/checkInReservation.js +41 -26
  220. package/lib/chevre/service/reserve/confirmReservation.d.ts +2 -5
  221. package/lib/chevre/service/reserve/confirmReservation.js +4 -11
  222. package/lib/chevre/service/reserve/factory.d.ts +1 -3
  223. package/lib/chevre/service/reserve/factory.js +11 -7
  224. package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.d.ts +2 -0
  225. package/lib/chevre/service/reserve/potentialActions/onPendingReservationCanceled.js +23 -11
  226. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +1 -1
  227. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +23 -10
  228. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +3 -0
  229. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +17 -9
  230. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +3 -1
  231. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +61 -11
  232. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +22 -10
  233. package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.d.ts +2 -3
  234. package/lib/chevre/service/reserve/potentialActions/onReservationsCreated.js +22 -10
  235. package/lib/chevre/service/reserve/useReservation.d.ts +3 -1
  236. package/lib/chevre/service/reserve/useReservation.js +25 -25
  237. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +3 -1
  238. package/lib/chevre/service/reserve/verifyToken4reservation.js +3 -1
  239. package/lib/chevre/service/reserveCOA/cancelReservation.d.ts +12 -0
  240. package/lib/chevre/service/reserveCOA/cancelReservation.js +78 -0
  241. package/lib/chevre/service/reserveCOA/factory.d.ts +13 -0
  242. package/lib/chevre/service/reserveCOA/factory.js +23 -0
  243. package/lib/chevre/service/task/acceptCOAOffer.js +9 -3
  244. package/lib/chevre/service/task/authorizePayment.js +5 -6
  245. package/lib/chevre/service/task/cancelPendingReservation.d.ts +2 -2
  246. package/lib/chevre/service/task/cancelPendingReservation.js +52 -16
  247. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +2 -0
  248. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -3
  249. package/lib/chevre/service/task/deletePerson.js +168 -136
  250. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +3 -3
  251. package/lib/chevre/service/task/importEventsFromCOA.js +3 -3
  252. package/lib/chevre/service/task/importOffersFromCOA.js +3 -4
  253. package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +3 -0
  254. package/lib/chevre/service/task/invalidatePaymentUrl.js +33 -0
  255. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +2 -2
  256. package/lib/chevre/service/task/onAuthorizationCreated.js +11 -16
  257. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +8 -5
  258. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +8 -5
  259. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +8 -5
  260. package/lib/chevre/service/task/onResourceUpdated.js +48 -27
  261. package/lib/chevre/service/task/pay.js +3 -3
  262. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.d.ts +28 -0
  263. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +33 -0
  264. package/lib/chevre/service/task/payment/payByTask.d.ts +48 -0
  265. package/lib/chevre/service/{payment.js → task/payment/payByTask.js} +16 -65
  266. package/lib/chevre/service/task/payment/refundByTask.d.ts +31 -0
  267. package/lib/chevre/service/task/payment/refundByTask.js +41 -0
  268. package/lib/chevre/service/task/payment/voidPaymentByTask.d.ts +23 -0
  269. package/lib/chevre/service/task/payment/voidPaymentByTask.js +38 -0
  270. package/lib/chevre/service/task/publishPaymentUrl.js +4 -0
  271. package/lib/chevre/service/task/refund.js +2 -2
  272. package/lib/chevre/service/task/reserve.js +2 -0
  273. package/lib/chevre/service/task/returnPayTransaction.js +7 -2
  274. package/lib/chevre/service/task/returnReserveTransaction.js +15 -6
  275. package/lib/chevre/service/task/triggerWebhook.js +2 -2
  276. package/lib/chevre/service/task/useReservation.js +14 -1
  277. package/lib/chevre/service/task/voidPayTransaction.js +5 -3
  278. package/lib/chevre/service/task/voidPayment.js +2 -2
  279. package/lib/chevre/service/task/voidReserveTransaction.js +4 -4
  280. package/lib/chevre/service/task.d.ts +19 -22
  281. package/lib/chevre/service/task.js +22 -51
  282. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +2 -1
  283. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +13 -7
  284. package/lib/chevre/service/transaction/placeOrder/confirm.js +29 -2
  285. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +5 -3
  286. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +80 -54
  287. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +4 -0
  288. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +2 -1
  289. package/lib/chevre/service/transaction/placeOrder.js +0 -2
  290. package/lib/chevre/service/transaction.d.ts +15 -8
  291. package/lib/chevre/service/transaction.js +8 -11
  292. package/package.json +5 -4
  293. package/example/src/chevre/investigateSellers.ts +0 -53
  294. package/example/src/chevre/migratePaymentServiceChannelsCreditCard.ts +0 -132
  295. package/example/src/chevre/migratePaymentServiceChannelsMovieTicket.ts +0 -113
  296. package/example/src/chevre/migratePaymentServiceContactPointMovieTicket.ts +0 -87
  297. package/example/src/chevre/optimizeOffers.ts +0 -16
  298. package/example/src/chevre/playAroundTicket.ts +0 -41
  299. package/example/src/chevre/reexportTasksByExportAction.ts +0 -37
  300. package/example/src/chevre/retryTasks.ts +0 -41
  301. package/example/src/chevre/saveTasks.ts +0 -53
  302. package/example/src/chevre/searchTransactions.ts +0 -39
  303. package/example/src/createMongooseConnection.ts +0 -26
  304. package/lib/chevre/service/payment/any/fixConfirmationNumberAsNeeded.d.ts +0 -11
  305. package/lib/chevre/service/payment/any/fixConfirmationNumberAsNeeded.js +0 -31
  306. package/lib/chevre/service/payment.d.ts +0 -95
@@ -0,0 +1,124 @@
1
+ // tslint:disable:no-console
2
+ // import * as fs from 'fs';
3
+ import * as moment from 'moment-timezone';
4
+ import * as mongoose from 'mongoose';
5
+
6
+ import { chevre } from '../../../../lib/index';
7
+
8
+ const PROJECT_ID = String(process.env.PROJECT_ID);
9
+ const AGGREGATE_PERIOD_IN_DAYS = 365;
10
+
11
+ function createAggregation(params: {
12
+ order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'>;
13
+ orderDateGte: Date;
14
+ orderDateLte: Date;
15
+ }) {
16
+ return async (repos: {
17
+ order: chevre.repository.Order;
18
+ }) => {
19
+ const { order, orderDateGte, orderDateLte } = params;
20
+
21
+ return repos.order.aggregateOrderOfCustomer({
22
+ project: { id: { $eq: PROJECT_ID } },
23
+ orderDate: { $gte: orderDateGte, $lte: orderDateLte },
24
+ customer: { email: { $eq: String(order.customer.email) } }
25
+ });
26
+ };
27
+ }
28
+
29
+ // tslint:disable-next-line:max-func-body-length
30
+ async function main() {
31
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
32
+
33
+ const aggregateOrderRepo = await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
34
+ const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
35
+
36
+ const orderDateLte: Date = moment()
37
+ .toDate();
38
+ const orderDateGte: Date = moment(orderDateLte)
39
+ .add(-AGGREGATE_PERIOD_IN_DAYS, 'days')
40
+ .toDate();
41
+
42
+ const cursor = orderRepo.getCursor(
43
+ {
44
+ 'project.id': { $eq: PROJECT_ID },
45
+ orderDate: {
46
+ $gte: orderDateGte,
47
+ $lte: orderDateLte
48
+ },
49
+ typeOf: { $eq: chevre.factory.order.OrderType.Order }
50
+ },
51
+ {
52
+ customer: 1,
53
+ orderDate: 1,
54
+ orderNumber: 1,
55
+ project: 1
56
+ }
57
+ );
58
+ console.log('docs found');
59
+
60
+ let maxSumGraceTime: number = 0;
61
+ const peopleWithAggregateOrder: {
62
+ identifier: string;
63
+ aggregateOrder: {
64
+ // emailCount: number;
65
+ orderCount: number;
66
+ sumGraceTime: number;
67
+ };
68
+ score?: number;
69
+ }[] = [];
70
+
71
+ let i = 0;
72
+ let updateCount = 0;
73
+ // tslint:disable-next-line:max-func-body-length
74
+ await cursor.eachAsync(async (doc) => {
75
+ i += 1;
76
+ const order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'> = doc.toObject();
77
+
78
+ const { email } = order.customer;
79
+ if (typeof email === 'string') {
80
+ console.log(
81
+ 'aggregating...',
82
+ order.project.id, order.orderNumber, order.orderDate, i);
83
+ const aggregateResult = await createAggregation({ order, orderDateGte, orderDateLte })({ order: orderRepo });
84
+ await aggregateOrderRepo.save(
85
+ {
86
+ project: order.project,
87
+ identifier: email,
88
+ typeOf: chevre.factory.personType.Person
89
+ },
90
+ { $set: { aggregateOrder: aggregateResult.aggregation } }
91
+ );
92
+ updateCount += 1;
93
+ console.log(
94
+ 'aggregated.',
95
+ order.project.id, order.orderNumber, order.orderDate, i);
96
+
97
+ const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
98
+ ? aggregateResult.aggregation.sumGraceTime
99
+ : 0;
100
+ maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
101
+
102
+ peopleWithAggregateOrder.push({
103
+ identifier: email,
104
+ aggregateOrder: {
105
+ ...aggregateResult.aggregation,
106
+ sumGraceTime
107
+ }
108
+ });
109
+ console.log('maxSumGraceTime:', maxSumGraceTime);
110
+ }
111
+ });
112
+
113
+ console.log(i, 'docs checked');
114
+ console.log(updateCount, 'docs aggregated');
115
+
116
+ // tslint:disable-next-line:non-literal-fs-path no-null-keyword
117
+ // fs.writeFileSync(`${__dirname}/peopleWithAggregateOrder.json`, JSON.stringify(peopleWithAggregateOrder, null, ' '));
118
+ }
119
+
120
+ main()
121
+ .then(() => {
122
+ console.log('success!');
123
+ })
124
+ .catch(console.error);
@@ -0,0 +1,172 @@
1
+ // tslint:disable:no-console
2
+ import * as fs from 'fs';
3
+ import * as moment from 'moment-timezone';
4
+ import * as mongoose from 'mongoose';
5
+
6
+ import { chevre } from '../../../../lib/index';
7
+
8
+ const PROJECT_ID = String(process.env.PROJECT_ID);
9
+ // const SCREEN_CODE = '10';
10
+ // const MOVIE_THEATER_CODE = '118';
11
+ const SCREEN_CODE = '130';
12
+ // const SCREEN_CODE = '211';
13
+ const MOVIE_THEATER_CODE = '020';
14
+ const AGGREGATE_PERIOD_IN_MONTHS = 12;
15
+ // tslint:disable-next-line:max-func-body-length
16
+ async function main() {
17
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
18
+
19
+ const aggregateOrderRepo = await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
20
+ const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
21
+ const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
22
+
23
+ const royalCustomers = await aggregateOrderRepo.searchRoyalCustomers({
24
+ limit: 300,
25
+ project: { id: PROJECT_ID },
26
+ aggregateOrder: { orderCount: { $gte: 12 } }
27
+ });
28
+ // tslint:disable-next-line:no-null-keyword
29
+ console.dir(royalCustomers, { depth: null });
30
+ console.log(royalCustomers.length, 'royalCustomers found');
31
+
32
+ const customerEmails = royalCustomers.map(({ identifier }) => identifier);
33
+
34
+ const seats = <Pick<chevre.factory.place.seat.IPlace, 'branchCode'>[]>await seatRepo.searchSeats({
35
+ // limit: 50,
36
+ $projection: {
37
+ additionalProperty: 0,
38
+ 'containedInPlace.typeOf': 0,
39
+ 'containedInPlace.name': 0,
40
+ 'containedInPlace.containedInPlace': 0,
41
+ name: 0, typeOf: 0
42
+ },
43
+ project: { id: { $eq: PROJECT_ID } },
44
+ containedInPlace: {
45
+ containedInPlace: {
46
+ branchCode: { $eq: SCREEN_CODE },
47
+ containedInPlace: { branchCode: { $eq: MOVIE_THEATER_CODE } }
48
+ }
49
+ }
50
+ });
51
+ // tslint:disable-next-line:no-null-keyword
52
+ // console.dir(seats, { depth: null });
53
+ console.log(seats.length, 'seats found');
54
+
55
+ const orderDateGte: Date = moment()
56
+ .add(-AGGREGATE_PERIOD_IN_MONTHS, 'months')
57
+ .toDate();
58
+ const orderDateLte: Date = moment()
59
+ .toDate();
60
+
61
+ let maxSumGraceTime: number = 0;
62
+ let maxRepeatRate: number = 0;
63
+ const seatsWithAggregateOrder: {
64
+ branchCode: string;
65
+ aggregateOrder: {
66
+ emailCount: number;
67
+ orderCount: number;
68
+ repeatRate: number;
69
+ avgGraceTime?: number;
70
+ sumGraceTime: number;
71
+ avgGraceTimeInHours?: number;
72
+ sumGraceTimeInHours: number;
73
+ };
74
+ score?: number;
75
+ }[] = [];
76
+ let i = 1;
77
+ for (const { branchCode } of seats) {
78
+ i += 1;
79
+ const startTime = process.hrtime();
80
+ const aggregateResult = await orderRepo.aggregateOrderOfSeat({
81
+ project: { id: { $eq: PROJECT_ID } },
82
+ orderDate: { $gte: orderDateGte, $lte: orderDateLte },
83
+ acceptedOffers: {
84
+ itemOffered: {
85
+ reservationFor: {
86
+ location: { branchCode: SCREEN_CODE },
87
+ superEvent: { location: { branchCode: MOVIE_THEATER_CODE } }
88
+ },
89
+ reservedTicket: { ticketedSeat: { seatNumber: branchCode } }
90
+ }
91
+ },
92
+ customer: { email: { $in: customerEmails } }
93
+ });
94
+ console.log('aggregateOrder:result', aggregateResult, orderDateGte, orderDateLte, i);
95
+ const diff = process.hrtime(startTime);
96
+ console.log(`aggregateOrderOfSeat took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
97
+
98
+ const emailCount = (typeof aggregateResult.aggregation.emailCount === 'number')
99
+ ? aggregateResult.aggregation.emailCount
100
+ : 0;
101
+ const repeatRate = (aggregateResult.aggregation.orderCount > 0)
102
+ // tslint:disable-next-line:no-magic-numbers
103
+ ? (aggregateResult.aggregation.orderCount - emailCount) * 100 / aggregateResult.aggregation.orderCount
104
+ : 0;
105
+ const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
106
+ ? aggregateResult.aggregation.sumGraceTime
107
+ : 0;
108
+ const avgGraceTimeInHours = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
109
+ ? Math.floor(
110
+ moment.duration(Math.floor(aggregateResult.aggregation.sumGraceTime / aggregateResult.aggregation.orderCount), 'milliseconds')
111
+ .asHours()
112
+ )
113
+ : 0;
114
+ const sumGraceTimeInHours = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
115
+ ? Math.floor(moment.duration(aggregateResult.aggregation.sumGraceTime, 'milliseconds')
116
+ .asHours())
117
+ : 0;
118
+ maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
119
+ maxRepeatRate = Math.max(repeatRate, maxRepeatRate);
120
+
121
+ seatsWithAggregateOrder.push({
122
+ branchCode,
123
+ aggregateOrder: {
124
+ ...aggregateResult.aggregation,
125
+ emailCount,
126
+ repeatRate,
127
+ avgGraceTimeInHours,
128
+ sumGraceTimeInHours,
129
+ sumGraceTime
130
+ }
131
+ });
132
+ }
133
+
134
+ const seatsJson = seatsWithAggregateOrder.map((seat, key) => {
135
+ // tslint:disable-next-line:no-magic-numbers
136
+ const score = Math.floor(seat.aggregateOrder.sumGraceTime * 100 / maxSumGraceTime);
137
+ console.log('aggregateOrder:result', seat.branchCode, key);
138
+
139
+ return {
140
+ branchCode: seat.branchCode,
141
+ score
142
+ };
143
+ });
144
+
145
+ const scoresByEmailJson = seatsWithAggregateOrder.map((seat, key) => {
146
+ // tslint:disable-next-line:no-magic-numbers
147
+ const score = Math.floor(seat.aggregateOrder.repeatRate * 100 / maxRepeatRate);
148
+ console.log('aggregateOrder:result', seat.branchCode, seat.aggregateOrder.emailCount, key);
149
+
150
+ return {
151
+ branchCode: seat.branchCode,
152
+ score
153
+ // repeatRate: seat.aggregateOrder.repeatRate,
154
+ // emailCount: seat.aggregateOrder.emailCount,
155
+ // orderCount: seat.aggregateOrder.orderCount
156
+ };
157
+ });
158
+
159
+ console.log('maxSumGraceTime:', maxSumGraceTime);
160
+ console.log('maxRepeatRate:', maxRepeatRate);
161
+
162
+ // tslint:disable-next-line:non-literal-fs-path no-null-keyword
163
+ fs.writeFileSync(`${__dirname}/seatScoresByGraceTime.json`, JSON.stringify(seatsJson, null, ' '));
164
+ // tslint:disable-next-line:non-literal-fs-path no-null-keyword
165
+ fs.writeFileSync(`${__dirname}/seatScoresByEmail.json`, JSON.stringify(scoresByEmailJson, null, ' '));
166
+ }
167
+
168
+ main()
169
+ .then(() => {
170
+ console.log('success!');
171
+ })
172
+ .catch(console.error);
@@ -0,0 +1,79 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+ // const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
14
+
15
+ const cursor = paymentServiceRepo.getCursor(
16
+ {
17
+ typeOf: {
18
+ $in: [
19
+ chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
20
+ chevre.factory.service.paymentService.PaymentServiceType.MovieTicket
21
+ ]
22
+ }
23
+ // _id: { $eq: '5f9a4fed4f3709000abe6415' }
24
+ },
25
+ {
26
+ _id: 1,
27
+ availableChannel: 1,
28
+ productID: 1,
29
+ project: 1,
30
+ typeOf: 1,
31
+ serviceType: 1
32
+ }
33
+ );
34
+ console.log('docs found');
35
+
36
+ let i = 0;
37
+ // let updateCount = 0;
38
+ const unexpectedIds: string[] = [];
39
+ await cursor.eachAsync(async (doc) => {
40
+ i += 1;
41
+ const paymentService: Pick<
42
+ chevre.factory.service.paymentService.IService,
43
+ 'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf' | 'serviceType'
44
+ > = doc.toObject();
45
+
46
+ console.log(
47
+ 'alreadyMigrated?', paymentService.project.id, paymentService.productID, i);
48
+ if (typeof paymentService.id !== 'string') {
49
+ throw new Error('id must be string');
50
+ }
51
+
52
+ let isUnique = false;
53
+ const existingServices = await paymentServiceRepo.projectFields(
54
+ {
55
+ project: { id: { $eq: paymentService.project.id } },
56
+ serviceType: { codeValue: { $eq: paymentService.serviceType.codeValue } }
57
+ },
58
+ ['id']
59
+ );
60
+ if (existingServices.length === 1 && existingServices.at(0)?.id === paymentService.id) {
61
+ isUnique = true;
62
+ }
63
+
64
+ if (isUnique) {
65
+ console.log(
66
+ 'unique.', paymentService.project.id, paymentService.productID, i);
67
+ } else {
68
+ unexpectedIds.push(paymentService.productID);
69
+ }
70
+ });
71
+
72
+ console.log(unexpectedIds);
73
+ console.log(i, 'docs checked');
74
+ console.log(unexpectedIds.length, 'docs unexpected');
75
+ }
76
+
77
+ main()
78
+ .then()
79
+ .catch(console.error);
@@ -0,0 +1,42 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
14
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
15
+
16
+ let result = await transactionRepo.countPotentiallyExportTasks({
17
+ endDate: {
18
+ $lt: moment()
19
+ // tslint:disable-next-line:no-magic-numbers
20
+ .add(-60, 'seconds')
21
+ .toDate()
22
+ },
23
+ limit: 10
24
+ });
25
+ console.log('result', result);
26
+
27
+ result = await taskRepo.countPotentiallyRunning({
28
+ runsAt: {
29
+ $lt: moment()
30
+ // tslint:disable-next-line:no-magic-numbers
31
+ .add(-60, 'seconds')
32
+ .toDate()
33
+ },
34
+ name: { $eq: chevre.factory.taskName.DeleteTransaction },
35
+ limit: 10
36
+ });
37
+ console.log('result', result);
38
+ }
39
+
40
+ main()
41
+ .then()
42
+ .catch(console.error);
@@ -0,0 +1,30 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ mongoose.Model.on('index', (...args) => {
9
+ console.error('******** index event emitted. ********\n', args);
10
+ });
11
+
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
16
+
17
+ const { count } = await transactionRepo.count<chevre.factory.transactionType.PlaceOrder>({
18
+ limit: 5000,
19
+ // page: 1,
20
+ // project: { id: { $eq: project.id } },
21
+ typeOf: chevre.factory.transactionType.PlaceOrder,
22
+ statuses: [chevre.factory.transactionStatusType.InProgress],
23
+ startThrough: new Date()
24
+ });
25
+ console.log('count:', count);
26
+ }
27
+
28
+ main()
29
+ .then()
30
+ .catch(console.error);
@@ -0,0 +1,57 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ chevre.eventEmitter.task.onTaskStatusChanged((event) => {
9
+ console.log('onTaskStatusChanged', event);
10
+ });
11
+
12
+ async function main() {
13
+ const now = new Date();
14
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
15
+
16
+ const taskIdentifier: string = `${project.id}:${chevre.factory.taskName.TriggerWebhook}:sample:2025032801`;
17
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
18
+ const creatingTask = {
19
+ alternateName: taskIdentifier,
20
+ identifier: taskIdentifier,
21
+ name: chevre.factory.taskName.TriggerWebhook,
22
+ status: chevre.factory.taskStatus.Ready,
23
+ runsAt: now,
24
+ remainingNumberOfTries: 1,
25
+ numberOfTried: 0,
26
+ executionResults: [],
27
+ data: {
28
+ object: {
29
+ sample: 'sample'
30
+ },
31
+ recipient: {
32
+ id: '',
33
+ name: 'telemetry',
34
+ typeOf: 'WebApplication'
35
+ },
36
+ target: {
37
+ httpMethod: 'POST',
38
+ encodingType: 'application/json',
39
+ typeOf: 'EntryPoint',
40
+ urlTemplate: 'https://smart-theater-telemetry-api.an.r.appspot.com/webhooks/lineNotify'
41
+ },
42
+ identifier: 'sampleNotificationIdentifier'
43
+ // about: {
44
+ // id: '67e62b0b28817948355a671c',
45
+ // typeOf: 'PlaceOrder'
46
+ // }
47
+ },
48
+ project: { id: project.id, typeOf: <chevre.factory.organizationType.Project>chevre.factory.organizationType.Project }
49
+ };
50
+ taskRepo.createIfNotExistByAlternateName(creatingTask, { emitImmediately: true });
51
+ taskRepo.createIfNotExistByAlternateName(creatingTask, { emitImmediately: true });
52
+ console.log('success!');
53
+ }
54
+
55
+ main()
56
+ .then()
57
+ .catch(console.error);
@@ -4,7 +4,7 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
- const TASK_STORAGE_PERIOD_IN_DAYS = 365;
7
+ const TASK_STORAGE_PERIOD_IN_MINUTES = 43200; // 30*24*60
8
8
 
9
9
  async function main() {
10
10
  const now = new Date();
@@ -12,15 +12,29 @@ async function main() {
12
12
 
13
13
  const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
14
14
 
15
- const result = await taskRepo.deleteRunsAtPassedCertainPeriod({
16
- runsAt: {
17
- $lt: moment(now)
18
- .add(-TASK_STORAGE_PERIOD_IN_DAYS, 'days')
19
- .toDate()
20
- }
21
- });
15
+ let taskInMinutes = 57600; // 40*24*60
16
+ // let taskInMinutes = 172800; // 120*24*60
17
+ // tslint:disable-next-line:no-magic-numbers
18
+ while (taskInMinutes > TASK_STORAGE_PERIOD_IN_MINUTES) {
19
+ taskInMinutes -= 1;
20
+ console.log(
21
+ 'cleaning...',
22
+ taskInMinutes,
23
+ moment.duration(taskInMinutes, 'minutes')
24
+ .asDays(),
25
+ 'days'
26
+ );
27
+ const result = await taskRepo.deleteRunsAtPassedCertainPeriod({
28
+ runsAt: {
29
+ $lt: moment(now)
30
+ .add(-taskInMinutes, 'minutes')
31
+ .toDate()
32
+ }
33
+ });
34
+ console.log('deleted', result);
35
+ }
22
36
 
23
- console.log('deleted', result);
37
+ console.log('success!');
24
38
  }
25
39
 
26
40
  main()
@@ -0,0 +1,41 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
11
+
12
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
+ const task = await taskRepo.executeOneIfExists({
14
+ name: {
15
+ $nin: [
16
+ chevre.factory.taskName.DeleteTransaction,
17
+ chevre.factory.taskName.ImportEventCapacitiesFromCOA,
18
+ chevre.factory.taskName.ImportEventsFromCOA,
19
+ chevre.factory.taskName.AcceptCOAOffer,
20
+ chevre.factory.taskName.CheckMovieTicket,
21
+ chevre.factory.taskName.AuthorizePayment,
22
+ chevre.factory.taskName.PublishPaymentUrl
23
+ ]
24
+ },
25
+ executor: { name: 'sample' },
26
+ runsAt: {
27
+ $lt: moment()
28
+ // tslint:disable-next-line:no-magic-numbers
29
+ .add(-2, 'years')
30
+ // .add(-60, 'seconds')
31
+ .toDate()
32
+ }
33
+ });
34
+
35
+ // tslint:disable-next-line:no-null-keyword
36
+ console.dir(task, { depth: null });
37
+ }
38
+
39
+ main()
40
+ .then()
41
+ .catch(console.error);
@@ -1,13 +1,10 @@
1
1
  // tslint:disable:no-console
2
- /**
3
- * イベント集計タスク実行
4
- */
5
2
  import { chevre } from '../../../lib/index';
6
3
 
7
4
  import * as mongoose from 'mongoose';
8
5
  import * as redis from 'redis';
9
6
 
10
- export async function aggregateScreeningEvent() {
7
+ export async function executeTaskIfExists() {
11
8
  const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
12
9
  socket: {
13
10
  port: Number(<string>process.env.REDIS_PORT),
@@ -21,8 +18,8 @@ export async function aggregateScreeningEvent() {
21
18
 
22
19
  let count = 0;
23
20
 
24
- const MAX_NUBMER_OF_PARALLEL_TASKS = 10;
25
- const INTERVAL_MILLISECONDS = 100;
21
+ const MAX_NUBMER_OF_PARALLEL_TASKS = 1;
22
+ const INTERVAL_MILLISECONDS = 1000;
26
23
 
27
24
  setInterval(
28
25
  async () => {
@@ -34,9 +31,21 @@ export async function aggregateScreeningEvent() {
34
31
 
35
32
  try {
36
33
  console.log('executing...', count);
37
- await (await chevre.service.task.createService()).executeByName({
38
- name: chevre.factory.taskName.AggregateScreeningEvent,
39
- executor: { name: 'sample' }
34
+ await (await chevre.service.task.createService()).executeOneIfExists({
35
+ // name: chevre.factory.taskName.AggregateScreeningEvent,
36
+ executor: { name: 'sample' },
37
+ runsAt: { $lt: new Date() },
38
+ name: {
39
+ $nin: [
40
+ chevre.factory.taskName.DeleteTransaction,
41
+ chevre.factory.taskName.ImportEventCapacitiesFromCOA,
42
+ chevre.factory.taskName.ImportEventsFromCOA,
43
+ chevre.factory.taskName.AcceptCOAOffer,
44
+ chevre.factory.taskName.CheckMovieTicket,
45
+ chevre.factory.taskName.AuthorizePayment,
46
+ chevre.factory.taskName.PublishPaymentUrl
47
+ ]
48
+ }
40
49
  })({
41
50
  connection: mongoose.connection,
42
51
  redisClient,
@@ -64,7 +73,7 @@ export async function aggregateScreeningEvent() {
64
73
  );
65
74
  }
66
75
 
67
- aggregateScreeningEvent()
76
+ executeTaskIfExists()
68
77
  .then(() => {
69
78
  console.log('success!');
70
79
  })