@chevre/domain 21.2.0-alpha.12 → 21.2.0-alpha.121

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 (293) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +85 -27
  3. package/example/src/chevre/countDelayedTasks.ts +7 -2
  4. package/example/src/chevre/deleteTasksByName.ts +10 -2
  5. package/example/src/chevre/findMovieTheaterById.ts +40 -0
  6. package/example/src/chevre/importEventsFromCOA.ts +3 -4
  7. package/example/src/chevre/lockStockHolder.ts +2 -1
  8. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  9. package/example/src/chevre/migrateScreeningEventSeriesVersion.ts +79 -0
  10. package/example/src/chevre/migrateStockHolderKeys.ts +1 -1
  11. package/example/src/chevre/processPay.ts +5 -1
  12. package/example/src/chevre/processRegisterMembership.ts +8 -4
  13. package/example/src/chevre/processRegisterPaymentCard.ts +8 -4
  14. package/example/src/chevre/processReserve.ts +5 -2
  15. package/example/src/chevre/saveTasks.ts +13 -10
  16. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  17. package/example/src/chevre/searchActions.ts +33 -0
  18. package/example/src/chevre/searchEventSeats.ts +2 -1
  19. package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +37 -1
  20. package/example/src/chevre/searchSendEmailActions.ts +44 -0
  21. package/example/src/chevre/task/executeTasks.ts +26 -0
  22. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  23. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  24. package/example/src/chevre/transaction/processReturnOrder.ts +40 -0
  25. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  26. package/example/src/chevre/updateScreeningRoom.ts +41 -0
  27. package/example/src/chevre/updateTransaction.ts +1 -1
  28. package/example/src/playOnMoment.ts +24 -0
  29. package/lib/chevre/credentials.d.ts +1 -0
  30. package/lib/chevre/credentials.js +2 -1
  31. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  32. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  33. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  34. package/lib/chevre/eventEmitter/task.js +25 -0
  35. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  36. package/lib/chevre/eventEmitter/transaction.js +25 -0
  37. package/lib/chevre/eventEmitter.d.ts +4 -0
  38. package/lib/chevre/eventEmitter.js +9 -0
  39. package/lib/chevre/index.d.ts +3 -2
  40. package/lib/chevre/index.js +5 -3
  41. package/lib/chevre/repo/account.js +3 -2
  42. package/lib/chevre/repo/accountTransaction.d.ts +3 -11
  43. package/lib/chevre/repo/accountTransaction.js +3 -55
  44. package/lib/chevre/repo/action.d.ts +42 -2
  45. package/lib/chevre/repo/action.js +130 -57
  46. package/lib/chevre/repo/additionalProperty.js +2 -1
  47. package/lib/chevre/repo/aggregation.d.ts +3 -0
  48. package/lib/chevre/repo/aggregation.js +3 -0
  49. package/lib/chevre/repo/assetTransaction.d.ts +25 -9
  50. package/lib/chevre/repo/assetTransaction.js +259 -87
  51. package/lib/chevre/repo/categoryCode.d.ts +1 -1
  52. package/lib/chevre/repo/categoryCode.js +37 -25
  53. package/lib/chevre/repo/code.js +3 -2
  54. package/lib/chevre/repo/comment.d.ts +4 -1
  55. package/lib/chevre/repo/comment.js +22 -6
  56. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  57. package/lib/chevre/repo/confirmationNumber.js +3 -15
  58. package/lib/chevre/repo/creativeWork.d.ts +2 -4
  59. package/lib/chevre/repo/creativeWork.js +35 -12
  60. package/lib/chevre/repo/customer.js +2 -1
  61. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  62. package/lib/chevre/repo/emailMessage.js +2 -1
  63. package/lib/chevre/repo/event.d.ts +27 -1
  64. package/lib/chevre/repo/event.js +67 -33
  65. package/lib/chevre/repo/member.js +4 -3
  66. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  67. package/lib/chevre/repo/merchantReturnPolicy.js +2 -1
  68. package/lib/chevre/repo/mongoose/schemas/account.d.ts +4 -2
  69. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +29 -3
  70. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +31 -3
  71. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
  72. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +13 -3
  73. package/lib/chevre/repo/mongoose/schemas/action.d.ts +43 -3
  74. package/lib/chevre/repo/mongoose/schemas/action.js +19 -1
  75. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +17 -3
  76. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +4 -2
  77. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +44 -3
  78. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +32 -19
  79. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +19 -3
  80. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
  81. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +25 -3
  82. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +27 -3
  83. package/lib/chevre/repo/mongoose/schemas/comments.js +1 -1
  84. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +43 -3
  85. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +25 -3
  86. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +21 -3
  87. package/lib/chevre/repo/mongoose/schemas/event.d.ts +71 -3
  88. package/lib/chevre/repo/mongoose/schemas/holdReservation.d.ts +75 -0
  89. package/lib/chevre/repo/mongoose/schemas/holdReservation.js +56 -0
  90. package/lib/chevre/repo/mongoose/schemas/member.d.ts +13 -3
  91. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +21 -3
  92. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +65 -3
  93. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +27 -3
  94. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +74 -0
  95. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +45 -0
  96. package/lib/chevre/repo/mongoose/schemas/order.d.ts +51 -3
  97. package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
  98. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +25 -3
  99. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +1 -1
  100. package/lib/chevre/repo/mongoose/schemas/place.d.ts +49 -3
  101. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +29 -3
  102. package/lib/chevre/repo/mongoose/schemas/product.d.ts +31 -3
  103. package/lib/chevre/repo/mongoose/schemas/project.d.ts +23 -3
  104. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +63 -5
  105. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
  106. package/lib/chevre/repo/mongoose/schemas/role.d.ts +11 -3
  107. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +31 -3
  108. package/lib/chevre/repo/mongoose/schemas/seller.js +6 -0
  109. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +11 -3
  110. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +1 -1
  111. package/lib/chevre/repo/mongoose/schemas/task.d.ts +30 -3
  112. package/lib/chevre/repo/mongoose/schemas/task.js +2 -1
  113. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +21 -3
  114. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +40 -3
  115. package/lib/chevre/repo/mongoose/schemas/transaction.js +2 -1
  116. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +11 -3
  117. package/lib/chevre/repo/offer.js +3 -2
  118. package/lib/chevre/repo/offerCatalog.js +0 -27
  119. package/lib/chevre/repo/offerItemCondition.d.ts +22 -0
  120. package/lib/chevre/repo/offerItemCondition.js +121 -0
  121. package/lib/chevre/repo/order.d.ts +55 -3
  122. package/lib/chevre/repo/order.js +62 -10
  123. package/lib/chevre/repo/ownershipInfo.js +2 -7
  124. package/lib/chevre/repo/place.d.ts +20 -5
  125. package/lib/chevre/repo/place.js +63 -23
  126. package/lib/chevre/repo/priceSpecification.js +3 -2
  127. package/lib/chevre/repo/product.d.ts +1 -3
  128. package/lib/chevre/repo/product.js +25 -4
  129. package/lib/chevre/repo/project.js +2 -1
  130. package/lib/chevre/repo/reservation.d.ts +20 -4
  131. package/lib/chevre/repo/reservation.js +40 -59
  132. package/lib/chevre/repo/role.js +3 -2
  133. package/lib/chevre/repo/seller.d.ts +1 -1
  134. package/lib/chevre/repo/seller.js +44 -23
  135. package/lib/chevre/repo/serviceOutput.js +2 -1
  136. package/lib/chevre/repo/stockHolder.d.ts +37 -6
  137. package/lib/chevre/repo/stockHolder.js +312 -87
  138. package/lib/chevre/repo/task.d.ts +45 -2
  139. package/lib/chevre/repo/task.js +94 -15
  140. package/lib/chevre/repo/transaction.d.ts +23 -3
  141. package/lib/chevre/repo/transaction.js +177 -56
  142. package/lib/chevre/repo/trip.js +2 -1
  143. package/lib/chevre/repository.d.ts +5 -2
  144. package/lib/chevre/repository.js +8 -4
  145. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +8 -6
  146. package/lib/chevre/service/aggregation/system.d.ts +110 -23
  147. package/lib/chevre/service/aggregation/system.js +213 -91
  148. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -28
  149. package/lib/chevre/service/assetTransaction/moneyTransfer.js +2 -24
  150. package/lib/chevre/service/assetTransaction/pay/account/validation.js +1 -1
  151. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +17 -1
  152. package/lib/chevre/service/assetTransaction/pay.d.ts +5 -1
  153. package/lib/chevre/service/assetTransaction/pay.js +20 -34
  154. package/lib/chevre/service/assetTransaction/refund.js +2 -24
  155. package/lib/chevre/service/assetTransaction/registerService.js +1 -25
  156. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +15 -5
  157. package/lib/chevre/service/assetTransaction/reserve/factory.js +122 -58
  158. package/lib/chevre/service/assetTransaction/reserve.d.ts +10 -1
  159. package/lib/chevre/service/assetTransaction/reserve.js +85 -69
  160. package/lib/chevre/service/assetTransaction.d.ts +6 -0
  161. package/lib/chevre/service/assetTransaction.js +9 -4
  162. package/lib/chevre/service/event.js +16 -5
  163. package/lib/chevre/service/notification/factory.js +2 -2
  164. package/lib/chevre/service/notification.d.ts +3 -1
  165. package/lib/chevre/service/notification.js +41 -7
  166. package/lib/chevre/service/offer/event/authorize.d.ts +3 -0
  167. package/lib/chevre/service/offer/event/authorize.js +8 -2
  168. package/lib/chevre/service/offer/event/factory.d.ts +3 -0
  169. package/lib/chevre/service/offer/event/factory.js +16 -5
  170. package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
  171. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  172. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  173. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -9
  174. package/lib/chevre/service/offer/product.js +2 -2
  175. package/lib/chevre/service/offer.d.ts +16 -8
  176. package/lib/chevre/service/offer.js +69 -8
  177. package/lib/chevre/service/order/deleteOrder.d.ts +3 -1
  178. package/lib/chevre/service/order/deleteOrder.js +8 -8
  179. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +5 -2
  180. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +41 -81
  181. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -3
  182. package/lib/chevre/service/order/onOrderUpdated.d.ts +16 -0
  183. package/lib/chevre/service/order/onOrderUpdated.js +22 -0
  184. package/lib/chevre/service/order/placeOrder.d.ts +1 -0
  185. package/lib/chevre/service/order/placeOrder.js +41 -24
  186. package/lib/chevre/service/order/returnOrder.d.ts +1 -0
  187. package/lib/chevre/service/order/returnOrder.js +7 -12
  188. package/lib/chevre/service/order/sendOrder.d.ts +1 -0
  189. package/lib/chevre/service/order/sendOrder.js +7 -10
  190. package/lib/chevre/service/order.d.ts +2 -1
  191. package/lib/chevre/service/order.js +3 -1
  192. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  193. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  194. package/lib/chevre/service/payment/any.d.ts +9 -5
  195. package/lib/chevre/service/payment/any.js +80 -18
  196. package/lib/chevre/service/payment/creditCard.d.ts +1 -1
  197. package/lib/chevre/service/payment/creditCard.js +23 -17
  198. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +8 -7
  199. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  200. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +1 -1
  201. package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -1
  202. package/lib/chevre/service/payment/movieTicket/validation.d.ts +6 -6
  203. package/lib/chevre/service/payment/movieTicket/validation.js +55 -32
  204. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  205. package/lib/chevre/service/payment/movieTicket.js +7 -6
  206. package/lib/chevre/service/product.js +1 -5
  207. package/lib/chevre/service/report/telemetry.d.ts +0 -11
  208. package/lib/chevre/service/report/telemetry.js +21 -24
  209. package/lib/chevre/service/reserve/cancelReservation.d.ts +5 -3
  210. package/lib/chevre/service/reserve/cancelReservation.js +153 -142
  211. package/lib/chevre/service/reserve/checkInReservation.d.ts +9 -4
  212. package/lib/chevre/service/reserve/checkInReservation.js +77 -3
  213. package/lib/chevre/service/reserve/confirmReservation.d.ts +7 -4
  214. package/lib/chevre/service/reserve/confirmReservation.js +133 -58
  215. package/lib/chevre/service/reserve/factory.d.ts +1 -1
  216. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +17 -5
  217. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +26 -24
  218. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -3
  219. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  220. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -3
  221. package/lib/chevre/service/reserve/useReservation.d.ts +7 -3
  222. package/lib/chevre/service/reserve/useReservation.js +61 -71
  223. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +15 -0
  224. package/lib/chevre/service/reserve/verifyToken4reservation.js +56 -0
  225. package/lib/chevre/service/reserve.d.ts +3 -2
  226. package/lib/chevre/service/reserve.js +4 -2
  227. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  228. package/lib/chevre/service/task/cancelPendingReservation.js +6 -2
  229. package/lib/chevre/service/task/cancelReservation.js +1 -1
  230. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  231. package/lib/chevre/service/task/deleteTransaction.js +10 -8
  232. package/lib/chevre/service/task/importOffersFromCOA.js +4 -0
  233. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +7 -0
  234. package/lib/chevre/service/task/onAuthorizationCreated.js +108 -0
  235. package/lib/chevre/service/task/onEventChanged.d.ts +7 -0
  236. package/lib/chevre/service/task/{deleteOrder.js → onEventChanged.js} +8 -14
  237. package/lib/chevre/service/task/onResourceUpdated.d.ts +7 -0
  238. package/lib/chevre/service/task/onResourceUpdated.js +352 -0
  239. package/lib/chevre/service/task/placeOrder.js +1 -1
  240. package/lib/chevre/service/task/reserve.js +10 -7
  241. package/lib/chevre/service/task/returnOrder.js +1 -1
  242. package/lib/chevre/service/task/returnPayTransaction.js +2 -12
  243. package/lib/chevre/service/task/sendOrder.js +1 -1
  244. package/lib/chevre/service/task/useReservation.d.ts +7 -0
  245. package/lib/chevre/service/task/useReservation.js +36 -0
  246. package/lib/chevre/service/task/voidReserveTransaction.js +4 -2
  247. package/lib/chevre/service/task.d.ts +9 -0
  248. package/lib/chevre/service/task.js +43 -4
  249. package/lib/chevre/service/transaction/deleteTransaction.d.ts +21 -0
  250. package/lib/chevre/service/transaction/deleteTransaction.js +232 -0
  251. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +11 -1
  252. package/lib/chevre/service/transaction/moneyTransfer/factory.d.ts +1 -1
  253. package/lib/chevre/service/transaction/moneyTransfer/factory.js +3 -1
  254. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -0
  255. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +1 -1
  256. package/lib/chevre/service/transaction/moneyTransfer.js +10 -13
  257. package/lib/chevre/service/transaction/orderProgramMembership/findCreditCard.js +1 -1
  258. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +1 -1
  259. package/lib/chevre/service/transaction/orderProgramMembership.js +7 -3
  260. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +42 -30
  261. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  262. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +1 -1
  263. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.d.ts +1 -0
  264. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  265. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +1 -0
  266. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  267. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +1 -0
  268. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.d.ts +3 -0
  269. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +7 -3
  270. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -0
  271. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -2
  272. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.d.ts +1 -1
  273. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +2 -2
  274. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +2 -1
  275. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +23 -17
  276. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +0 -3
  277. package/lib/chevre/service/transaction/placeOrderInProgress.js +28 -15
  278. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +10 -1
  279. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +25 -17
  280. package/lib/chevre/service/transaction/returnOrder.d.ts +4 -0
  281. package/lib/chevre/service/transaction/returnOrder.js +228 -36
  282. package/lib/chevre/service/transaction.d.ts +8 -13
  283. package/lib/chevre/service/transaction.js +12 -145
  284. package/lib/chevre/settings.d.ts +12 -1
  285. package/lib/chevre/settings.js +53 -6
  286. package/package.json +5 -5
  287. package/example/src/chevre/createManyEventsIfNotExist.ts +0 -205
  288. package/example/src/chevre/eventCatalog2eventService.ts +0 -123
  289. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  290. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
  291. package/lib/chevre/service/task/deleteAssetTransaction.d.ts +0 -12
  292. package/lib/chevre/service/task/deleteAssetTransaction.js +0 -65
  293. package/lib/chevre/service/task/deleteOrder.d.ts +0 -6
