@chevre/domain 21.20.0-alpha.9 → 21.20.0

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 (226) hide show
  1. package/example/src/chevre/findTransactionById.ts +21 -0
  2. package/example/src/chevre/importCategoryCodesFromCOA.ts +2 -1
  3. package/example/src/chevre/importOffersFromCOA.ts +2 -1
  4. package/example/src/chevre/migrateActionInstrumentTransactionNumber.ts +93 -0
  5. package/example/src/chevre/migrateDeleteTransactionTasks.ts +119 -0
  6. package/example/src/chevre/migrateEventMakesOfferAvailableAtOrFrom.ts +87 -0
  7. package/example/src/chevre/migrateIAMMemberPOSRoles.ts +3 -2
  8. package/example/src/chevre/migrateOfferAvailableAtOrFrom.ts +63 -0
  9. package/example/src/chevre/{migrateOrderPaymentMethodIdentifier.ts → migrateOrderAcceptedOfferSerialNumber.ts} +18 -19
  10. package/example/src/chevre/onAssetTransactionStatusChanged.ts +36 -0
  11. package/example/src/chevre/retryTasks.ts +39 -0
  12. package/example/src/chevre/searchActions.ts +13 -7
  13. package/example/src/chevre/searchOrderAcceptedOffers.ts +13 -3
  14. package/example/src/chevre/searchOrders.ts +13 -15
  15. package/example/src/chevre/searchSlicedAcceptedOffersByOrderNumber.ts +28 -0
  16. package/example/src/chevre/sendOrder.ts +37 -0
  17. package/example/src/chevre/transaction/processPlaceOrder.ts +2 -1
  18. package/example/src/verifyToken.ts +44 -0
  19. package/lib/chevre/credentials.d.ts +2 -0
  20. package/lib/chevre/credentials.js +4 -2
  21. package/lib/chevre/errorHandler.js +3 -0
  22. package/lib/chevre/factory/order.d.ts +1 -0
  23. package/lib/chevre/factory/order.js +2 -1
  24. package/lib/chevre/factory/reservedAgentIdentifireNames.js +2 -1
  25. package/lib/chevre/factory/transaction.d.ts +10 -1
  26. package/lib/chevre/repo/acceptedOffer.d.ts +58 -2
  27. package/lib/chevre/repo/acceptedOffer.js +100 -4
  28. package/lib/chevre/repo/accountingReport.d.ts +33 -7
  29. package/lib/chevre/repo/accountingReport.js +157 -5
  30. package/lib/chevre/repo/action.d.ts +32 -8
  31. package/lib/chevre/repo/action.js +114 -54
  32. package/lib/chevre/repo/event.d.ts +20 -0
  33. package/lib/chevre/repo/event.js +22 -0
  34. package/lib/chevre/repo/member.d.ts +8 -1
  35. package/lib/chevre/repo/member.js +7 -1
  36. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +2 -1
  37. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
  38. package/lib/chevre/repo/mongoose/schemas/action.js +25 -11
  39. package/lib/chevre/repo/mongoose/schemas/order.d.ts +1 -1
  40. package/lib/chevre/repo/mongoose/schemas/order.js +38 -11
  41. package/lib/chevre/repo/offer.d.ts +42 -0
  42. package/lib/chevre/repo/offer.js +35 -0
  43. package/lib/chevre/repo/order.js +43 -20
  44. package/lib/chevre/repo/orderInTransaction.d.ts +44 -0
  45. package/lib/chevre/repo/orderInTransaction.js +164 -0
  46. package/lib/chevre/repo/paymentServiceProvider.js +2 -1
  47. package/lib/chevre/repo/person.js +1 -4
  48. package/lib/chevre/repo/task.d.ts +26 -3
  49. package/lib/chevre/repo/task.js +61 -46
  50. package/lib/chevre/repo/transaction.d.ts +2 -2
  51. package/lib/chevre/repo/transaction.js +13 -36
  52. package/lib/chevre/repository.d.ts +5 -0
  53. package/lib/chevre/repository.js +15 -2
  54. package/lib/chevre/service/aggregation/event/importFromCOA.js +5 -5
  55. package/lib/chevre/service/assetTransaction/pay/factory.js +1 -6
  56. package/lib/chevre/service/assetTransaction/pay/potentialActions/createPayObjectServiceOutput.d.ts +9 -0
  57. package/lib/chevre/service/assetTransaction/pay/potentialActions/createPayObjectServiceOutput.js +143 -0
  58. package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +11 -3
  59. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +4 -165
  60. package/lib/chevre/service/assetTransaction/pay.d.ts +21 -1
  61. package/lib/chevre/service/assetTransaction/pay.js +64 -23
  62. package/lib/chevre/service/assetTransaction/reserve/factory.js +11 -14
  63. package/lib/chevre/service/assetTransaction/reserveCOA.d.ts +19 -0
  64. package/lib/chevre/service/assetTransaction/reserveCOA.js +46 -0
  65. package/lib/chevre/service/code.js +1 -1
  66. package/lib/chevre/service/delivery.js +2 -2
  67. package/lib/chevre/service/event/createEvent.js +1 -1
  68. package/lib/chevre/service/event.js +16 -24
  69. package/lib/chevre/service/moneyTransfer.js +1 -1
  70. package/lib/chevre/service/notification.js +71 -66
  71. package/lib/chevre/service/offer/any.d.ts +35 -0
  72. package/lib/chevre/service/offer/any.js +67 -0
  73. package/lib/chevre/service/offer/event/authorize.d.ts +7 -0
  74. package/lib/chevre/service/offer/event/authorize.js +27 -17
  75. package/lib/chevre/service/offer/event/cancel.d.ts +2 -0
  76. package/lib/chevre/service/offer/event/cancel.js +13 -1
  77. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  78. package/lib/chevre/service/offer/event/factory.js +11 -22
  79. package/lib/chevre/service/offer/event/importFromCOA.js +6 -8
  80. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  81. package/lib/chevre/service/offer/event/voidTransaction.js +24 -7
  82. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +54 -0
  83. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +138 -0
  84. package/lib/chevre/service/offer/eventServiceByCOA/cancel.d.ts +39 -0
  85. package/lib/chevre/service/offer/eventServiceByCOA/cancel.js +59 -0
  86. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.d.ts +25 -0
  87. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +165 -0
  88. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +10 -23
  89. package/lib/chevre/service/offer/eventServiceByCOA.d.ts +4 -89
  90. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -292
  91. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +10 -1
  92. package/lib/chevre/service/offer/moneyTransfer/authorize.js +49 -3
  93. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +1 -1
  94. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.d.ts +2 -0
  95. package/lib/chevre/service/offer/moneyTransfer/settleTransaction.js +47 -2
  96. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +1 -1
  97. package/lib/chevre/service/offer/product/factory.js +2 -5
  98. package/lib/chevre/service/offer/product.d.ts +2 -0
  99. package/lib/chevre/service/offer/product.js +11 -23
  100. package/lib/chevre/service/order/confirmPayTransaction.d.ts +3 -1
  101. package/lib/chevre/service/order/confirmPayTransaction.js +4 -4
  102. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +1 -1
  103. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +12 -1
  104. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +206 -7
  105. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  106. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +1 -1
  107. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +51 -53
  108. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +1 -1
  109. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +10 -25
  110. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +16 -0
  111. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +91 -0
  112. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +8 -0
  113. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.js +37 -0
  114. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +12 -0
  115. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +115 -0
  116. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +19 -1
  117. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +8 -0
  118. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +41 -0
  119. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +6 -10
  120. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +116 -92
  121. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +4 -1
  122. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +81 -84
  123. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
  124. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +18 -15
  125. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +62 -1
  126. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +3 -1
  127. package/lib/chevre/service/order/onOrderStatusChanged.js +5 -1
  128. package/lib/chevre/service/order/placeOrder.d.ts +3 -1
  129. package/lib/chevre/service/order/placeOrder.js +157 -50
  130. package/lib/chevre/service/order/returnOrder.js +25 -16
  131. package/lib/chevre/service/order/sendOrder.d.ts +5 -0
  132. package/lib/chevre/service/order/sendOrder.js +67 -33
  133. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  134. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.d.ts +3 -1
  135. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onPaid.js +15 -9
  136. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.d.ts +3 -1
  137. package/lib/chevre/service/payment/any/onPaymentStatusChanged/onRefunded.js +8 -5
  138. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +2 -2
  139. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  140. package/lib/chevre/service/payment/any.d.ts +6 -2
  141. package/lib/chevre/service/payment/any.js +3 -2
  142. package/lib/chevre/service/payment/creditCard.d.ts +1 -1
  143. package/lib/chevre/service/payment/creditCard.js +62 -68
  144. package/lib/chevre/service/payment/faceToFace.d.ts +1 -1
  145. package/lib/chevre/service/payment/movieTicket.d.ts +1 -1
  146. package/lib/chevre/service/payment/movieTicket.js +1 -1
  147. package/lib/chevre/service/payment/paymentCard.d.ts +1 -1
  148. package/lib/chevre/service/payment.d.ts +5 -0
  149. package/lib/chevre/service/payment.js +40 -5
  150. package/lib/chevre/service/product.js +1 -1
  151. package/lib/chevre/service/reserve/cancelReservation.js +2 -2
  152. package/lib/chevre/service/reserve/checkInReservation.d.ts +1 -3
  153. package/lib/chevre/service/reserve/checkInReservation.js +6 -5
  154. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  155. package/lib/chevre/service/reserve/factory.js +0 -8
  156. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +1 -1
  157. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +4 -4
  158. package/lib/chevre/service/reserve/searchByOrder.js +2 -1
  159. package/lib/chevre/service/reserve/useReservation.d.ts +1 -3
  160. package/lib/chevre/service/reserve/useReservation.js +10 -9
  161. package/lib/chevre/service/reserve/verifyToken4reservation.js +2 -0
  162. package/lib/chevre/service/task/confirmMoneyTransfer.js +4 -4
  163. package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
  164. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  165. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +30 -8
  166. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +6 -1
  167. package/lib/chevre/service/task/confirmReserveTransaction.js +176 -29
  168. package/lib/chevre/service/task/createAccountingReport.d.ts +6 -0
  169. package/lib/chevre/service/task/createAccountingReport.js +80 -0
  170. package/lib/chevre/service/task/importOffersFromCOA.js +2 -1
  171. package/lib/chevre/service/task/onAuthorizationCreated.js +0 -1
  172. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -7
  173. package/lib/chevre/service/task/pay.js +6 -0
  174. package/lib/chevre/service/task/placeOrder.js +9 -10
  175. package/lib/chevre/service/task/returnOrder.js +0 -3
  176. package/lib/chevre/service/task/returnPayTransaction.js +1 -1
  177. package/lib/chevre/service/task/returnReserveTransaction.js +3 -2
  178. package/lib/chevre/service/task/sendOrder.js +8 -4
  179. package/lib/chevre/service/task/useReservation.js +1 -1
  180. package/lib/chevre/service/task/voidReserveTransaction.js +8 -12
  181. package/lib/chevre/service/transaction/deleteTransaction.js +1 -1
  182. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.js +2 -18
  183. package/lib/chevre/service/transaction/moneyTransfer.js +7 -6
  184. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +2 -2
  185. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +17 -20
  186. package/lib/chevre/service/transaction/placeOrder.js +2 -1
  187. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.d.ts +51 -0
  188. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +268 -0
  189. package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +1 -1
  190. package/lib/chevre/service/transaction/placeOrderInProgress/factory.js +3 -2
  191. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  192. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +22 -44
  193. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.d.ts +14 -0
  194. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.js +41 -0
  195. package/lib/chevre/service/transaction/placeOrderInProgress/publishConfirmationNumberIfNotExist.d.ts +18 -0
  196. package/lib/chevre/service/transaction/placeOrderInProgress/publishConfirmationNumberIfNotExist.js +42 -0
  197. package/lib/chevre/service/transaction/placeOrderInProgress/publishOrderNumberIfNotExist.d.ts +23 -0
  198. package/lib/chevre/service/transaction/placeOrderInProgress/publishOrderNumberIfNotExist.js +46 -0
  199. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +34 -37
  200. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +3 -1
  201. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +13 -4
  202. package/lib/chevre/service/transaction/placeOrderInProgress/start.d.ts +19 -0
  203. package/lib/chevre/service/transaction/placeOrderInProgress/start.js +46 -0
  204. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateStartRequest.d.ts +26 -0
  205. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateStartRequest.js +109 -0
  206. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +10 -23
  207. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +20 -1
  208. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +11 -73
  209. package/lib/chevre/service/transaction/placeOrderInProgress.js +13 -286
  210. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +1 -2
  211. package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +0 -1
  212. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +8 -3
  213. package/lib/chevre/service/transaction/returnOrder/preStart.js +78 -50
  214. package/lib/chevre/service/transaction/returnOrder.js +3 -10
  215. package/lib/chevre/service.js +0 -10
  216. package/lib/chevre/settings.d.ts +7 -3
  217. package/lib/chevre/settings.js +13 -4
  218. package/package.json +5 -9
  219. package/example/src/chevre/cleanAccountingReports.ts +0 -57
  220. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +0 -78
  221. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +0 -11
  222. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.js +0 -30
  223. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.d.ts +0 -7
  224. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +0 -82
  225. package/lib/chevre/service/util.d.ts +0 -19
  226. package/lib/chevre/service/util.js +0 -126
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const accountingReport_1 = require("./mongoose/schemas/accountingReport");
14
14
  const errorHandler_1 = require("../errorHandler");
