@chevre/domain 26.0.0-alpha.4 → 26.0.0-alpha.41

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 (246) hide show
  1. package/lib/chevre/eventEmitter/task.d.ts +8 -23
  2. package/lib/chevre/eventEmitter/task.js +2 -2
  3. package/lib/chevre/repo/acceptedOffer.d.ts +0 -7
  4. package/lib/chevre/repo/acceptedOffer.js +27 -27
  5. package/lib/chevre/repo/action/acceptCOAOffer.d.ts +3 -1
  6. package/lib/chevre/repo/action/acceptCOAOffer.js +8 -2
  7. package/lib/chevre/repo/action/acceptPay.d.ts +3 -1
  8. package/lib/chevre/repo/action/acceptPay.js +8 -4
  9. package/lib/chevre/repo/action/{actionProcess.d.ts → anyAction/actionProcess.d.ts} +18 -45
  10. package/lib/chevre/repo/action/{actionProcess.js → anyAction/actionProcess.js} +26 -91
  11. package/lib/chevre/repo/action/anyAction/actionRecipe.d.ts +37 -0
  12. package/lib/chevre/repo/action/anyAction/actionRecipe.js +53 -0
  13. package/lib/chevre/repo/action/authorizeInvoice.d.ts +5 -8
  14. package/lib/chevre/repo/action/authorizeInvoice.js +7 -4
  15. package/lib/chevre/repo/action/authorizeOffer.d.ts +3 -1
  16. package/lib/chevre/repo/action/authorizeOffer.js +7 -2
  17. package/lib/chevre/repo/action/authorizePaymentMethod.d.ts +3 -1
  18. package/lib/chevre/repo/action/authorizePaymentMethod.js +7 -4
  19. package/lib/chevre/repo/action/authorizeTicketedObject.d.ts +3 -1
  20. package/lib/chevre/repo/action/authorizeTicketedObject.js +7 -2
  21. package/lib/chevre/repo/action/checkMovieTicket.d.ts +3 -1
  22. package/lib/chevre/repo/action/checkMovieTicket.js +8 -1
  23. package/lib/chevre/repo/action/create.d.ts +10 -0
  24. package/lib/chevre/repo/action/create.js +17 -0
  25. package/lib/chevre/repo/action/inform.d.ts +38 -0
  26. package/lib/chevre/repo/action/inform.js +146 -0
  27. package/lib/chevre/repo/action/pay.d.ts +3 -1
  28. package/lib/chevre/repo/action/pay.js +7 -4
  29. package/lib/chevre/repo/action/refund.d.ts +3 -1
  30. package/lib/chevre/repo/action/refund.js +7 -4
  31. package/lib/chevre/repo/action/sendEmailMessage.d.ts +10 -0
  32. package/lib/chevre/repo/action/sendEmailMessage.js +17 -0
  33. package/lib/chevre/repo/action/sendOrder.d.ts +10 -0
  34. package/lib/chevre/repo/action/sendOrder.js +16 -0
  35. package/lib/chevre/repo/action/unknown2actionError.d.ts +6 -0
  36. package/lib/chevre/repo/action/unknown2actionError.js +15 -0
  37. package/lib/chevre/repo/action/update.d.ts +48 -0
  38. package/lib/chevre/repo/action/update.js +166 -0
  39. package/lib/chevre/repo/action/use.d.ts +39 -0
  40. package/lib/chevre/repo/action/use.js +153 -0
  41. package/lib/chevre/repo/action.d.ts +5 -101
  42. package/lib/chevre/repo/action.js +7 -453
  43. package/lib/chevre/repo/adminAction.d.ts +87 -0
  44. package/lib/chevre/repo/adminAction.js +170 -0
  45. package/lib/chevre/repo/adminAssetTransaction.d.ts +126 -0
  46. package/lib/chevre/repo/adminAssetTransaction.js +491 -0
  47. package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
  48. package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
  49. package/lib/chevre/repo/adminTask.d.ts +25 -8
  50. package/lib/chevre/repo/adminTask.js +31 -32
  51. package/lib/chevre/repo/adminTransaction.d.ts +131 -0
  52. package/lib/chevre/repo/adminTransaction.js +237 -0
  53. package/lib/chevre/repo/aggregateAction.d.ts +8 -11
  54. package/lib/chevre/repo/aggregateAction.js +0 -61
  55. package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
  56. package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
  57. package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
  58. package/lib/chevre/repo/aggregateTransaction.js +166 -0
  59. package/lib/chevre/repo/aggregateUseAction.d.ts +35 -0
  60. package/lib/chevre/repo/aggregateUseAction.js +164 -0
  61. package/lib/chevre/repo/aggregation.d.ts +0 -8
  62. package/lib/chevre/repo/aggregation.js +0 -10
  63. package/lib/chevre/repo/assetTransaction.d.ts +10 -235
  64. package/lib/chevre/repo/assetTransaction.js +48 -636
  65. package/lib/chevre/repo/asyncAction.d.ts +2 -2
  66. package/lib/chevre/repo/authorization.d.ts +0 -6
  67. package/lib/chevre/repo/authorization.js +15 -27
  68. package/lib/chevre/repo/message.d.ts +0 -7
  69. package/lib/chevre/repo/message.js +0 -38
  70. package/lib/chevre/repo/migrateAction.d.ts +48 -0
  71. package/lib/chevre/repo/migrateAction.js +32 -0
  72. package/lib/chevre/repo/mongoose/schemas/action/inform.d.ts +11 -0
  73. package/lib/chevre/repo/mongoose/schemas/action/inform.js +82 -0
  74. package/lib/chevre/repo/mongoose/schemas/action/update.d.ts +12 -0
  75. package/lib/chevre/repo/mongoose/schemas/action/update.js +112 -0
  76. package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → action/use.d.ts} +4 -6
  77. package/lib/chevre/repo/mongoose/schemas/action/use.js +92 -0
  78. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -3
  79. package/lib/chevre/repo/mongoose/schemas/action.js +22 -7
  80. package/lib/chevre/repo/mongoose/schemas/actionRecipe.d.ts +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +19 -1
  82. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
  83. package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
  84. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +95 -76
  85. package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
  86. package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
  87. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
  88. package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
  89. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
  90. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
  91. package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
  92. package/lib/chevre/repo/mongoose/schemas/task.js +134 -118
  93. package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
  94. package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
  95. package/lib/chevre/repo/orderInTransaction.js +30 -22
  96. package/lib/chevre/repo/scheduledTask.d.ts +5 -2
  97. package/lib/chevre/repo/scheduledTask.js +3 -25
  98. package/lib/chevre/repo/task.d.ts +45 -171
  99. package/lib/chevre/repo/task.js +20 -475
  100. package/lib/chevre/repo/taskDelayed.d.ts +74 -0
  101. package/lib/chevre/repo/taskDelayed.js +195 -0
  102. package/lib/chevre/repo/taskRunning.d.ts +35 -0
  103. package/lib/chevre/repo/taskRunning.js +89 -0
  104. package/lib/chevre/repo/ticket.d.ts +0 -6
  105. package/lib/chevre/repo/ticket.js +0 -11
  106. package/lib/chevre/repo/transaction.d.ts +1 -187
  107. package/lib/chevre/repo/transaction.js +2 -383
  108. package/lib/chevre/repository.d.ts +50 -10
  109. package/lib/chevre/repository.js +112 -24
  110. package/lib/chevre/service/aggregation/system.d.ts +9 -8
  111. package/lib/chevre/service/aggregation/system.js +5 -5
  112. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
  113. package/lib/chevre/service/assetTransaction/refund.js +2 -2
  114. package/lib/chevre/service/asyncAction.d.ts +2 -2
  115. package/lib/chevre/service/asyncAction.js +1 -4
  116. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
  117. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
  118. package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
  119. package/lib/chevre/service/asyncActionHandler.js +11 -13
  120. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +4 -2
  121. package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
  122. package/lib/chevre/service/event.d.ts +4 -2
  123. package/lib/chevre/service/event.js +3 -3
  124. package/lib/chevre/service/notification/sendEmailMessage.d.ts +4 -2
  125. package/lib/chevre/service/notification/sendEmailMessage.js +3 -3
  126. package/lib/chevre/service/notification/triggerWebhook.d.ts +4 -2
  127. package/lib/chevre/service/notification/triggerWebhook.js +5 -16
  128. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
  129. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  130. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  131. package/lib/chevre/service/offer/onEventChanged.js +0 -2
  132. package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
  133. package/lib/chevre/service/order/createAccountingReportIfNotExist.d.ts +1 -1
  134. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +2 -56
  135. package/lib/chevre/service/order/deleteOrder.d.ts +2 -2
  136. package/lib/chevre/service/order/deleteOrder.js +1 -2
  137. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
  138. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
  139. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +2 -4
  140. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +2 -4
  141. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
  142. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
  143. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -10
  144. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
  145. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +4 -8
  146. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
  147. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  148. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +5 -11
  149. package/lib/chevre/service/order/onOrderUpdated/factory.js +0 -3
  150. package/lib/chevre/service/order/returnOrder.d.ts +0 -2
  151. package/lib/chevre/service/order/returnOrder.js +8 -40
  152. package/lib/chevre/service/order/sendOrder.d.ts +4 -6
  153. package/lib/chevre/service/order/sendOrder.js +30 -72
  154. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  155. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  156. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  157. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  158. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  159. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  160. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
  161. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
  162. package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
  163. package/lib/chevre/service/project.d.ts +0 -6
  164. package/lib/chevre/service/project.js +0 -2
  165. package/lib/chevre/service/reserve/cancelReservation.js +3 -3
  166. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  167. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  168. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
  169. package/lib/chevre/service/reserve/useReservation.d.ts +4 -0
  170. package/lib/chevre/service/reserve/useReservation.js +6 -24
  171. package/lib/chevre/service/scheduledTask.d.ts +1 -4
  172. package/lib/chevre/service/scheduledTask.js +3 -10
  173. package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
  174. package/lib/chevre/service/scheduledTaskHandler.js +0 -13
  175. package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
  176. package/lib/chevre/service/task/authorizePayment.js +1 -7
  177. package/lib/chevre/service/task/checkMovieTicket.js +1 -7
  178. package/lib/chevre/service/task/checkResource.js +14 -57
  179. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
  180. package/lib/chevre/service/task/createAccountingReport.js +8 -15
  181. package/lib/chevre/service/task/deleteTransaction.js +10 -41
  182. package/lib/chevre/service/task/importEventsFromCOA.js +4 -2
  183. package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
  184. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.d.ts +4 -2
  185. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +4 -4
  186. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +4 -2
  187. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +4 -4
  188. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +4 -2
  189. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +4 -4
  190. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +4 -2
  191. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +4 -4
  192. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +4 -2
  193. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +4 -4
  194. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +4 -2
  195. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +4 -4
  196. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +4 -2
  197. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +4 -4
  198. package/lib/chevre/service/task/onResourceDeleted.js +4 -3
  199. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +0 -1
  200. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +0 -1
  201. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +0 -1
  202. package/lib/chevre/service/task/onResourceUpdated.js +0 -8
  203. package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
  204. package/lib/chevre/service/task/returnOrder.js +2 -5
  205. package/lib/chevre/service/task/returnPayTransaction.js +2 -5
  206. package/lib/chevre/service/task/sendEmailMessage.js +2 -2
  207. package/lib/chevre/service/task/sendOrder.js +4 -8
  208. package/lib/chevre/service/task/syncResourcesFromCOA.js +31 -23
  209. package/lib/chevre/service/task/triggerWebhook.js +4 -2
  210. package/lib/chevre/service/task/useReservation.js +4 -0
  211. package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
  212. package/lib/chevre/service/task.d.ts +3 -22
  213. package/lib/chevre/service/task.js +8 -40
  214. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +0 -1
  215. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
  216. package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
  217. package/lib/chevre/service/taskHandler.d.ts +1 -2
  218. package/lib/chevre/service/taskHandler.js +7 -19
  219. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
  220. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
  221. package/lib/chevre/service/transaction/deleteTransaction.d.ts +8 -4
  222. package/lib/chevre/service/transaction/deleteTransaction.js +7 -7
  223. package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
  224. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  225. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  226. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  227. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
  228. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  229. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  230. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  231. package/lib/chevre/service/transaction/returnOrder.js +15 -13
  232. package/lib/chevre/service/transaction.d.ts +2 -0
  233. package/lib/chevre/service/transaction.js +0 -2
  234. package/lib/chevre/service/validation/validateOrder.d.ts +0 -4
  235. package/lib/chevre/service/validation/validateOrder.js +3 -3
  236. package/lib/chevre/taskSettings.d.ts +4 -4
  237. package/package.json +2 -2
  238. package/lib/chevre/repo/action/checkThing.d.ts +0 -8
  239. package/lib/chevre/repo/action/checkThing.js +0 -13
  240. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -227
  241. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.d.ts +0 -25
  242. package/lib/chevre/repo/mongoose/schemas/pendingReservationAggregate.js +0 -100
  243. package/lib/chevre/repo/ownershipInfo.d.ts +0 -122
  244. package/lib/chevre/repo/ownershipInfo.js +0 -466
  245. package/lib/chevre/service/validation/validateEvent.d.ts +0 -11
  246. package/lib/chevre/service/validation/validateEvent.js +0 -21
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateActionRepo = void 0;
4
+ const factory_1 = require("../../factory");
5
+ const settings_1 = require("../../settings");
6
+ const update_1 = require("../mongoose/schemas/action/update");
7
+ const unknown2actionError_1 = require("./unknown2actionError");
8
+ const AVAILABLE_PROJECT_FIELDS = [
9
+ 'project',
10
+ 'actionStatus',
11
+ 'typeOf',
12
+ 'agent',
13
+ 'result',
14
+ 'error',
15
+ 'object',
16
+ 'startDate',
17
+ 'endDate',
18
+ 'instrument',
19
+ 'targetCollection',
20
+ 'sameAs',
21
+ 'expires'
22
+ ];
23
+ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
24
+ /**
25
+ * リソース編集アクションリポジトリ
26
+ */
27
+ class UpdateActionRepo {
28
+ updateActionModel;
29
+ constructor(connection) {
30
+ this.updateActionModel = connection.model(update_1.modelName, (0, update_1.createSchema)());
31
+ }
32
+ static CREATE_MONGO_CONDITIONS(params) {
33
+ const andConditions = [];
34
+ const idEq = params.id;
35
+ if (typeof idEq === 'string') {
36
+ andConditions.push({ _id: { $eq: idEq } });
37
+ }
38
+ const projectIdEq = params.project?.id?.$eq;
39
+ if (typeof projectIdEq === 'string') {
40
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
41
+ }
42
+ const objectIdEq = params.object?.id;
43
+ if (typeof objectIdEq === 'string') {
44
+ andConditions.push({ 'object.id': { $exists: true, $eq: objectIdEq } });
45
+ }
46
+ const resultIdEq = params.result?.id;
47
+ if (typeof resultIdEq === 'string') {
48
+ andConditions.push({ 'result.id': { $exists: true, $eq: resultIdEq } });
49
+ }
50
+ if (typeof params.typeOf === 'string') {
51
+ andConditions.push({ typeOf: { $eq: params.typeOf } });
52
+ }
53
+ const startDateGte = params.startFrom;
54
+ if (startDateGte instanceof Date) {
55
+ andConditions.push({ startDate: { $gte: startDateGte } });
56
+ }
57
+ const startDateLte = params.startThrough;
58
+ if (startDateLte instanceof Date) {
59
+ andConditions.push({ startDate: { $lte: startDateLte } });
60
+ }
61
+ return andConditions;
62
+ }
63
+ /**
64
+ * アクション開始
65
+ */
66
+ async startUpdateAction(attributes) {
67
+ const startDate = new Date();
68
+ const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
69
+ const creatingAction = {
70
+ ...attributes,
71
+ actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
72
+ startDate,
73
+ expires
74
+ };
75
+ const result = await this.updateActionModel.insertMany(creatingAction, { rawResult: true });
76
+ const id = result.insertedIds?.[0]?.toHexString();
77
+ if (typeof id !== 'string') {
78
+ throw new factory_1.factory.errors.Internal('action not saved');
79
+ }
80
+ return { id, startDate, typeOf: creatingAction.typeOf };
81
+ }
82
+ async completeUpdateAction(params) {
83
+ const doc = await this.updateActionModel.findOneAndUpdate({
84
+ _id: { $eq: params.id },
85
+ typeOf: { $eq: params.typeOf }
86
+ }, {
87
+ $set: {
88
+ actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
89
+ result: params.result,
90
+ endDate: new Date()
91
+ }
92
+ }, { new: false, projection: { _id: 1 } })
93
+ .lean()
94
+ .exec();
95
+ if (doc === null) {
96
+ throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
97
+ }
98
+ }
99
+ /**
100
+ * アクション失敗
101
+ */
102
+ async giveUpUpdateAction(params) {
103
+ const actionError = Array.isArray(params.error)
104
+ ? params.error.map(unknown2actionError_1.unknown2actionError)
105
+ : (0, unknown2actionError_1.unknown2actionError)(params.error);
106
+ const doc = await this.updateActionModel.findOneAndUpdate({
107
+ typeOf: { $eq: params.typeOf },
108
+ _id: { $eq: params.id }
109
+ }, {
110
+ $set: {
111
+ actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
112
+ error: actionError,
113
+ endDate: new Date()
114
+ }
115
+ }, { new: true, projection: { _id: 1 } })
116
+ .lean()
117
+ .exec();
118
+ if (doc === null) {
119
+ throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
120
+ }
121
+ }
122
+ async findUpdateActions(params, inclusion) {
123
+ const conditions = UpdateActionRepo.CREATE_MONGO_CONDITIONS(params);
124
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
125
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
126
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
127
+ }
128
+ const projection = {
129
+ _id: 0,
130
+ id: { $toString: '$_id' },
131
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
132
+ };
133
+ const query = this.updateActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
134
+ if (typeof params.limit === 'number' && params.limit > 0) {
135
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
136
+ query.limit(params.limit)
137
+ .skip(params.limit * (page - 1));
138
+ }
139
+ /* istanbul ignore else */
140
+ if (params.sort?.startDate !== undefined) {
141
+ query.sort({ startDate: params.sort.startDate });
142
+ }
143
+ // const explainResult = await (<any>query).explain();
144
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
145
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
146
+ .lean() // 2024-08-26~
147
+ .exec();
148
+ }
149
+ async findUpdateActionsBySameAs(params) {
150
+ const projection = {
151
+ _id: 0,
152
+ id: { $toString: '$_id' },
153
+ actionStatus: 1,
154
+ error: 1
155
+ };
156
+ const query = this.updateActionModel.find({
157
+ typeOf: { $eq: params.typeOf.$eq },
158
+ 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq }
159
+ }, projection)
160
+ .limit(1);
161
+ return query
162
+ .lean()
163
+ .exec();
164
+ }
165
+ }
166
+ exports.UpdateActionRepo = UpdateActionRepo;
@@ -0,0 +1,39 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { factory } from '../../factory';
3
+ import { IDocType } from '../mongoose/schemas/action/use';
4
+ type StartableActionType = factory.actionType.UseAction;
5
+ type IAction = IDocType & {
6
+ id: string;
7
+ };
8
+ type IKeyOfProjection = keyof IDocType;
9
+ type IFindParams = factory.action.consume.use.reservation.IFindParams;
10
+ /**
11
+ * 予約使用アクションリポジトリ
12
+ */
13
+ export declare class UseActionRepo {
14
+ private readonly useActionModel;
15
+ constructor(connection: Connection);
16
+ static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'actionStatus' | 'id' | 'object' | 'project' | 'startFrom' | 'startThrough'>): FilterQuery<IDocType>[];
17
+ /**
18
+ * アクション開始
19
+ */
20
+ startUseAction(attributes: factory.action.consume.use.reservation.IAttributes): Promise<Pick<IAction, 'id' | 'typeOf' | 'startDate'>>;
21
+ completeUseAction(params: {
22
+ typeOf: StartableActionType;
23
+ id: string;
24
+ }): Promise<void>;
25
+ /**
26
+ * アクション失敗
27
+ */
28
+ giveUpUseAction(params: {
29
+ typeOf: StartableActionType;
30
+ id: string;
31
+ error: Error | Error[] | unknown;
32
+ }): Promise<void>;
33
+ findUseActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<IAction[]>;
34
+ /**
35
+ * 移行処理
36
+ */
37
+ migrateUseAction(params: factory.action.consume.use.reservation.IAction): Promise<import("mongoose").UpdateWriteOpResult>;
38
+ }
39
+ export {};
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseActionRepo = void 0;
4
+ const factory_1 = require("../../factory");
5
+ const settings_1 = require("../../settings");
6
+ const use_1 = require("../mongoose/schemas/action/use");
7
+ const unknown2actionError_1 = require("./unknown2actionError");
8
+ const AVAILABLE_PROJECT_FIELDS = [
9
+ 'project',
10
+ 'actionStatus',
11
+ 'typeOf',
12
+ 'agent',
13
+ 'error',
14
+ 'object',
15
+ 'startDate',
16
+ 'endDate',
17
+ 'instrument',
18
+ 'location',
19
+ 'expires'
20
+ ];
21
+ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
22
+ /**
23
+ * 予約使用アクションリポジトリ
24
+ */
25
+ class UseActionRepo {
26
+ useActionModel;
27
+ constructor(connection) {
28
+ this.useActionModel = connection.model(use_1.modelName, (0, use_1.createSchema)());
29
+ }
30
+ static CREATE_MONGO_CONDITIONS(params) {
31
+ const andConditions = [];
32
+ const actionStatusEq = params.actionStatus;
33
+ if (typeof actionStatusEq === 'string') {
34
+ andConditions.push({ actionStatus: { $eq: actionStatusEq } });
35
+ }
36
+ const idEq = params.id;
37
+ if (typeof idEq === 'string') {
38
+ andConditions.push({ _id: { $eq: idEq } });
39
+ }
40
+ const projectIdEq = params.project?.id?.$eq;
41
+ if (typeof projectIdEq === 'string') {
42
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
43
+ }
44
+ const startDateGte = params.startFrom;
45
+ if (startDateGte instanceof Date) {
46
+ andConditions.push({ startDate: { $gte: startDateGte } });
47
+ }
48
+ const startDateLte = params.startThrough;
49
+ if (startDateLte instanceof Date) {
50
+ andConditions.push({ startDate: { $lte: startDateLte } });
51
+ }
52
+ const objectIdEq = params.object?.id;
53
+ if (typeof objectIdEq === 'string') {
54
+ andConditions.push({ 'object.id': { $exists: true, $eq: objectIdEq } });
55
+ }
56
+ return andConditions;
57
+ }
58
+ /**
59
+ * アクション開始
60
+ */
61
+ async startUseAction(attributes) {
62
+ const startDate = new Date();
63
+ const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
64
+ const creatingAction = {
65
+ ...attributes,
66
+ actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
67
+ startDate,
68
+ expires
69
+ };
70
+ const result = await this.useActionModel.insertMany(creatingAction, { rawResult: true });
71
+ const id = result.insertedIds?.[0]?.toHexString();
72
+ if (typeof id !== 'string') {
73
+ throw new factory_1.factory.errors.Internal('action not saved');
74
+ }
75
+ return { id, startDate, typeOf: creatingAction.typeOf };
76
+ }
77
+ async completeUseAction(params) {
78
+ const doc = await this.useActionModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
79
+ $set: {
80
+ actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
81
+ // result: params.result,
82
+ endDate: new Date()
83
+ }
84
+ }, { new: false, projection: { _id: 1 } })
85
+ .lean()
86
+ .exec();
87
+ if (doc === null) {
88
+ throw new factory_1.factory.errors.NotFound(this.useActionModel.modelName);
89
+ }
90
+ }
91
+ /**
92
+ * アクション失敗
93
+ */
94
+ async giveUpUseAction(params) {
95
+ const actionError = Array.isArray(params.error)
96
+ ? params.error.map(unknown2actionError_1.unknown2actionError)
97
+ : (0, unknown2actionError_1.unknown2actionError)(params.error);
98
+ const doc = await this.useActionModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
99
+ $set: {
100
+ actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
101
+ error: actionError,
102
+ endDate: new Date()
103
+ }
104
+ }, { new: true, projection: { _id: 1 } })
105
+ .lean()
106
+ .exec();
107
+ if (doc === null) {
108
+ throw new factory_1.factory.errors.NotFound(this.useActionModel.modelName);
109
+ }
110
+ }
111
+ async findUseActions(params, inclusion) {
112
+ const conditions = UseActionRepo.CREATE_MONGO_CONDITIONS(params);
113
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
114
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
115
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
116
+ }
117
+ const projection = {
118
+ _id: 0,
119
+ id: { $toString: '$_id' },
120
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
121
+ };
122
+ const query = this.useActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
123
+ if (typeof params.limit === 'number' && params.limit > 0) {
124
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
125
+ query.limit(params.limit)
126
+ .skip(params.limit * (page - 1));
127
+ }
128
+ /* istanbul ignore else */
129
+ if (params.sort?.startDate !== undefined) {
130
+ query.sort({ startDate: params.sort.startDate });
131
+ }
132
+ // const explainResult = await (<any>query).explain();
133
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
134
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
135
+ .lean() // 2024-08-26~
136
+ .exec();
137
+ }
138
+ /**
139
+ * 移行処理
140
+ */
141
+ async migrateUseAction(params) {
142
+ const { id, ...upserting } = params;
143
+ return this.useActionModel.updateOne({
144
+ _id: { $eq: id }
145
+ }, {
146
+ $setOnInsert: {
147
+ ...upserting,
148
+ _id: id
149
+ }
150
+ }, { upsert: true });
151
+ }
152
+ }
153
+ exports.UseActionRepo = UseActionRepo;
@@ -1,22 +1,17 @@
1
- import { FilterQuery } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import { factory } from '../factory';
3
- import type { IDocType } from './mongoose/schemas/action';
4
- import { IAction, IKeyOfProjection, ActionProcessRepo, ICancelActionAction, IActionRecipe } from './action/actionProcess';
5
- export type IAction4transaction<T extends factory.actionType.AcceptAction | factory.actionType.AuthorizeAction> = T extends factory.actionType.AcceptAction ? factory.action.accept.coaOffer.IAction | factory.action.accept.pay.IAction : T extends factory.actionType.AuthorizeAction ? (factory.action.authorize.offer.eventService.IAction | factory.action.authorize.paymentMethod.any.IAction) : never;
3
+ import { IAction, IKeyOfProjection, ActionProcessRepo, ICancelActionAction, IActionRecipe } from './action/anyAction/actionProcess';
6
4
  export { ICancelActionAction };