@@ -13,6 +13,8 @@ exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../factory");
15
15
  const task_1 = require("./mongoose/schemas/task");
16
+ const task_2 = require("../eventEmitter/task");
17
+ const settings_1 = require("../settings");
16
18
  /**
17
19
  * タスク実行時のソート条件
18
20
  */
@@ -149,27 +151,43 @@ class MongoRepository {
149
151
  }
150
152
  return andConditions;
151
153
  }
152
- saveMany(taskAttributes) {
154
+ saveMany(taskAttributes, options) {
153
155
  return __awaiter(this, void 0, void 0, function* () {
156
+ const emitImmediately = (options === null || options === void 0 ? void 0 : options.emitImmediately) === true;
154
157
  if (taskAttributes.length > 0) {
155
158
  const result = yield this.taskModel.insertMany(taskAttributes, { ordered: false, rawResult: true });
156
159
  if (result.insertedCount !== taskAttributes.length) {
157
160
  throw new factory.errors.ServiceUnavailable('all tasks not saved');
158
161
  }
159
- // return result.ops;
160
- return Object.values(result.insertedIds)
162
+ const savedTasks = Object.values(result.insertedIds)
161
163
  .map((objectId) => {
162
164
  return { id: objectId.toHexString() };
163
165
  });
166
+ if (emitImmediately) {
167
+ savedTasks.forEach((savedTask) => {
168
+ task_2.taskEventEmitter.emitTaskStatusChanged({
169
+ id: savedTask.id,
170
+ status: factory.taskStatus.Ready
171
+ });
172
+ });
173
+ // taskAttributes.forEach((savedTask) => {
174
+ // taskEventEmitter.emitTaskStatusChanged({
175
+ // name: savedTask.name,
176
+ // status: factory.taskStatus.Ready
177
+ // });
178
+ // });
179
+ }
180
+ // return result.ops;
181
+ return savedTasks;
164
182
  }
165
183
  else {
166
184
  return [];
167
185
  }
168
186
  });
169
187
  }
170
- createInformTaskIfNotExist(params) {
188
+ createInformTaskIfNotExist(params, options) {
171
189
  return __awaiter(this, void 0, void 0, function* () {
172
- yield this.taskModel.findOneAndUpdate({
190
+ const createdTask = yield this.taskModel.findOneAndUpdate({
173
191
  'project.id': { $eq: params.project.id },
174
192
  name: params.name,
175
193
  'data.object.id': {
@@ -177,7 +195,38 @@ class MongoRepository {
177
195
  $eq: String(params.data.object.id)
178
196
  }
179
197
  }, { $setOnInsert: params }, { new: true, upsert: true })
198
+ .select({ _id: 1 })
180
199
  .exec();
200
+ if (options.emitImmediately) {
201
+ task_2.taskEventEmitter.emitTaskStatusChanged({
202
+ id: createdTask.id,
203
+ name: params.name,
204
+ status: factory.taskStatus.Ready
205
+ });
206
+ }
207
+ });
208
+ }
209
+ executeById(params) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const doc = yield this.taskModel.findOneAndUpdate({
212
+ status: factory.taskStatus.Ready,
213
+ runsAt: { $lt: new Date() },
214
+ _id: { $eq: params.id }
215
+ }, {
216
+ status: factory.taskStatus.Running,
217
+ lastTriedAt: new Date(),
218
+ $inc: {
219
+ remainingNumberOfTries: -1,
220
+ numberOfTried: 1 // トライ回数増やす
221
+ },
222
+ executor: params.executor
223
+ }, { new: true })
224
+ .exec();
225
+ if (doc === null) {
226
+ // tslint:disable-next-line:no-null-keyword
227
+ return null;
228
+ }
229
+ return doc.toObject();
181
230
  });
182
231
  }
183
232
  executeOneByName(params) {
@@ -192,7 +241,8 @@ class MongoRepository {
192
241
  $inc: {
193
242
  remainingNumberOfTries: -1,
194
243
  numberOfTried: 1 // トライ回数増やす
195
- }
244
+ },
245
+ executor: params.executor
196
246
  }, { new: true })
197
247
  .sort(sortOrder4executionOfTasks)
198
248
  .exec();
@@ -203,6 +253,35 @@ class MongoRepository {
203
253
  return doc.toObject();
204
254
  });