15
+ const factory = require("../factory");
16
+ const DEFAULT_SEARCH_LIMIT = 100;
15
17
  /**
16
18
  * 経理レポートリポジトリ
17
19
  */
@@ -19,13 +21,103 @@ class MongoRepository {
19
21
  constructor(connection) {
20
22
  this.accountingReportModel = connection.model(accountingReport_1.modelName, (0, accountingReport_1.createSchema)());
21
23
  }
22
- /**
23
- * なければ作成する
24
- */
25
- createIfNotExist(params) {
24
+ 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;
26
+ const matchStages = [];
27
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
28
+ if (typeof projectIdEq === 'string') {
29
+ matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
30
+ }
31
+ // req.seller.idを考慮(2023-07-21~)
32
+ if (typeof ((_c = params.seller) === null || _c === void 0 ? void 0 : _c.id) === 'string') {
33
+ matchStages.push({ $match: { 'mainEntity.seller.id': { $exists: true, $eq: params.seller.id } } });
34
+ }
35
+ const orderNumberEq = (_e = (_d = params.order) === null || _d === void 0 ? void 0 : _d.orderNumber) === null || _e === void 0 ? void 0 : _e.$eq;
36
+ if (typeof orderNumberEq === 'string') {
37
+ matchStages.push({ $match: { 'mainEntity.orderNumber': { $eq: orderNumberEq } } });
38
+ }
39
+ const sellerIdEq = (_h = (_g = (_f = params.order) === null || _f === void 0 ? void 0 : _f.seller) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$eq;
40
+ if (typeof sellerIdEq === 'string') {
41
+ matchStages.push({ $match: { 'mainEntity.seller.id': { $exists: true, $eq: sellerIdEq } } });
42
+ }
43
+ const paymentMethodIdEq = (_l = (_k = (_j = params.order) === null || _j === void 0 ? void 0 : _j.paymentMethods) === null || _k === void 0 ? void 0 : _k.paymentMethodId) === null || _l === void 0 ? void 0 : _l.$eq;
44
+ if (typeof paymentMethodIdEq === 'string') {
45
+ matchStages.push({
46
+ $match: { 'mainEntity.paymentMethods.paymentMethodId': { $exists: true, $eq: paymentMethodIdEq } }
47
+ });
48
+ }
49
+ const orderDateGte = (_o = (_m = params.order) === null || _m === void 0 ? void 0 : _m.orderDate) === null || _o === void 0 ? void 0 : _o.$gte;
50
+ if (orderDateGte instanceof Date) {
51
+ matchStages.push({
52
+ $match: { 'mainEntity.orderDate': { $gte: orderDateGte } }
53
+ });
54
+ }
55
+ const orderDateLte = (_q = (_p = params.order) === null || _p === void 0 ? void 0 : _p.orderDate) === null || _q === void 0 ? void 0 : _q.$lte;
56
+ if (orderDateLte instanceof Date) {
57
+ matchStages.push({
58
+ $match: { 'mainEntity.orderDate': { $lte: orderDateLte } }
59
+ });
60
+ }
61
+ const reservationForStartDateGte = (_v = (_u = (_t = (_s = (_r = params.order) === null || _r === void 0 ? void 0 : _r.acceptedOffers) === null || _s === void 0 ? void 0 : _s.itemOffered) === null || _t === void 0 ? void 0 : _t.reservationFor) === null || _u === void 0 ? void 0 : _u.startDate) === null || _v === void 0 ? void 0 : _v.$gte;
62
+ if (reservationForStartDateGte instanceof Date) {
63
+ matchStages.push({
64
+ $match: {
65
+ 'mainEntity.acceptedOffers.itemOffered.reservationFor.startDate': {
66
+ $exists: true,
67
+ $gte: reservationForStartDateGte
68
+ }
69
+ }
70
+ });
71
+ }
72
+ const reservationForStartDateLte = (_0 = (_z = (_y = (_x = (_w = params.order) === null || _w === void 0 ? void 0 : _w.acceptedOffers) === null || _x === void 0 ? void 0 : _x.itemOffered) === null || _y === void 0 ? void 0 : _y.reservationFor) === null || _z === void 0 ? void 0 : _z.startDate) === null || _0 === void 0 ? void 0 : _0.$lte;
73
+ if (reservationForStartDateLte instanceof Date) {
74
+ matchStages.push({
75
+ $match: {
76
+ 'mainEntity.acceptedOffers.itemOffered.reservationFor.startDate': {
77
+ $exists: true,
78
+ $lte: reservationForStartDateLte
79
+ }
80
+ }
81
+ });
82
+ }
83
+ return matchStages;
84
+ }
85
+ // public async createIfNotExist(params: IAccountingReport) {
86
+ // try {
87
+ // await this.accountingReportModel.findOneAndUpdate(
88
+ // { 'mainEntity.orderNumber': params.mainEntity.orderNumber },
89
+ // { $setOnInsert: params },
90
+ // { upsert: true }
91
+ // )
92
+ // .exec();
93
+ // } catch (error) {
94
+ // let throwsError = true;
95
+ // if (await isMongoError(error)) {
96
+ // // すでにorderNumberが存在する場合ok
97
+ // if (error.code === MongoErrorCode.DuplicateKey) {
98
+ // throwsError = false;
99
+ // }
100
+ // }
101
+ // if (throwsError) {
102
+ // throw error;
103
+ // }
104
+ // }
105
+ // }
106
+ syncMainEntity(params) {
26
107
  return __awaiter(this, void 0, void 0, function* () {
108
+ const setOnInsert = {
109
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
110
+ typeOf: 'Report',
111
+ hasPart: [],
112
+ mainEntity: {
113
+ orderNumber: params.mainEntity.orderNumber // orderNumberのみが最低限必要なのでなければ作成
114
+ }
115
+ };
27
116
  try {
28
- yield this.accountingReportModel.findOneAndUpdate({ 'mainEntity.orderNumber': params.mainEntity.orderNumber }, { $setOnInsert: params }, { upsert: true })
117
+ // なければ作成
118
+ yield this.accountingReportModel.updateOne({ 'mainEntity.orderNumber': { $eq: params.mainEntity.orderNumber } }, { $setOnInsert: setOnInsert }, {
119
+ upsert: true
120
+ })
29
121
  .exec();
30
122
  }
31
123
  catch (error) {
@@ -40,6 +132,9 @@ class MongoRepository {
40
132
  throw error;
41
133
  }
42
134
  }
135
+ // mainEntityを同期
136
+ yield this.accountingReportModel.updateOne({ 'mainEntity.orderNumber': { $eq: params.mainEntity.orderNumber } }, { $set: { mainEntity: params.mainEntity } })
137
+ .exec();
43
138
  });
44
139
  }
45
140
  /**
@@ -51,5 +146,62 @@ class MongoRepository {
51
146
  .exec();
52
147
  });
53
148
  }
149
+ /**
150
+ * 注文にアクションレポートを追加する
151
+ * 注文に対する経理レポート自体が未作成であれば自動的に作成する
152
+ */
153
+ addChildReport(params) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ const setOnInsert = {
156
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
157
+ typeOf: 'Report',
158
+ // hasPart: [],
159
+ mainEntity: {
160
+ orderNumber: params.mainEntity.orderNumber // orderNumberのみが最低限必要なのでなければ作成
161
+ }
162
+ };
163
+ const doc = yield this.accountingReportModel.findOneAndUpdate({ 'mainEntity.orderNumber': { $eq: params.mainEntity.orderNumber } }, {
164
+ $addToSet: { hasPart: params.hasPart },
165
+ $setOnInsert: setOnInsert
166
+ }, {
167
+ projection: { _id: 1 },
168
+ upsert: true
169
+ })
170
+ .exec();
171
+ if (doc === null) {
172
+ throw new factory.errors.NotFound(this.accountingReportModel.modelName);
173
+ }
174
+ });
175
+ }
176
+ search(params) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const limit = (typeof params.limit === 'number') ? Math.min(params.limit, DEFAULT_SEARCH_LIMIT) : DEFAULT_SEARCH_LIMIT;
179
+ const page = (typeof params.page === 'number') ? Math.max(params.page, 1) : 1;
180
+ const unwindAcceptedOffers = params.$unwindAcceptedOffers === '1';
181
+ const matchStages = MongoRepository.CREATE_MONGO_CONDITIONS(params);
182
+ const aggregate = this.accountingReportModel.aggregate([
183
+ // pipelineの順序に注意
184
+ // @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
185
+ { $sort: { 'mainEntity.orderDate': factory.sortType.Descending } },
186
+ { $unwind: '$hasPart' },
187
+ ...(unwindAcceptedOffers) ? [{ $unwind: '$mainEntity.acceptedOffers' }] : [],
188
+ ...matchStages,
189
+ {
190
+ $project: {
191
+ _id: 0,
192
+ mainEntity: '$hasPart.mainEntity',
193
+ isPartOf: {
194
+ mainEntity: '$mainEntity'
195
+ }
196
+ }
197
+ }
198
+ ]);
199
+ return aggregate.allowDiskUse(true)
200
+ .limit(limit * page)
201
+ .skip(limit * (page - 1))
202
+ // .setOptions({ maxTimeMS: 10000 })
203
+ .exec();
204
+ });
205
+ }
54
206
  }
