@chevre/domain 21.2.0-alpha.11 → 21.2.0-alpha.111

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 (277) hide show
  1. package/example/src/chevre/aggregation/aggregateSystem.ts +85 -27
  2. package/example/src/chevre/deleteTasksByName.ts +10 -2
  3. package/example/src/chevre/importEventsFromCOA.ts +3 -4
  4. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  5. package/example/src/chevre/processPay.ts +5 -1
  6. package/example/src/chevre/processRegisterMembership.ts +8 -4
  7. package/example/src/chevre/processRegisterPaymentCard.ts +8 -4
  8. package/example/src/chevre/processReserve.ts +4 -1
  9. package/example/src/chevre/saveTasks.ts +13 -10
  10. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  11. package/example/src/chevre/searchActions.ts +33 -0
  12. package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +37 -1
  13. package/example/src/chevre/searchSendEmailActions.ts +44 -0
  14. package/example/src/chevre/task/executeTasks.ts +26 -0
  15. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  16. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  17. package/example/src/chevre/transaction/processReturnOrder.ts +40 -0
  18. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  19. package/example/src/chevre/updateTransaction.ts +1 -1
  20. package/example/src/playOnMoment.ts +24 -0
  21. package/lib/chevre/credentials.d.ts +1 -0
  22. package/lib/chevre/credentials.js +2 -1
  23. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  24. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  25. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  26. package/lib/chevre/eventEmitter/task.js +25 -0
  27. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  28. package/lib/chevre/eventEmitter/transaction.js +25 -0
  29. package/lib/chevre/eventEmitter.d.ts +4 -0
  30. package/lib/chevre/eventEmitter.js +9 -0
  31. package/lib/chevre/index.d.ts +3 -2
  32. package/lib/chevre/index.js +5 -3
  33. package/lib/chevre/repo/account.js +3 -2
  34. package/lib/chevre/repo/accountTransaction.d.ts +3 -11
  35. package/lib/chevre/repo/accountTransaction.js +3 -55
  36. package/lib/chevre/repo/action.d.ts +42 -2
  37. package/lib/chevre/repo/action.js +130 -57
  38. package/lib/chevre/repo/additionalProperty.js +2 -1
  39. package/lib/chevre/repo/aggregation.d.ts +3 -0
  40. package/lib/chevre/repo/aggregation.js +3 -0
  41. package/lib/chevre/repo/assetTransaction.d.ts +25 -9
  42. package/lib/chevre/repo/assetTransaction.js +259 -87
  43. package/lib/chevre/repo/categoryCode.d.ts +1 -1
  44. package/lib/chevre/repo/categoryCode.js +37 -25
  45. package/lib/chevre/repo/code.js +3 -2
  46. package/lib/chevre/repo/comment.d.ts +4 -1
  47. package/lib/chevre/repo/comment.js +22 -6
  48. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  49. package/lib/chevre/repo/confirmationNumber.js +3 -15
  50. package/lib/chevre/repo/creativeWork.d.ts +2 -4
  51. package/lib/chevre/repo/creativeWork.js +35 -12
  52. package/lib/chevre/repo/customer.js +2 -1
  53. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  54. package/lib/chevre/repo/emailMessage.js +2 -1
  55. package/lib/chevre/repo/event.d.ts +5 -1
  56. package/lib/chevre/repo/event.js +4 -3
  57. package/lib/chevre/repo/member.js +4 -3
  58. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  59. package/lib/chevre/repo/merchantReturnPolicy.js +2 -1
  60. package/lib/chevre/repo/mongoose/schemas/account.d.ts +4 -2
  61. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +29 -3
  62. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +31 -3
  63. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
  64. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +13 -3
  65. package/lib/chevre/repo/mongoose/schemas/action.d.ts +43 -3
  66. package/lib/chevre/repo/mongoose/schemas/action.js +19 -1
  67. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +17 -3
  68. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +4 -2
  69. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +44 -3
  70. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +32 -19
  71. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +19 -3
  72. package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
  73. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +25 -3
  74. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +27 -3
  75. package/lib/chevre/repo/mongoose/schemas/comments.js +1 -1
  76. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +43 -3
  77. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +25 -3
  78. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +21 -3
  79. package/lib/chevre/repo/mongoose/schemas/event.d.ts +71 -3
  80. package/lib/chevre/repo/mongoose/schemas/member.d.ts +13 -3
  81. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +21 -3
  82. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +65 -3
  83. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +27 -3
  84. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +74 -0
  85. package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +45 -0
  86. package/lib/chevre/repo/mongoose/schemas/order.d.ts +51 -3
  87. package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
  88. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +25 -3
  89. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +1 -1
  90. package/lib/chevre/repo/mongoose/schemas/place.d.ts +49 -3
  91. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +29 -3
  92. package/lib/chevre/repo/mongoose/schemas/product.d.ts +31 -3
  93. package/lib/chevre/repo/mongoose/schemas/project.d.ts +23 -3
  94. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +63 -5
  95. package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
  96. package/lib/chevre/repo/mongoose/schemas/role.d.ts +11 -3
  97. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +31 -3
  98. package/lib/chevre/repo/mongoose/schemas/seller.js +6 -0
  99. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +11 -3
  100. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +1 -1
  101. package/lib/chevre/repo/mongoose/schemas/task.d.ts +30 -3
  102. package/lib/chevre/repo/mongoose/schemas/task.js +2 -1
  103. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +21 -3
  104. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +40 -3
  105. package/lib/chevre/repo/mongoose/schemas/transaction.js +2 -1
  106. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +11 -3
  107. package/lib/chevre/repo/offer.js +3 -2
  108. package/lib/chevre/repo/offerCatalog.js +0 -27
  109. package/lib/chevre/repo/offerItemCondition.d.ts +22 -0
  110. package/lib/chevre/repo/offerItemCondition.js +121 -0
  111. package/lib/chevre/repo/order.d.ts +55 -3
  112. package/lib/chevre/repo/order.js +62 -10
  113. package/lib/chevre/repo/ownershipInfo.js +2 -7
  114. package/lib/chevre/repo/place.js +3 -2
  115. package/lib/chevre/repo/priceSpecification.js +3 -2
  116. package/lib/chevre/repo/product.d.ts +1 -3
  117. package/lib/chevre/repo/product.js +25 -4
  118. package/lib/chevre/repo/project.js +2 -1
  119. package/lib/chevre/repo/reservation.d.ts +20 -4
  120. package/lib/chevre/repo/reservation.js +40 -59
  121. package/lib/chevre/repo/role.js +3 -2
  122. package/lib/chevre/repo/seller.d.ts +1 -1
  123. package/lib/chevre/repo/seller.js +44 -23
  124. package/lib/chevre/repo/serviceOutput.js +2 -1
  125. package/lib/chevre/repo/task.d.ts +42 -2
  126. package/lib/chevre/repo/task.js +93 -11
  127. package/lib/chevre/repo/transaction.d.ts +23 -4
  128. package/lib/chevre/repo/transaction.js +179 -60
  129. package/lib/chevre/repo/trip.js +2 -1
  130. package/lib/chevre/repository.d.ts +5 -2
  131. package/lib/chevre/repository.js +8 -4
  132. package/lib/chevre/service/aggregation/system.d.ts +110 -23
  133. package/lib/chevre/service/aggregation/system.js +213 -91
  134. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -28
  135. package/lib/chevre/service/assetTransaction/moneyTransfer.js +2 -24
  136. package/lib/chevre/service/assetTransaction/pay/account/validation.js +1 -1
  137. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +17 -1
  138. package/lib/chevre/service/assetTransaction/pay.d.ts +5 -1
  139. package/lib/chevre/service/assetTransaction/pay.js +20 -34
  140. package/lib/chevre/service/assetTransaction/refund.js +2 -24
  141. package/lib/chevre/service/assetTransaction/registerService.js +1 -25
  142. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +15 -5
  143. package/lib/chevre/service/assetTransaction/reserve/factory.js +122 -58
  144. package/lib/chevre/service/assetTransaction/reserve.d.ts +10 -1
  145. package/lib/chevre/service/assetTransaction/reserve.js +85 -69
  146. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  147. package/lib/chevre/service/assetTransaction.js +9 -5
  148. package/lib/chevre/service/event.js +16 -5
  149. package/lib/chevre/service/notification/factory.js +2 -2
  150. package/lib/chevre/service/notification.d.ts +3 -1
  151. package/lib/chevre/service/notification.js +41 -7
  152. package/lib/chevre/service/offer/event/authorize.d.ts +3 -0
  153. package/lib/chevre/service/offer/event/authorize.js +8 -2
  154. package/lib/chevre/service/offer/event/factory.d.ts +3 -0
  155. package/lib/chevre/service/offer/event/factory.js +16 -5
  156. package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
  157. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  158. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  159. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -9
  160. package/lib/chevre/service/offer/product.js +2 -2
  161. package/lib/chevre/service/offer.d.ts +16 -8
  162. package/lib/chevre/service/offer.js +69 -8
  163. package/lib/chevre/service/order/deleteOrder.d.ts +3 -1
  164. package/lib/chevre/service/order/deleteOrder.js +8 -8
  165. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +5 -2
  166. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +41 -81
  167. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -3
  168. package/lib/chevre/service/order/onOrderUpdated.d.ts +16 -0
  169. package/lib/chevre/service/order/onOrderUpdated.js +22 -0
  170. package/lib/chevre/service/order/placeOrder.d.ts +1 -0
  171. package/lib/chevre/service/order/placeOrder.js +41 -24
  172. package/lib/chevre/service/order/returnOrder.d.ts +1 -0
  173. package/lib/chevre/service/order/returnOrder.js +7 -12
  174. package/lib/chevre/service/order/sendOrder.d.ts +1 -0
  175. package/lib/chevre/service/order/sendOrder.js +7 -10
  176. package/lib/chevre/service/order.d.ts +2 -1
  177. package/lib/chevre/service/order.js +3 -1
  178. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  179. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  180. package/lib/chevre/service/payment/any.d.ts +9 -5
  181. package/lib/chevre/service/payment/any.js +80 -18
  182. package/lib/chevre/service/payment/creditCard.d.ts +1 -1
  183. package/lib/chevre/service/payment/creditCard.js +23 -17
  184. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +8 -7
  185. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  186. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +1 -1
  187. package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -1
  188. package/lib/chevre/service/payment/movieTicket/validation.d.ts +6 -6
  189. package/lib/chevre/service/payment/movieTicket/validation.js +55 -32
  190. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  191. package/lib/chevre/service/payment/movieTicket.js +7 -6
  192. package/lib/chevre/service/product.js +1 -5
  193. package/lib/chevre/service/report/telemetry.d.ts +0 -11
  194. package/lib/chevre/service/report/telemetry.js +21 -24
  195. package/lib/chevre/service/reserve/cancelReservation.d.ts +5 -3
  196. package/lib/chevre/service/reserve/cancelReservation.js +147 -139
  197. package/lib/chevre/service/reserve/checkInReservation.d.ts +9 -4
  198. package/lib/chevre/service/reserve/checkInReservation.js +77 -3
  199. package/lib/chevre/service/reserve/confirmReservation.d.ts +7 -4
  200. package/lib/chevre/service/reserve/confirmReservation.js +133 -58
  201. package/lib/chevre/service/reserve/factory.d.ts +1 -1
  202. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +17 -5
  203. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +26 -24
  204. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -3
  205. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  206. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -3
  207. package/lib/chevre/service/reserve/useReservation.d.ts +7 -3
  208. package/lib/chevre/service/reserve/useReservation.js +61 -71
  209. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +15 -0
  210. package/lib/chevre/service/reserve/verifyToken4reservation.js +56 -0
  211. package/lib/chevre/service/reserve.d.ts +3 -2
  212. package/lib/chevre/service/reserve.js +4 -2
  213. package/lib/chevre/service/task/cancelPendingReservation.js +5 -1
  214. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  215. package/lib/chevre/service/task/deleteTransaction.js +10 -8
  216. package/lib/chevre/service/task/importOffersFromCOA.js +4 -0
  217. package/lib/chevre/service/task/onAuthorizationCreated.d.ts +7 -0
  218. package/lib/chevre/service/task/onAuthorizationCreated.js +108 -0
  219. package/lib/chevre/service/task/onEventChanged.d.ts +7 -0
  220. package/lib/chevre/service/task/{deleteOrder.js → onEventChanged.js} +8 -14
  221. package/lib/chevre/service/task/onResourceUpdated.d.ts +7 -0
  222. package/lib/chevre/service/task/onResourceUpdated.js +199 -0
  223. package/lib/chevre/service/task/placeOrder.js +1 -1
  224. package/lib/chevre/service/task/reserve.js +10 -7
  225. package/lib/chevre/service/task/returnOrder.js +1 -1
  226. package/lib/chevre/service/task/returnPayTransaction.js +2 -12
  227. package/lib/chevre/service/task/sendOrder.js +1 -1
  228. package/lib/chevre/service/task/useReservation.d.ts +7 -0
  229. package/lib/chevre/service/task/useReservation.js +36 -0
  230. package/lib/chevre/service/task/voidReserveTransaction.js +3 -1
  231. package/lib/chevre/service/task.d.ts +9 -0
  232. package/lib/chevre/service/task.js +43 -4
  233. package/lib/chevre/service/transaction/deleteTransaction.d.ts +21 -0
  234. package/lib/chevre/service/transaction/deleteTransaction.js +232 -0
  235. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +11 -1
  236. package/lib/chevre/service/transaction/moneyTransfer/factory.d.ts +1 -1
  237. package/lib/chevre/service/transaction/moneyTransfer/factory.js +3 -1
  238. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -0
  239. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +1 -1
  240. package/lib/chevre/service/transaction/moneyTransfer.js +10 -13
  241. package/lib/chevre/service/transaction/orderProgramMembership/findCreditCard.js +1 -1
  242. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +1 -1
  243. package/lib/chevre/service/transaction/orderProgramMembership.js +7 -3
  244. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +42 -30
  245. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  246. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +1 -1
  247. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.d.ts +1 -0
  248. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  249. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +1 -0
  250. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  251. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +1 -0
  252. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.d.ts +3 -0
  253. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +7 -3
  254. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -0
  255. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +2 -2
  256. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.d.ts +1 -1
  257. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +2 -2
  258. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +2 -1
  259. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +23 -17
  260. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +0 -3
  261. package/lib/chevre/service/transaction/placeOrderInProgress.js +28 -15
  262. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +10 -1
  263. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +25 -17
  264. package/lib/chevre/service/transaction/returnOrder.d.ts +4 -0
  265. package/lib/chevre/service/transaction/returnOrder.js +228 -36
  266. package/lib/chevre/service/transaction.d.ts +8 -13
  267. package/lib/chevre/service/transaction.js +12 -145
  268. package/lib/chevre/settings.d.ts +11 -1
  269. package/lib/chevre/settings.js +50 -6
  270. package/package.json +5 -5
  271. package/example/src/chevre/createManyEventsIfNotExist.ts +0 -205
  272. package/example/src/chevre/eventCatalog2eventService.ts +0 -123
  273. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  274. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
  275. package/lib/chevre/service/task/deleteAssetTransaction.d.ts +0 -12
  276. package/lib/chevre/service/task/deleteAssetTransaction.js +0 -65
  277. 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 assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