7
5
  /**
8
6
  * 汎用アクションリポジトリで開始可能なアクションタイプ
9
7
  */
10
- type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction>;
11
- type IAvailableActionRecipe = IActionRecipe<Exclude<factory.recipe.RecipeCategory, factory.recipe.RecipeCategory.publishPaymentUrl | factory.recipe.RecipeCategory.checkMovieTicket | factory.recipe.RecipeCategory.acceptCOAOffer | factory.recipe.RecipeCategory.authorizeInvoice | factory.recipe.RecipeCategory.authorizeInvoice3ds | factory.recipe.RecipeCategory.payCreditCard | factory.recipe.RecipeCategory.payMovieTicket | factory.recipe.RecipeCategory.refundCreditCard | factory.recipe.RecipeCategory.refundMovieTicket>>;
12
- export interface IDeleteActionResult {
13
- identifier: string;
14
- deletedCount?: number;
15
- }
8
+ export type StartableActionType = factory.actionType.AuthorizeAction | factory.actionType.CancelAction | factory.actionType.ConfirmAction | factory.actionType.OrderAction | factory.actionType.ReserveAction | factory.actionType.ReturnAction;
9
+ export type IAvailableActionRecipe = IActionRecipe<Exclude<factory.recipe.RecipeCategory, factory.recipe.RecipeCategory.publishPaymentUrl | factory.recipe.RecipeCategory.checkMovieTicket | factory.recipe.RecipeCategory.acceptCOAOffer | factory.recipe.RecipeCategory.authorizeInvoice | factory.recipe.RecipeCategory.authorizeInvoice3ds | factory.recipe.RecipeCategory.payCreditCard | factory.recipe.RecipeCategory.payMovieTicket | factory.recipe.RecipeCategory.refundCreditCard | factory.recipe.RecipeCategory.refundMovieTicket>>;
16
10
  /**
17
11
  * アクションリポジトリ
18
12
  */