55
207
  exports.MongoRepository = MongoRepository;
@@ -30,6 +30,7 @@ export interface IUseActionCountByOffer {
30
30
  _id: string[];
31
31
  useActionCount?: number;
32
32
  }
33
+ type KeyOfAction = keyof factory.action.IAction<factory.action.IAttributes<factory.actionType, any, any>> | '_id';
33
34
  interface IAggregationByStatus {
34
35
  actionCount: number;
35
36
  avgDuration: number;
@@ -57,7 +58,7 @@ export declare class MongoRepository {
57
58
  /**
58
59
  * アクション検索
59
60
  */
60
- search<T extends factory.actionType>(params: factory.action.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<IAction<T>[]>;
61
+ search<T extends factory.actionType>(params: factory.action.ISearchConditions, inclusion: KeyOfAction[], exclusion: KeyOfAction[]): Promise<IAction<T>[]>;
61
62
  /**
62
63
  * アクション開始
63
64
  */
@@ -78,10 +79,10 @@ export declare class MongoRepository {
78
79
  /**
79
80
  * アクション取消
80
81
  */
81
- cancel<T extends factory.actionType>(params: {
82
- typeOf: T;
82
+ cancelWithVoid(params: {
83
+ typeOf: factory.actionType;
83
84
  id: string;
84
- }): Promise<IAction<T>>;
85
+ }): Promise<void>;
85
86
  /**
86
87
  * アクション失敗
87
88
  */
@@ -90,6 +91,12 @@ export declare class MongoRepository {
90
91
  id: string;
91
92
  error: Error;
92
93
  }): Promise<void>;
94
+ /**
95
+ * アクション再開
96
+ */
97
+ reStart(params: {
98
+ id: string;
99
+ }): Promise<void>;
93
100
  /**
94
101
  * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
95
102
  */
@@ -136,6 +143,9 @@ export declare class MongoRepository {
136
143
  actionStatus?: {
137
144
  $eq?: factory.actionStatusType;
138
145
  };
146
+ id?: {
147
+ $nin?: string[];
148
+ };
139
149
  sort?: factory.action.ISortOrder;
140
150
  }): Promise<IAction<T>[]>;
141
151
  /**
@@ -150,11 +160,11 @@ export declare class MongoRepository {
150
160
  id: string;
151
161
  };
152
162
  }): Promise<void>;
153
- updateAuthorizeEventOfferAction<T extends factory.service.webAPI.Identifier>(params: {
163
+ updateAuthorizeEventOfferAction(params: {
154
164
  id: string;
155
- object: factory.action.authorize.offer.eventService.IObject<T>;
156
- result: factory.action.authorize.offer.eventService.IResult<T>;
157
- }): Promise<factory.action.authorize.offer.eventService.IAction<T>>;
165
+ object: factory.action.authorize.offer.eventService.IObject<factory.service.webAPI.Identifier.COA>;
166
+ result: factory.action.authorize.offer.eventService.IResult<factory.service.webAPI.Identifier.COA>;
167
+ }): Promise<factory.action.authorize.offer.eventService.IAction<factory.service.webAPI.Identifier.COA>>;
158
168
  updateById(params: {
159
169
  id: string;
160
170
  update: any;
@@ -272,6 +282,20 @@ export declare class MongoRepository {
272
282
  startThrough: Date;
273
283
  }): Promise<IAggregateAction>;
274
284
  getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
285
+ /**
286
+ * 互換性維持対応専用
287
+ */
288
+ fixInstrumentTransactionNumber(params: {
289
+ id: string;
290
+ instrument: {
291
+ transactionNumber: string;
292
+ };
293
+ object?: {
294
+ pendingTransaction?: {
295
+ transactionNumber?: string;
296
+ };
297
+ };
298
+ }): Promise<void>;
275
299
  private agggregateByStatus;
276
300
  }
277
301
  export {};