205
255
  }
256
+ /**
257
+ * 一定期間遅延したタスクを実行する
258
+ */
259
+ executeTasks(params) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const runsAtLt = moment(params.now)
262
+ .add(-params.delayInSeconds, 'seconds')
263
+ .toDate();
264
+ const delayedTasks = yield this.taskModel.find(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined))
265
+ .select({
266
+ _id: 1,
267
+ name: 1,
268
+ status: 1
269
+ })
270
+ .limit(params.limit)
271
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
272
+ .exec();
273
+ if (delayedTasks.length > 0) {
274
+ delayedTasks.forEach((delayedTask) => {
275
+ task_2.taskEventEmitter.emitTaskStatusChanged({
276
+ id: delayedTask.id,
277
+ name: delayedTask.name,
278
+ status: delayedTask.status
279
+ });
280
+ });
281
+ }
282
+ return delayedTasks;
283
+ });
284
+ }
206
285
  retry(params) {
207
286
  return __awaiter(this, void 0, void 0, function* () {
208
287
  const lastTriedAtShoudBeLessThan = moment()
@@ -297,7 +376,7 @@ class MongoRepository {
297
376
  return __awaiter(this, void 0, void 0, function* () {
298
377
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
299
378
  return this.taskModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
300
- .setOptions({ maxTimeMS: 10000 })
379
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
301
380
  .exec();
302
381
  });
303
382
  }
@@ -319,7 +398,7 @@ class MongoRepository {
319
398
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.runsAt) !== undefined) {
320
399
  query.sort({ runsAt: params.sort.runsAt });
321
400
  }
322
- return query.setOptions({ maxTimeMS: 10000 })
401
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
323
402
  .exec()
324
403
  .then((docs) => docs.map((doc) => doc.toObject()));
325
404
  });