15
15
  const factory = require("../factory");
16
+ const assetTransaction_2 = require("../eventEmitter/assetTransaction");
17
+ const settings_1 = require("../settings");
16
18
  /**
17
19
  * 資産取引リポジトリ
18
20
  */
@@ -22,7 +24,7 @@ class MongoRepository {
22
24
  }
23
25
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
24
26
  static CREATE_MONGO_CONDITIONS(params) {
25
- 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;
27
+ 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;
26
28
  const andConditions = [
27
29
  {
28
30
  typeOf: params.typeOf
@@ -132,15 +134,18 @@ class MongoRepository {
132
134
  const objectPaymentMethodIdEq4refund = (_j = (_h = params.object) === null || _h === void 0 ? void 0 : _h.paymentMethodId) === null || _j === void 0 ? void 0 : _j.$eq;
133
135
  if (typeof objectPaymentMethodIdEq4refund === 'string') {
134
136
  andConditions.push({
135
- 'object.paymentMethodId': {
136
- $exists: true,
137
- $eq: objectPaymentMethodIdEq4refund
138
- }
137
+ 'object.paymentMethodId': { $exists: true, $eq: objectPaymentMethodIdEq4refund }
138
+ });
139
+ }
140
+ const objectPaymentMethodIdIn4refund = (_l = (_k = params.object) === null || _k === void 0 ? void 0 : _k.paymentMethodId) === null || _l === void 0 ? void 0 : _l.$in;
141
+ if (Array.isArray(objectPaymentMethodIdIn4refund)) {
142
+ andConditions.push({
143
+ 'object.paymentMethodId': { $exists: true, $in: objectPaymentMethodIdIn4refund }
139
144
  });
140
145
  }
141
146
  break;
142
147
  case factory.assetTransactionType.MoneyTransfer:
143
- const fromLocationIdentifierEq = (_m = (_l = (_k = params.object) === null || _k === void 0 ? void 0 : _k.fromLocation) === null || _l === void 0 ? void 0 : _l.identifier) === null || _m === void 0 ? void 0 : _m.$eq;
148
+ const fromLocationIdentifierEq = (_p = (_o = (_m = params.object) === null || _m === void 0 ? void 0 : _m.fromLocation) === null || _o === void 0 ? void 0 : _o.identifier) === null || _p === void 0 ? void 0 : _p.$eq;
144
149
  if (typeof fromLocationIdentifierEq === 'string') {
145
150
  andConditions.push({
146
151
  'object.fromLocation.identifier': {
@@ -149,7 +154,7 @@ class MongoRepository {
149
154
  }
150
155
  });
151
156
  }
152
- const toLocationIdentifierEq = (_q = (_p = (_o = params.object) === null || _o === void 0 ? void 0 : _o.toLocation) === null || _p === void 0 ? void 0 : _p.identifier) === null || _q === void 0 ? void 0 : _q.$eq;
157
+ const toLocationIdentifierEq = (_s = (_r = (_q = params.object) === null || _q === void 0 ? void 0 : _q.toLocation) === null || _r === void 0 ? void 0 : _r.identifier) === null || _s === void 0 ? void 0 : _s.$eq;
153
158
  if (typeof toLocationIdentifierEq === 'string') {
154
159
  andConditions.push({
155
160
  'object.toLocation.identifier': {
@@ -158,7 +163,7 @@ class MongoRepository {
158
163
  }
159
164
  });
160
165
  }
161
- const pendingTransactionIdentifierEq = (_t = (_s = (_r = params.object) === null || _r === void 0 ? void 0 : _r.pendingTransaction) === null || _s === void 0 ? void 0 : _s.identifier) === null || _t === void 0 ? void 0 : _t.$eq;
166
+ const pendingTransactionIdentifierEq = (_v = (_u = (_t = params.object) === null || _t === void 0 ? void 0 : _t.pendingTransaction) === null || _u === void 0 ? void 0 : _u.identifier) === null || _v === void 0 ? void 0 : _v.$eq;
162
167
  if (typeof pendingTransactionIdentifierEq === 'string') {
163
168
  andConditions.push({
164
169
  'object.pendingTransaction.identifier': {
@@ -171,7 +176,25 @@ class MongoRepository {
171
176
  case factory.assetTransactionType.CancelReservation:
172
177
  break;
173
178
  case factory.assetTransactionType.Reserve:
174
- const objectReservationNumberEq = (_v = (_u = params.object) === null || _u === void 0 ? void 0 : _u.reservationNumber) === null || _v === void 0 ? void 0 : _v.$eq;
179
+ const objectReservationForIdEq = (_y = (_x = (_w = params.object) === null || _w === void 0 ? void 0 : _w.reservationFor) === null || _x === void 0 ? void 0 : _x.id) === null || _y === void 0 ? void 0 : _y.$eq;
180
+ if (typeof objectReservationForIdEq === 'string') {
181
+ andConditions.push({
182
+ 'object.reservationFor.id': {
183
+ $exists: true,
184
+ $eq: objectReservationForIdEq
185
+ }
186
+ });
187
+ }
188
+ const objectReservationNumberIn = (_0 = (_z = params.object) === null || _z === void 0 ? void 0 : _z.reservationNumber) === null || _0 === void 0 ? void 0 : _0.$in;
189
+ if (Array.isArray(objectReservationNumberIn)) {
190
+ andConditions.push({
191
+ 'object.reservationNumber': {
192
+ $exists: true,
193
+ $in: objectReservationNumberIn
194
+ }
195
+ });
196
+ }
197
+ const objectReservationNumberEq = (_2 = (_1 = params.object) === null || _1 === void 0 ? void 0 : _1.reservationNumber) === null || _2 === void 0 ? void 0 : _2.$eq;
175
198
  if (typeof objectReservationNumberEq === 'string') {
176
199
  andConditions.push({
177
200
  'object.reservationNumber': {
@@ -180,19 +203,17 @@ class MongoRepository {
180
203
  }
181
204
  });
182
205
  }
206
+ const objectSubReservationIdIn = (_5 = (_4 = (_3 = params.object) === null || _3 === void 0 ? void 0 : _3.reservations) === null || _4 === void 0 ? void 0 : _4.id) === null || _5 === void 0 ? void 0 : _5.$in;
207
+ if (Array.isArray(objectSubReservationIdIn)) {
208
+ andConditions.push({
209
+ 'object.subReservation.id': {
210
+ $exists: true,
211
+ $in: objectSubReservationIdIn
212
+ }
213
+ });
214
+ }
183
215
  if (params.object !== undefined) {
184
216
  if (params.object.reservations !== undefined) {
185
- if (params.object.reservations.id !== undefined) {
186
- if (Array.isArray(params.object.reservations.id.$in)) {
187
- andConditions.push({
188
- // 'object.reservations.id': {
189
- 'object.subReservation.id': {
190
- $exists: true,
191
- $in: params.object.reservations.id.$in
192
- }
193
- });
194
- }
195
- }
196
217
  if (params.object.reservations.reservationNumber !== undefined) {
197
218
  if (Array.isArray(params.object.reservations.reservationNumber.$in)) {
198
219
  andConditions.push({
@@ -217,9 +238,27 @@ class MongoRepository {
217
238
  }
218
239
  }
219
240
  }
241
+ const objectUnderNameIdEq = (_8 = (_7 = (_6 = params.object) === null || _6 === void 0 ? void 0 : _6.underName) === null || _7 === void 0 ? void 0 : _7.id) === null || _8 === void 0 ? void 0 : _8.$eq;
242
+ if (typeof objectUnderNameIdEq === 'string') {
243
+ andConditions.push({
244
+ 'object.underName.id': {
245
+ $exists: true,
246
+ $eq: objectUnderNameIdEq
247
+ }
248
+ });
249
+ }
250
+ const objectSubReservationSeatNumberEq = (_13 = (_12 = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.reservations) === null || _10 === void 0 ? void 0 : _10.reservedTicket) === null || _11 === void 0 ? void 0 : _11.ticketedSeat) === null || _12 === void 0 ? void 0 : _12.seatNumber) === null || _13 === void 0 ? void 0 : _13.$eq;
251
+ if (typeof objectSubReservationSeatNumberEq === 'string') {
252
+ andConditions.push({
253
+ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
254
+ $exists: true,
255
+ $eq: objectSubReservationSeatNumberEq
256
+ }
257
+ });
258
+ }
220
259
  break;
221
260
  case factory.assetTransactionType.RegisterService:
222
- const objectItemOfferedServiceOutputIdentifierEq = (_z = (_y = (_x = (_w = params.object) === null || _w === void 0 ? void 0 : _w.itemOffered) === null || _x === void 0 ? void 0 : _x.serviceOutput) === null || _y === void 0 ? void 0 : _y.identifier) === null || _z === void 0 ? void 0 : _z.$eq;
261
+ const objectItemOfferedServiceOutputIdentifierEq = (_17 = (_16 = (_15 = (_14 = params.object) === null || _14 === void 0 ? void 0 : _14.itemOffered) === null || _15 === void 0 ? void 0 : _15.serviceOutput) === null || _16 === void 0 ? void 0 : _16.identifier) === null || _17 === void 0 ? void 0 : _17.$eq;
223
262
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
224
263
  andConditions.push({
225
264
  'object.itemOffered.serviceOutput.identifier': {
@@ -228,7 +267,7 @@ class MongoRepository {
228
267
  }
229
268
  });
230
269
  }
231
- const objectItemOfferedServiceOutputIdentifierIn = (_3 = (_2 = (_1 = (_0 = params.object) === null || _0 === void 0 ? void 0 : _0.itemOffered) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.identifier) === null || _3 === void 0 ? void 0 : _3.$in;
270
+ const objectItemOfferedServiceOutputIdentifierIn = (_21 = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceOutput) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$in;
232
271
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
233
272
  andConditions.push({
234
273
  'object.itemOffered.serviceOutput.identifier': {
@@ -247,7 +286,9 @@ class MongoRepository {
247
286
  */
248
287
  start(params) {
249
288
  return __awaiter(this, void 0, void 0, function* () {
250
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate: new Date(), endDate: undefined, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
289
+ return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate: new Date(), endDate: undefined, tasksExportAction: {
290
+ actionStatus: factory.actionStatusType.PotentialActionStatus
291
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
251
292
  .then((doc) => doc.toObject());
252
293
  });
253
294
  }
@@ -277,26 +318,24 @@ class MongoRepository {
277
318
  return doc.toObject();
278
319
  });
279
320
  }
280
- /**
281
- * 取引を確定する
282
- */
283
321
  addReservations(params) {
322
+ var _a;
284
323
  return __awaiter(this, void 0, void 0, function* () {
285
324
  const doc = yield this.transactionModel.findOneAndUpdate({
286
- _id: params.id,
287
- typeOf: params.typeOf,
288
- status: factory.transactionStatusType.InProgress
289
- }, {
290
- 'object.acceptedOffer': params.object.acceptedOffer,
325
+ _id: { $eq: params.id },
326
+ typeOf: { $eq: params.typeOf },
327
+ status: { $eq: factory.transactionStatusType.InProgress }
328
+ }, Object.assign({ 'object.acceptedOffer': params.object.acceptedOffer,
291
329
  // 念のため残す(2021/10/14)が、そのうち削除
292
330
  // 冗長なので削除(2021/10/19~)
293
331
  // 'object.event': params.object.reservationFor,
294
- 'object.reservationFor': params.object.reservationFor,
332
+ 'object.reservationFor': params.object.reservationFor,
295
333
  // 念のため残す(2021/10/14)が、そのうち削除
296
334
  // 冗長なので削除(2021/10/19~)
297
335
  // 'object.reservations': params.object.subReservation,
298
- 'object.subReservation': params.object.subReservation
299
- }, { new: true })
336
+ 'object.subReservation': params.object.subReservation }, (typeof ((_a = params.object.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
337
+ ? { 'object.issuedThrough': params.object.issuedThrough }
338
+ : undefined), { new: true })
300
339
  .exec();
301
340
  if (doc === null) {
302
341
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -308,36 +347,40 @@ class MongoRepository {
308
347
  * 取引を確定する
309
348
  */
310
349
  confirm(params) {
350
+ var _a, _b;
311
351
  return __awaiter(this, void 0, void 0, function* () {
312
352
  const doc = yield this.transactionModel.findOneAndUpdate({
313
- _id: params.id,
314
- typeOf: params.typeOf,
315
- status: factory.transactionStatusType.InProgress
316
- }, {
317
- status: factory.transactionStatusType.Confirmed,
318
- endDate: new Date(),
319
- result: params.result,
320
- potentialActions: params.potentialActions // resultを更新
321
- }, { new: true })
353
+ _id: { $eq: params.id },
354
+ typeOf: { $eq: params.typeOf },
355
+ status: { $eq: factory.transactionStatusType.InProgress }
356
+ }, Object.assign({ status: factory.transactionStatusType.Confirmed, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
357
+ ? { 'object.underName': params.object.underName }
358
+ : undefined), {
359
+ new: true,
360
+ projection: { _id: 1 }
361
+ })
322
362
  .exec();
323
363
  // NotFoundであれば取引状態確認
324
364
  if (doc === null) {
325
365
  const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
326
366
  if (transaction.status === factory.transactionStatusType.Confirmed) {
327
- // すでに確定済の場合
328
- return transaction;
367
+ // すでに確定済の場合スルー
329
368
  }
330
369
  else if (transaction.status === factory.transactionStatusType.Expired) {
331
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
370
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
332
371
  }
333
372
  else if (transaction.status === factory.transactionStatusType.Canceled) {
334
- throw new factory.errors.Argument('Transaction id', 'Transaction already canceled');
373
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already canceled`);
335
374
  }
336
375
  else {
337
376
  throw new factory.errors.NotFound(this.transactionModel.modelName);
338
377
  }
339
378
  }
340
- return doc.toObject();
379
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
380
+ id: params.id,
381
+ typeOf: params.typeOf,
382
+ status: factory.transactionStatusType.Confirmed
383
+ });
341
384
  });
342
385
  }
343
386
  /**
@@ -345,23 +388,42 @@ class MongoRepository {
345
388
  */
346
389
  startAndConfirm(params) {
347
390
  return __awaiter(this, void 0, void 0, function* () {
348
- return this.transactionModel.create(Object.assign(Object.assign({ _id: params.id, typeOf: params.typeOf }, params), { startDate: new Date(), status: factory.transactionStatusType.Confirmed, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }))
391
+ const startDate = new Date();
392
+ const confirmedTransaction = yield this.transactionModel.create(Object.assign(Object.assign({}, params), { _id: params.id, typeOf: params.typeOf, startDate, status: factory.transactionStatusType.Confirmed, tasksExportAction: {
393
+ actionStatus: factory.actionStatusType.PotentialActionStatus
394
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: startDate, result: params.result, potentialActions: params.potentialActions }))
349
395
  .then((doc) => doc.toObject());
396
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
397
+ id: params.id,
398
+ typeOf: params.typeOf,
399
+ status: factory.transactionStatusType.Confirmed
400
+ });
401
+ return confirmedTransaction;
350
402
  });
351
403
  }
352
404
  /**
353
405
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
354
406
  */
355
407
  startExportTasks(params) {
356
- var _a, _b, _c;
408
+ var _a, _b;
357
409
  return __awaiter(this, void 0, void 0, function* () {
358
- return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({}, (typeof ((_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === 'string')
359
- ? {
360
- 'project.id': {
361
- $eq: params.project.id
362
- }
363
- } : undefined), (Array.isArray((_b = params.typeOf) === null || _b === void 0 ? void 0 : _b.$in))
364
- ? { typeOf: { $in: (_c = params.typeOf) === null || _c === void 0 ? void 0 : _c.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
410
+ switch (params.status) {
411
+ case factory.transactionStatusType.InProgress:
412
+ throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
413
+ default:
414
+ // no op
415
+ }
416
+ const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
417
+ return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === 'string') ? { '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), {
418
+ 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
419
+ 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
420
+ 'tasksExportAction.startDate': new Date(),
421
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
422
+ }, { new: true })
423
+ .select({
424
+ _id: 1,
425
+ typeOf: 1
426
+ })
365
427
  .exec()
366
428
  // tslint:disable-next-line:no-null-keyword
367
429
  .then((doc) => (doc === null) ? null : doc.toObject());
@@ -374,17 +436,74 @@ class MongoRepository {
374
436
  */
375
437
  reexportTasks(params) {
376
438
  return __awaiter(this, void 0, void 0, function* () {
377
- yield this.transactionModel.updateMany({
378
- tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
439
+ const reexportingTransactions = yield this.transactionModel.find({
440
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
379
441
  updatedAt: {
380
442
  $lt: moment()
381
443
  .add(-params.intervalInMinutes, 'minutes')
382
444
  .toDate()
383
445
  }
384
- }, {
385
- tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
386
446
  })
447
+ .select({
448
+ _id: 1,
449
+ typeOf: 1,
450
+ status: 1
451
+ })
452
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
453
+ .exec();
454
+ if (reexportingTransactions.length > 0) {
455
+ for (const reexportingTransaction of reexportingTransactions) {
456
+ yield this.transactionModel.updateOne({
457
+ _id: { $eq: reexportingTransaction.id },
458
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
459
+ }, {
460
+ tasksExportAction: {
461
+ actionStatus: factory.actionStatusType.PotentialActionStatus
462
+ },
463
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
464
+ })
465
+ .exec();
466
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
467
+ id: reexportingTransaction.id,
468
+ typeOf: reexportingTransaction.typeOf,
469
+ status: reexportingTransaction.status
470
+ });
471
+ }
472
+ }
473
+ });
474
+ }
475
+ /**
476
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
477
+ */
478
+ exportTasks(params) {
479
+ return __awaiter(this, void 0, void 0, function* () {
480
+ const delayedTransactions = yield this.transactionModel.find({
481
+ status: { $in: params.status.$in },
482
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported },
483
+ endDate: {
484
+ $exists: true,
485
+ $lt: moment(params.now)
486
+ .add(-params.delayInSeconds, 'seconds')
487
+ .toDate()
488
+ }
489
+ })
490
+ .select({
491
+ _id: 1,
492
+ typeOf: 1,
493
+ status: 1
494
+ })
495
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
387
496
  .exec();
497
+ if (delayedTransactions.length > 0) {
498
+ delayedTransactions.forEach((delayedTransaction) => {
499
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
500
+ id: delayedTransaction.id,
501
+ typeOf: delayedTransaction.typeOf,
502
+ status: delayedTransaction.status
503
+ });
504
+ });
505
+ }
506
+ return delayedTransactions;
388
507
  });
389
508
  }
390
509
  /**
@@ -393,10 +512,15 @@ class MongoRepository {
393
512
  */
394
513
  setTasksExportedById(params) {
395
514
  return __awaiter(this, void 0, void 0, function* () {
396
- yield this.transactionModel.findByIdAndUpdate(params.id, {
515
+ const endDate = new Date();
516
+ yield this.transactionModel.updateOne({
517
+ _id: { $eq: params.id },
518
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
519
+ }, {
397
520
  tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
398
- tasksExportedAt: moment()
399
- .toDate()
521
+ tasksExportedAt: endDate,
522
+ 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
523
+ 'tasksExportAction.endDate': endDate
400
524
  })
401
525
  .exec();
402
526
  });
@@ -406,15 +530,36 @@ class MongoRepository {
406
530
  */
407
531
  makeExpired(params) {
408
532
  return __awaiter(this, void 0, void 0, function* () {
409
- // ステータスと期限を見て更新
410
- yield this.transactionModel.updateMany({
411
- status: factory.transactionStatusType.InProgress,
412
- expires: { $lt: params.expires }
413
- }, {
414
- status: factory.transactionStatusType.Expired,
415
- endDate: new Date()
533
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
534
+ const expiringTransactions = yield this.transactionModel.find({
535
+ status: { $eq: factory.transactionStatusType.InProgress },
536
+ expires: { $lt: params.expires.$lt }
537
+ })
538
+ .select({
539
+ _id: 1,
540
+ typeOf: 1
416
541
  })
542
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
417
543
  .exec();
544
+ if (expiringTransactions.length > 0) {
545
+ // ステータスと期限を見て更新
546
+ yield this.transactionModel.updateMany({
547
+ _id: { $in: expiringTransactions.map((t) => t.id) },
548
+ status: { $eq: factory.transactionStatusType.InProgress },
549
+ expires: { $lt: params.expires.$lt }
550
+ }, {
551
+ status: factory.transactionStatusType.Expired,
552
+ endDate: new Date()
553
+ })
554
+ .exec();
555
+ expiringTransactions.forEach((expiringTransaction) => {
556
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
557
+ id: expiringTransaction.id,
558
+ typeOf: expiringTransaction.typeOf,
559
+ status: factory.transactionStatusType.Expired
560
+ });
561
+ });
562
+ }
418
563
  });
419
564
  }
420
565
  /**
@@ -422,19 +567,18 @@ class MongoRepository {
422
567
  */
423
568
  cancel(params) {
424
569
  return __awaiter(this, void 0, void 0, function* () {
425
- const endDate = moment()
426
- .toDate();
570
+ const endDate = new Date();
427
571
  // 進行中ステータスの取引を中止する
428
- const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: params.typeOf }, (typeof params.id === 'string') ? { _id: params.id } : undefined), (typeof params.transactionNumber === 'string')
572
+ const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: { $eq: params.typeOf } }, (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), (typeof params.transactionNumber === 'string')
429
573
  ? { transactionNumber: { $exists: true, $eq: params.transactionNumber } }
430
- : undefined), { status: factory.transactionStatusType.InProgress }), {
574
+ : undefined), { status: { $eq: factory.transactionStatusType.InProgress } }), {
431
575
  status: factory.transactionStatusType.Canceled,
432
576
  endDate: endDate
433
577
  }, { new: true })
434
578
  .exec();
579
+ let transaction;
435
580
  // NotFoundであれば取引状態確認
436
581
  if (doc === null) {
437
- let transaction;
438
582
  if (typeof params.id === 'string') {
439
583
  transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
440
584
  }
@@ -448,39 +592,64 @@ class MongoRepository {
448
592
  throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
449
593
  }
450
594
  if (transaction.status === factory.transactionStatusType.Canceled) {
451
- // すでに中止済の場合
452
- return transaction;
595
+ // すでに中止済の場合スルー
453
596
  }
454
597
  else if (transaction.status === factory.transactionStatusType.Expired) {
455
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
598
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
456
599
  }
457
600
  else if (transaction.status === factory.transactionStatusType.Confirmed) {
458
- throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
601
+ throw new factory.errors.Argument('Transaction id', `Confirmed transaction ${transaction.typeOf} ${transaction.transactionNumber} unable to cancel`);
459
602
  }
460
603
  else {
461
604
  throw new factory.errors.NotFound(this.transactionModel.modelName);
462
605
  }
463
606
  }
464
- return doc.toObject();
607
+ else {
608
+ transaction = doc.toObject();
609
+ }
610
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
611
+ id: transaction.id,
612
+ typeOf: params.typeOf,
613
+ status: factory.transactionStatusType.Canceled
614
+ });
615
+ return transaction;
465
616
  });
466
617
  }
467
618
  count(params) {
468
619
  return __awaiter(this, void 0, void 0, function* () {
469
620
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
470
621
  return this.transactionModel.countDocuments({ $and: conditions })
471
- .setOptions({ maxTimeMS: 10000 })
622
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
472
623
  .exec();
473
624
  });
474
625
  }
475
626
  /**
476
627
  * 取引を検索する
477
628
  */
478
- search(params, projection) {
629
+ search(params, inclusion, exclusion) {
479
630
  var _a;
480
631
  return __awaiter(this, void 0, void 0, function* () {
481
632
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
633
+ let projection = {};
634
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
635
+ inclusion.forEach((field) => {
636
+ projection[field] = 1;
637
+ });
638
+ }
639
+ else {
640
+ projection = {
641
+ __v: 0,
642
+ createdAt: 0,
643
+ updatedAt: 0
644
+ };
645
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
646
+ exclusion.forEach((field) => {
647
+ projection[field] = 0;
648
+ });
649
+ }
650
+ }
482
651
  const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
483
- .select(Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
652
+ .select(projection);
484
653
  if (typeof params.limit === 'number' && params.limit > 0) {
485
654
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
486
655
  query.limit(params.limit)
@@ -491,7 +660,7 @@ class MongoRepository {
491
660
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.startDate) !== undefined) {
492
661
  query.sort({ startDate: params.sort.startDate });
493
662
  }
494
- return query.setOptions({ maxTimeMS: 10000 })
663
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
495
664
  .exec()
496
665
  .then((docs) => docs.map((doc) => doc.toObject()));
497
666
  });
@@ -523,9 +692,12 @@ class MongoRepository {
523
692
  /**
524
693
  * 特定の取引を更新する(汎用)
525
694
  */
526
- findByIdAndUpdate(params) {
695
+ findByIdAndUpdateInProgress(params) {
527
696
  return __awaiter(this, void 0, void 0, function* () {
528
- return this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, { new: true })
697
+ return this.transactionModel.findOneAndUpdate({
698
+ _id: { $eq: params.id },
699
+ status: { $eq: factory.transactionStatusType.InProgress }
700
+ }, params.update, { new: true })
529
701
  .exec()
530
702
  .then((doc) => {
531
703
  if (doc === null) {
@@ -35,7 +35,7 @@ export declare class MongoRepository {
35
35
  /**
36
36
  * 検索
37
37
  */
38
- search(params: factory.categoryCode.ISearchConditions): Promise<factory.categoryCode.ICategoryCode[]>;
38
+ search(params: factory.categoryCode.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<factory.categoryCode.ICategoryCode[]>;
39
39
  findById(params: {
40
40
  id: string;
41
41
  }): Promise<factory.categoryCode.ICategoryCode>;