19
13
  export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActionType>, IAvailableActionRecipe> {
14
+ constructor(connection: Connection);
20
15
  /**
21
16
  * 汎用アクション検索
22
17
  */
@@ -25,95 +20,4 @@ export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActio
25
20
  $eq?: T;
26
21
  };
27
22
  }, inclusion: IKeyOfProjection[]): Promise<IAction<T>[]>;
28
- /**
29
- * 取引に対するアクションを検索する
30
- */
31
- searchByPurpose<T extends factory.actionType.AuthorizeAction>(params: {
32
- typeOf?: T;
33
- purpose: {
34
- typeOf: factory.transactionType;
35
- id: string;
36
- };
37
- object?: {
38
- typeOf?: {
39
- $eq?: factory.action.authorize.offer.eventService.ObjectType.SeatReservation | factory.action.authorize.paymentMethod.any.ResultType.Payment;
40
- };
41
- paymentMethodId?: {
42
- $eq?: string;
43
- };
44
- };
45
- actionStatus?: {
46
- $eq?: factory.actionStatusType.CompletedActionStatus;
47
- };
48
- sort?: factory.action.ISortOrder;
49
- }): Promise<IAction4transaction<T>[]>;
50
- /**
51
- * 注文番号から、注文に対するアクションを検索する
52
- */
53
- searchByOrderNumber(params: {
54
- orderNumber: string;
55
- sort?: factory.action.ISortOrder;
56
- }): Promise<IAction<factory.actionType>[]>;
57
- /**
58
- * 注文番号から、注文に対するアクションを削除する
59
- */
60
- deleteActionsByOrderNumber(params: {
61
- project: {
62
- id: string;
63
- };
64
- orderNumber: string;
65
- }): Promise<IDeleteActionResult[]>;
66
- deleteByProject(params: {
67
- project: {
68
- id: string;
69
- };
70
- }): Promise<void>;
71
- /**
72
- * 開始日時を一定期間過ぎたアクションを削除する
73
- */
74
- deleteStartDatePassedCertainPeriod(params: {
75
- $lt: Date;
76
- }): Promise<import("mongodb").DeleteResult>;
77
- /**
78
- * 終了日時を一定期間過ぎたアクションを削除する
79
- * 作成日時を一定期間過ぎたアクションレシピも削除する
80
- */
81
- deleteEndDatePassedCertainPeriod(params: {
82
- $lt: Date;
83
- }): Promise<{
84
- deleteActionRecipesResult: import("mongodb").DeleteResult;
85
- deleteActionsResult: import("mongodb").DeleteResult;
86
- } | undefined>;
87
- /**
88
- * 取引からアクションを削除する
89
- */
90
- deleteActionsByTransactionId(params: {
91
- project: {
92
- id: string;
93
- };
94
- transaction: {
95
- typeOf: factory.transactionType;
96
- id: string;
97
- };
98
- typeOf: {
99
- $in: factory.actionType[];
100
- };
101
- }): Promise<IDeleteActionResult[]>;
102
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id"> & {
103
- identifier?: string;
104
- } & {
105
- _id: import("mongoose").Types.ObjectId;
106
- } & {
107
- __v: number;
108
- }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id"> & {
109
- identifier?: string;
110
- } & {
111
- _id: import("mongoose").Types.ObjectId;
112
- } & {
113
- __v: number;
114
- }) | null>;
115
- unsetUnnecessaryFields(params: {
116
- filter: FilterQuery<factory.action.IAction<factory.action.IAttributes<factory.actionType, any, any>>>;
117
- $unset: any;
118
- }): Promise<import("mongoose").UpdateWriteOpResult>;
119
23
  }