@@ -333,10 +412,13 @@ class MongoRepository {
333
412
  });
334
413
  }
335
414
  deleteByName(params) {
415
+ var _a, _b;
336
416
  return __awaiter(this, void 0, void 0, function* () {
337
- return this.taskModel.deleteMany({
338
- name: { $eq: params.name }
339
- })
417
+ return this.taskModel.deleteMany(Object.assign(Object.assign({ name: { $eq: params.name } }, (typeof ((_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { status: { $eq: params.status.$eq } } : undefined), (((_b = params.runsAt) === null || _b === void 0 ? void 0 : _b.$gte) instanceof Date)
418
+ ? {
419
+ runsAt: { $gte: params.runsAt.$gte, $lte: params.runsAt.$lte }
420
+ }
421
+ : undefined))
340
422
  .exec();
341
423
  });
342
424
  }
@@ -345,10 +427,7 @@ class MongoRepository {
345
427
  const runsAtLt = moment()
346
428
  .add(-params.delayInSeconds, 'seconds')
347
429
  .toDate();
348
- return this.taskModel.count({
349
- status: factory.taskStatus.Ready,
350
- runsAt: { $lt: runsAtLt }
351
- })
430
+ return this.taskModel.count(Object.assign({ status: factory.taskStatus.Ready, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined))
352
431
  .exec();
353
432
  });
354
433
  }
@@ -40,6 +40,8 @@ export declare class MongoRepository {
40
40
  findById<T extends factory.transactionType>(params: {
41
41
  typeOf: T;
42
42
  id: string;
43
+ inclusion?: string[];
44
+ exclusion?: string[];
43
45
  }): Promise<factory.transaction.ITransaction<T>>;
44
46
  /**
45
47
  * 進行中の取引を取得する
@@ -111,7 +113,13 @@ export declare class MongoRepository {
111
113
  $in: T[];
112
114
  };
113
115
  status: factory.transactionStatusType;
114
- }): Promise<factory.transaction.ITransaction<T> | null>;
116
+ id?: string;
117
+ tasksExportAction: {
118
+ agent: {
119
+ name: string;
120
+ };
121
+ };
122
+ }): Promise<Pick<factory.transaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
115
123
  /**
116
124
  * タスクエクスポートリトライ
117
125
  * TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
@@ -119,6 +127,16 @@ export declare class MongoRepository {
119
127
  reexportTasks(params: {
120
128
  intervalInMinutes: number;
121
129
  }): Promise<void>;
130
+ /**
131
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
132
+ */
133
+ exportTasks(params: {
134
+ now: Date;
135
+ delayInSeconds: number;
136
+ status: {
137
+ $in: factory.transactionStatusType[];
138
+ };
139
+ }): Promise<Pick<import("@chevre/factory/lib/transaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/transaction/placeOrder").ITransaction | import("@chevre/factory/lib/transaction/returnOrder").ITransaction, "id" | "typeOf" | "status">[]>;
122
140
  /**
123
141
  * set task status exported by transaction id
124
142
  * IDでタスクをエクスポート済に変更する
@@ -130,7 +148,9 @@ export declare class MongoRepository {
130
148
  * 取引を期限切れにする
131
149
  */
132
150
  makeExpired(params: {
133
- expires: Date;
151
+ expires: {
152
+ $lt: Date;
153
+ };
134
154
  }): Promise<void>;
135
155
  /**
136
156
  * 取引を中止する
@@ -150,7 +170,7 @@ export declare class MongoRepository {
150
170
  /**
151
171
  * 特定の取引を更新する(汎用)
152
172
  */
153
- findByIdAndUpdate(params: {
173
+ findByIdAndUpdateInProgress(params: {
154
174
  id: string;
155
175
  update: {
156
176
  $set?: any;
@@ -13,6 +13,8 @@ exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../factory");
15
15
  const transaction_1 = require("./mongoose/schemas/transaction");
16
+ const transaction_2 = require("../eventEmitter/transaction");
17
+ const settings_1 = require("../settings");
16
18
  /**
17
19
  * 取引リポジトリ
18
20
  */
@@ -263,7 +265,9 @@ class MongoRepository {
263
265
  else {
264
266
  expires = params.expires;
265
267
  }
266
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate, endDate: undefined, expires, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
268
+ return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate, endDate: undefined, expires, tasksExportAction: {
269
+ actionStatus: factory.actionStatusType.PotentialActionStatus
270
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
267
271
  .then((doc) => doc.toObject());
268
272
  });
269
273
  }
@@ -272,10 +276,29 @@ class MongoRepository {
272
276
  */
273
277
  findById(params) {
274
278
  return __awaiter(this, void 0, void 0, function* () {
279
+ let projection = {};
280
+ if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
281
+ params.inclusion.forEach((field) => {
282
+ projection[field] = 1;
283
+ });
284
+ }
285
+ else {
286
+ projection = {
287
+ __v: 0,
288
+ createdAt: 0,
289
+ updatedAt: 0
290
+ };
291
+ if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
292
+ params.exclusion.forEach((field) => {
293
+ projection[field] = 0;
294
+ });
295
+ }
296
+ }
275
297
  const doc = yield this.transactionModel.findOne({
276
298
  _id: { $eq: params.id },
277
299
  typeOf: { $eq: params.typeOf }
278
300
  })
301
+ .select(projection)
279
302
  .exec();
280
303
  if (doc === null) {
281
304
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -291,7 +314,9 @@ class MongoRepository {
291
314
  const doc = yield this.transactionModel.findOne({
292
315
  _id: { $eq: params.id },
293
316
  typeOf: { $eq: params.typeOf },
294
- status: { $eq: factory.transactionStatusType.InProgress }
317
+ status: { $eq: factory.transactionStatusType.InProgress },
318
+ // expiresを条件に追加(2023-05-12~),
319
+ expires: { $gt: new Date() }
295
320
  })
296
321
  .exec();
297
322
  if (doc === null) {
@@ -343,9 +368,9 @@ class MongoRepository {
343
368
  var _a, _b;
344
369
  return __awaiter(this, void 0, void 0, function* () {
345
370
  const doc = yield this.transactionModel.findOneAndUpdate({
346
- _id: params.id,
347
- typeOf: params.typeOf,
348
- status: factory.transactionStatusType.InProgress
371
+ _id: { $eq: params.id },
372
+ typeOf: { $eq: params.typeOf },
373
+ status: { $eq: factory.transactionStatusType.InProgress }
349
374
  }, {
350
375
  $set: Object.assign(Object.assign({ 'agent.id': params.agent.id }, (typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined), (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { 'object.customer': params.object.customer } : undefined)
351
376
  }, {
@@ -363,9 +388,9 @@ class MongoRepository {
363
388
  updateExpires(params) {
364
389
  return __awaiter(this, void 0, void 0, function* () {
365
390
  const doc = yield this.transactionModel.findOneAndUpdate({
366
- _id: params.id,
367
- typeOf: params.typeOf,
368
- status: factory.transactionStatusType.InProgress
391
+ _id: { $eq: params.id },
392
+ typeOf: { $eq: params.typeOf },
393
+ status: { $eq: factory.transactionStatusType.InProgress }
369
394
  }, {
370
395
  $set: {
371
396
  expires: params.expires
@@ -387,9 +412,9 @@ class MongoRepository {
387
412
  var _a;
388
413
  return __awaiter(this, void 0, void 0, function* () {
389
414
  const doc = yield this.transactionModel.findOneAndUpdate({
390
- _id: params.id,
391
- typeOf: params.typeOf,
392
- status: factory.transactionStatusType.InProgress
415
+ _id: { $eq: params.id },
416
+ typeOf: { $eq: params.typeOf },
417
+ status: { $eq: factory.transactionStatusType.InProgress }
393
418
  }, {
394
419
  $set: Object.assign({}, (typeof ((_a = params.object) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? { 'object.name': params.object.name } : undefined)
395
420
  }, {
@@ -407,9 +432,9 @@ class MongoRepository {
407
432
  confirm(params) {
408
433
  return __awaiter(this, void 0, void 0, function* () {
409
434
  const doc = yield this.transactionModel.findOneAndUpdate({
410
- _id: params.id,
411
- typeOf: params.typeOf,
412
- status: factory.transactionStatusType.InProgress
435
+ _id: { $eq: params.id },
436
+ typeOf: { $eq: params.typeOf },
437
+ status: { $eq: factory.transactionStatusType.InProgress }
413
438
  }, {
414
439
  status: factory.transactionStatusType.Confirmed,
415
440
  endDate: new Date(),
@@ -424,43 +449,49 @@ class MongoRepository {
424
449
  // NotFoundであれば取引状態確認
425
450
  if (doc === null) {
426
451
  const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
427
- // tslint:disable-next-line:no-single-line-block-comment
428
- /* istanbul ignore next */
429
452
  if (transaction.status === factory.transactionStatusType.Confirmed) {
430
- // すでに確定済の場合
431
- return;
432
- // tslint:disable-next-line:no-single-line-block-comment
433
- /* istanbul ignore next */
453
+ // すでに確定済の場合スルー
434
454
  }
435
455
  else if (transaction.status === factory.transactionStatusType.Expired) {
436
456
  throw new factory.errors.Argument('Transaction id', 'Already expired');
437
- // tslint:disable-next-line:no-single-line-block-comment
438
- /* istanbul ignore next */
439
457
  }
440
458
  else if (transaction.status === factory.transactionStatusType.Canceled) {
441
459
  throw new factory.errors.Argument('Transaction id', 'Already canceled');
442
- // tslint:disable-next-line:no-single-line-block-comment
443
- /* istanbul ignore next */
444
460
  }
445
461
  else {
446
462
  throw new factory.errors.NotFound(this.transactionModel.modelName);
447
463
  }
448
464
  }
449
- // return doc.toObject();
465
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
466
+ id: params.id,
467
+ typeOf: params.typeOf,
468
+ status: factory.transactionStatusType.Confirmed
469
+ });
450
470
  });
451
471
  }
452
472
  /**
453
473
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
454
474
  */
455
475
  startExportTasks(params) {
476
+ var _a;
456
477
  return __awaiter(this, void 0, void 0, function* () {
457
- return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({}, (params.project !== undefined)
458
- ? {
459
- 'project.id': {
460
- $eq: params.project.id
461
- }
462
- } : undefined), (params.typeOf !== undefined && params.typeOf !== null && Array.isArray(params.typeOf.$in))
463
- ? { typeOf: { $in: params.typeOf.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
478
+ switch (params.status) {
479
+ case factory.transactionStatusType.InProgress:
480
+ throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
481
+ default:
482
+ // no op
483
+ }
484
+ const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
485
+ return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.project !== undefined) ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
486
+ 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
487
+ 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
488
+ 'tasksExportAction.startDate': new Date(),
489
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
490
+ }, { new: true })
491
+ .select({
492
+ _id: 1,
493
+ typeOf: 1
494
+ })
464
495
  .exec()
465
496
  // tslint:disable-next-line:no-null-keyword
466
497
  .then((doc) => (doc === null) ? null : doc.toObject());
@@ -473,17 +504,74 @@ class MongoRepository {
473
504
  */
474
505
  reexportTasks(params) {
475
506
  return __awaiter(this, void 0, void 0, function* () {
476
- yield this.transactionModel.updateMany({
477
- tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
507
+ const reexportingTransactions = yield this.transactionModel.find({
508
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
478
509
  updatedAt: {
479
510
  $lt: moment()
480
511
  .add(-params.intervalInMinutes, 'minutes')
481
512
  .toDate()
482
513
  }
483
- }, {
484
- tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
485
514
  })
515
+ .select({
516
+ _id: 1,
517
+ typeOf: 1,
518
+ status: 1
519
+ })
520
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
521
+ .exec();
522
+ if (reexportingTransactions.length > 0) {
523
+ for (const reexportingTransaction of reexportingTransactions) {
524
+ yield this.transactionModel.updateOne({
525
+ _id: { $eq: reexportingTransaction.id },
526
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
527
+ }, {
528
+ tasksExportAction: {
529
+ actionStatus: factory.actionStatusType.PotentialActionStatus
530
+ },
531
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
532
+ })
533
+ .exec();
534
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
535
+ id: reexportingTransaction.id,
536
+ typeOf: reexportingTransaction.typeOf,
537
+ status: reexportingTransaction.status
538
+ });
539
+ }
540
+ }
541
+ });
542
+ }
543
+ /**
544
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
545
+ */
546
+ exportTasks(params) {
547
+ return __awaiter(this, void 0, void 0, function* () {
548
+ const delayedTransactions = yield this.transactionModel.find({
549
+ status: { $in: params.status.$in },
550
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported },
551
+ endDate: {
552
+ $exists: true,
553
+ $lt: moment(params.now)
554
+ .add(-params.delayInSeconds, 'seconds')
555
+ .toDate()
556
+ }
557
+ })
558
+ .select({
559
+ _id: 1,
560
+ typeOf: 1,
561
+ status: 1
562
+ })
563
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
486
564
  .exec();
565
+ if (delayedTransactions.length > 0) {
566
+ delayedTransactions.forEach((delayedTransaction) => {
567
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
568
+ id: delayedTransaction.id,
569
+ typeOf: delayedTransaction.typeOf,
570
+ status: delayedTransaction.status
571
+ });
572
+ });
573
+ }
574
+ return delayedTransactions;
487
575
  });
488
576
  }
489
577
  /**
@@ -492,9 +580,15 @@ class MongoRepository {
492
580
  */
493
581
  setTasksExportedById(params) {
494
582
  return __awaiter(this, void 0, void 0, function* () {
495
- yield this.transactionModel.findByIdAndUpdate(params.id, {
583
+ const endDate = new Date();
584
+ yield this.transactionModel.updateOne({
585
+ _id: { $eq: params.id },
586
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
587
+ }, {
496
588
  tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
497
- tasksExportedAt: new Date()
589
+ tasksExportedAt: endDate,
590
+ 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
591
+ 'tasksExportAction.endDate': endDate
498
592
  })
499
593
  .exec();
500
594
  });
@@ -504,15 +598,36 @@ class MongoRepository {
504
598
  */
505
599
  makeExpired(params) {
506
600
  return __awaiter(this, void 0, void 0, function* () {
507
- // ステータスと期限を見て更新
508
- yield this.transactionModel.updateMany({
509
- status: factory.transactionStatusType.InProgress,
510
- expires: { $lt: params.expires }
511
- }, {
512
- status: factory.transactionStatusType.Expired,
513
- endDate: new Date()
601
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
602
+ const expiringTransactions = yield this.transactionModel.find({
603
+ status: { $eq: factory.transactionStatusType.InProgress },
604
+ expires: { $lt: params.expires.$lt }
605
+ })
606
+ .select({
607
+ _id: 1,
608
+ typeOf: 1
514
609
  })
610
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
515
611
  .exec();
612
+ if (expiringTransactions.length > 0) {
613
+ // ステータスと期限を見て更新
614
+ yield this.transactionModel.updateMany({
615
+ _id: { $in: expiringTransactions.map((t) => t.id) },
616
+ status: { $eq: factory.transactionStatusType.InProgress },
617
+ expires: { $lt: params.expires.$lt }
618
+ }, {
619
+ status: factory.transactionStatusType.Expired,
620
+ endDate: new Date()
621
+ })
622
+ .exec();
623
+ expiringTransactions.forEach((expiringTransaction) => {
624
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
625
+ id: expiringTransaction.id,
626
+ typeOf: expiringTransaction.typeOf,
627
+ status: factory.transactionStatusType.Expired
628
+ });
629
+ });
630
+ }
516
631
  });
517
632
  }
518
633
  /**
@@ -537,11 +652,8 @@ class MongoRepository {
537
652
  // NotFoundであれば取引状態確認
538
653
  if (doc === null) {
539
654
  const transaction = yield this.findById(params);
540
- // tslint:disable-next-line:no-single-line-block-comment
541
- /* istanbul ignore next */
542
655
  if (transaction.status === factory.transactionStatusType.Canceled) {
543
- // すでに中止済の場合
544
- return;
656
+ // すでに中止済の場合スルー
545
657
  }
546
658
  else if (transaction.status === factory.transactionStatusType.Expired) {
547
659
  throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
@@ -553,14 +665,18 @@ class MongoRepository {
553
665
  throw new factory.errors.NotFound(this.transactionModel.modelName);
554
666
  }
555
667
  }
556
- // return doc.toObject();
668
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
669
+ id: params.id,
670
+ typeOf: params.typeOf,
671
+ status: factory.transactionStatusType.Canceled
672
+ });
557
673
  });
558
674
  }
559
675
  count(params) {
560
676
  return __awaiter(this, void 0, void 0, function* () {
561
677
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
562
678
  return this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
563
- .setOptions({ maxTimeMS: 10000 })
679
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
564
680
  .exec();
565
681
  });
566
682
  }
@@ -603,7 +719,7 @@ class MongoRepository {
603
719
  }
604
720
  // const explainResult = await (<any>query).explain();
605
721
  // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
606
- return query.setOptions({ maxTimeMS: 10000 })
722
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
607
723
  .exec()
608
724
  .then((docs) => docs.map((doc) => doc.toObject()));
609
725
  });
@@ -611,9 +727,12 @@ class MongoRepository {
611
727
  /**
612
728
  * 特定の取引を更新する(汎用)
613
729
  */
614
- findByIdAndUpdate(params) {
730
+ findByIdAndUpdateInProgress(params) {
615
731
  return __awaiter(this, void 0, void 0, function* () {
616
- yield this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, {
732
+ yield this.transactionModel.findOneAndUpdate({
733
+ _id: { $eq: params.id },
734
+ status: { $eq: factory.transactionStatusType.InProgress }
735
+ }, params.update, {
617
736
  // new: true,
618
737
  projection: { _id: 1 }
619
738
  })
@@ -628,7 +747,8 @@ class MongoRepository {
628
747
  saveOrderNumberIfNotExist(params) {
629
748
  return __awaiter(this, void 0, void 0, function* () {
630
749
  yield this.transactionModel.updateOne({
631
- _id: params.id,
750
+ _id: { $eq: params.id },
751
+ status: { $eq: factory.transactionStatusType.InProgress },
632
752
  'object.orderNumber': { $exists: false }
633
753
  }, { 'object.orderNumber': params.orderNumber })
634
754
  .exec();
@@ -637,7 +757,8 @@ class MongoRepository {
637
757
  saveConfirmationNumberIfNotExist(params) {
638
758
  return __awaiter(this, void 0, void 0, function* () {
639
759
  yield this.transactionModel.updateOne({
640
- _id: params.id,
760
+ _id: { $eq: params.id },
761
+ status: { $eq: factory.transactionStatusType.InProgress },
641
762
  'object.confirmationNumber': { $exists: false }
642
763
  }, { 'object.confirmationNumber': params.confirmationNumber })
643
764
  .exec();
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
24
  const factory = require("../factory");
25
25
  const trip_1 = require("./mongoose/schemas/trip");
26
+ const settings_1 = require("../settings");
26
27
  /**
27
28
  * トリップリポジトリ
28
29
  */
@@ -193,7 +194,7 @@ class MongoRepository {
193
194
  // console.log(explainResult[0].queryPlanner?.winningPlan?.inputStage?.inputStage?.inputStage);
194
195
  // console.log(explainResult);
195
196
  // return [];
196
- return query.setOptions({ maxTimeMS: 10000 })
197
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
197
198
  .exec()
198
199
  .then((docs) => docs.map((doc) => doc.toObject()));
199
200
  });