@chevre/domain 24.0.0-alpha.2 → 24.0.0-alpha.21

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 (177) hide show
  1. package/lib/chevre/repo/action/acceptCOAOffer.d.ts +23 -0
  2. package/lib/chevre/repo/action/acceptCOAOffer.js +64 -0
  3. package/lib/chevre/repo/action/acceptPay.d.ts +8 -0
  4. package/lib/chevre/repo/action/acceptPay.js +13 -0
  5. package/lib/chevre/repo/action/actionProcess.d.ts +115 -0
  6. package/lib/chevre/repo/action/actionProcess.js +293 -0
  7. package/lib/chevre/repo/action/authorizeOffer.d.ts +21 -0
  8. package/lib/chevre/repo/action/authorizeOffer.js +85 -0
  9. package/lib/chevre/repo/action/checkMovieTicket.d.ts +111 -0
  10. package/lib/chevre/repo/action/checkMovieTicket.js +200 -0
  11. package/lib/chevre/repo/action/checkThing.d.ts +8 -0
  12. package/lib/chevre/repo/action/checkThing.js +13 -0
  13. package/lib/chevre/repo/action.d.ts +9 -249
  14. package/lib/chevre/repo/action.js +308 -708
  15. package/lib/chevre/repo/aggregateAction.d.ts +102 -0
  16. package/lib/chevre/repo/aggregateAction.js +379 -0
  17. package/lib/chevre/repo/mongoose/schemas/transaction.js +31 -0
  18. package/lib/chevre/repo/orderInTransaction.d.ts +8 -0
  19. package/lib/chevre/repo/orderInTransaction.js +16 -2
  20. package/lib/chevre/repo/orderNumber.d.ts +3 -2
  21. package/lib/chevre/repo/orderNumber.js +23 -28
  22. package/lib/chevre/repo/transaction/moneyTransfer.d.ts +61 -0
  23. package/lib/chevre/repo/transaction/moneyTransfer.js +379 -0
  24. package/lib/chevre/repo/transaction/placeOrder.d.ts +140 -0
  25. package/lib/chevre/repo/transaction/placeOrder.js +528 -0
  26. package/lib/chevre/repo/transaction/returnOrder.d.ts +45 -0
  27. package/lib/chevre/repo/transaction/returnOrder.js +341 -0
  28. package/lib/chevre/repo/transaction.d.ts +1 -125
  29. package/lib/chevre/repo/transaction.js +726 -632
  30. package/lib/chevre/repository.d.ts +49 -0
  31. package/lib/chevre/repository.js +107 -2
  32. package/lib/chevre/service/aggregation/system.d.ts +10 -10
  33. package/lib/chevre/service/aggregation/system.js +9 -9
  34. package/lib/chevre/service/assetTransaction/pay/check.d.ts +5 -4
  35. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.d.ts +5 -2
  36. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +3 -3
  37. package/lib/chevre/service/assetTransaction/pay/start/factory.d.ts +51 -3
  38. package/lib/chevre/service/assetTransaction/pay/start/factory.js +58 -21
  39. package/lib/chevre/service/assetTransaction/pay/start/preStart/fixPaymentService.d.ts +10 -0
  40. package/lib/chevre/service/assetTransaction/pay/start/preStart/fixPaymentService.js +88 -0
  41. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.d.ts +55 -0
  42. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +56 -0
  43. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +3 -1
  44. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +1 -11
  45. package/lib/chevre/service/assetTransaction/pay/start.d.ts +2 -0
  46. package/lib/chevre/service/assetTransaction/pay/start.js +8 -132
  47. package/lib/chevre/service/notification/triggerWebhook.d.ts +7 -6
  48. package/lib/chevre/service/offer/event/authorize.d.ts +2 -2
  49. package/lib/chevre/service/offer/event/authorize.js +3 -3
  50. package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +2 -2
  51. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +1 -1
  52. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.d.ts +0 -2
  53. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -0
  54. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -2
  55. package/lib/chevre/service/offer/event/voidTransaction.js +2 -2
  56. package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +3 -3
  57. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +2 -2
  58. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +16 -5
  59. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +7 -7
  60. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +6 -4
  61. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -10
  62. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +21 -13
  63. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +19 -10
  64. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +2 -2
  65. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +2 -2
  66. package/lib/chevre/service/offer/moneyTransfer/authorize.js +6 -3
  67. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.d.ts +2 -2
  68. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +4 -1
  69. package/lib/chevre/service/offer/product.d.ts +3 -3
  70. package/lib/chevre/service/offer/product.js +4 -4
  71. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  72. package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
  73. package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +2 -2
  74. package/lib/chevre/service/order/findPlaceOrderTransaction.js +1 -1
  75. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.d.ts +16 -0
  76. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +97 -0
  77. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.d.ts +21 -0
  78. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.js +86 -0
  79. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.d.ts +22 -0
  80. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +112 -0
  81. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onReserveTransactionConfirmed.d.ts +22 -0
  82. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onReserveTransactionConfirmed.js +74 -0
  83. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.d.ts +25 -0
  84. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.js +111 -0
  85. package/lib/chevre/service/order/onAssetTransactionStatusChanged/processing2inTransit.d.ts +16 -0
  86. package/lib/chevre/service/order/onAssetTransactionStatusChanged/processing2inTransit.js +74 -0
  87. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +8 -30
  88. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +37 -348
  89. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +6 -7
  90. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +6 -5
  91. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +7 -6
  92. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +1 -1
  93. package/lib/chevre/service/order/payOrder.d.ts +2 -2
  94. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +2 -2
  95. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +1 -1
  96. package/lib/chevre/service/order/placeOrder.d.ts +13 -12
  97. package/lib/chevre/service/order/returnOrder.d.ts +2 -2
  98. package/lib/chevre/service/order/returnOrder.js +1 -1
  99. package/lib/chevre/service/order/sendOrder.d.ts +6 -6
  100. package/lib/chevre/service/order/sendOrder.js +10 -8
  101. package/lib/chevre/service/order.d.ts +3 -6
  102. package/lib/chevre/service/order.js +3 -9
  103. package/lib/chevre/service/payment/any/{fixOrderAsNeeded.d.ts → authorize/fixOrderAsNeeded.d.ts} +6 -6
  104. package/lib/chevre/service/payment/any/{fixOrderAsNeeded.js → authorize/fixOrderAsNeeded.js} +5 -8
  105. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +3 -3
  106. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +3 -3
  107. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +1 -1
  108. package/lib/chevre/service/payment/any/authorize.d.ts +92 -0
  109. package/lib/chevre/service/payment/any/authorize.js +225 -0
  110. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +43 -0
  111. package/lib/chevre/service/payment/any/findAcceptAction.js +94 -0
  112. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +41 -0
  113. package/lib/chevre/service/payment/any/findAuthorizeAction.js +83 -0
  114. package/lib/chevre/service/payment/any/findCheckAction.d.ts +45 -0
  115. package/lib/chevre/service/payment/any/findCheckAction.js +89 -0
  116. package/lib/chevre/service/payment/any/invalidatePaymentUrl.d.ts +28 -0
  117. package/lib/chevre/service/payment/any/invalidatePaymentUrl.js +185 -0
  118. package/lib/chevre/service/payment/any/onPayActionCompleted.d.ts +7 -3
  119. package/lib/chevre/service/payment/any/onPayActionCompleted.js +3 -0
  120. package/lib/chevre/service/payment/any/processVoidPayTransaction.d.ts +29 -0
  121. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +125 -0
  122. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +2 -2
  123. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +66 -0
  124. package/lib/chevre/service/payment/any/publishPaymentUrl.js +133 -0
  125. package/lib/chevre/service/payment/any/voidPayTransaction.d.ts +31 -0
  126. package/lib/chevre/service/payment/any/voidPayTransaction.js +38 -0
  127. package/lib/chevre/service/payment/any.d.ts +8 -305
  128. package/lib/chevre/service/payment/any.js +17 -857
  129. package/lib/chevre/service/payment/movieTicket/authorize.d.ts +2 -0
  130. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.d.ts +3 -3
  131. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
  132. package/lib/chevre/service/payment/movieTicket/validation.d.ts +11 -10
  133. package/lib/chevre/service/payment/movieTicket/validation.js +19 -15
  134. package/lib/chevre/service/report/telemetry.d.ts +4 -0
  135. package/lib/chevre/service/report/telemetry.js +7 -12
  136. package/lib/chevre/service/task/acceptCOAOffer.js +11 -6
  137. package/lib/chevre/service/task/authorizePayment.js +6 -2
  138. package/lib/chevre/service/task/checkMovieTicket.js +3 -3
  139. package/lib/chevre/service/task/checkResource.js +2 -2
  140. package/lib/chevre/service/task/confirmPayTransaction.js +2 -2
  141. package/lib/chevre/service/task/deleteTransaction.js +7 -1
  142. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +4 -2
  143. package/lib/chevre/service/task/onOrderPaymentCompleted.js +2 -2
  144. package/lib/chevre/service/task/payment/payByTask.d.ts +14 -12
  145. package/lib/chevre/service/task/placeOrder.js +6 -4
  146. package/lib/chevre/service/task/publishPaymentUrl.js +8 -4
  147. package/lib/chevre/service/task/returnOrder.js +4 -4
  148. package/lib/chevre/service/task/returnPayTransaction.js +4 -3
  149. package/lib/chevre/service/task/sendOrder.js +4 -4
  150. package/lib/chevre/service/task/voidMoneyTransferTransaction.js +6 -3
  151. package/lib/chevre/service/task/voidPayTransaction.js +4 -2
  152. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -3
  153. package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
  154. package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -0
  155. package/lib/chevre/service/transaction/deleteTransaction.js +56 -14
  156. package/lib/chevre/service/transaction/moneyTransfer.d.ts +5 -5
  157. package/lib/chevre/service/transaction/moneyTransfer.js +5 -5
  158. package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -2
  159. package/lib/chevre/service/transaction/placeOrder/confirm.js +10 -9
  160. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +7 -6
  161. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +1 -1
  162. package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.d.ts → issueOrderNumberIfNotExist.d.ts} +4 -4
  163. package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.js → issueOrderNumberIfNotExist.js} +21 -13
  164. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.d.ts +2 -2
  165. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +3 -3
  166. package/lib/chevre/service/transaction/placeOrder/start.d.ts +3 -3
  167. package/lib/chevre/service/transaction/placeOrder/start.js +2 -2
  168. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +23 -0
  169. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +126 -0
  170. package/lib/chevre/service/transaction/placeOrder.d.ts +2 -1
  171. package/lib/chevre/service/transaction/placeOrder.js +3 -1
  172. package/lib/chevre/service/transaction/returnOrder/preStart.d.ts +1 -1
  173. package/lib/chevre/service/transaction/returnOrder.d.ts +16 -14
  174. package/lib/chevre/service/transaction/returnOrder.js +4 -4
  175. package/lib/chevre/service/transaction.d.ts +9 -21
  176. package/lib/chevre/service/transaction.js +5 -111
  177. package/package.json +4 -8
@@ -0,0 +1,102 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ interface IAggregationByStatus {
4
+ actionCount: number;
5
+ avgDuration: number;
6
+ maxDuration: number;
7
+ minDuration: number;
8
+ percentilesDuration: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.actionStatusType;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ interface IAggregateAction {
18
+ statuses: IStatus[];
19
+ }
20
+ /**
21
+ * アクション集計リポジトリ
22
+ */
23
+ export declare class AggregateActionRepo {
24
+ private readonly actionModel;
25
+ constructor(connection: Connection);
26
+ /**
27
+ * イベントと入場ゲート指定で予約使用アクションを集計する
28
+ * discontinue(2024-12-26~)
29
+ */
30
+ aggregateAuthorizeEventServiceOfferAction(params: {
31
+ project?: {
32
+ id?: {
33
+ $ne?: string;
34
+ };
35
+ };
36
+ startFrom: Date;
37
+ startThrough: Date;
38
+ typeOf: factory.actionType;
39
+ }): Promise<IAggregateAction>;
40
+ aggregateAuthorizePaymentAction(params: {
41
+ project?: {
42
+ id?: {
43
+ $ne?: string;
44
+ };
45
+ };
46
+ startFrom: Date;
47
+ startThrough: Date;
48
+ typeOf: factory.actionType;
49
+ }): Promise<IAggregateAction>;
50
+ aggregateAuthorizeOrderAction(params: {
51
+ project?: {
52
+ id?: {
53
+ $ne?: string;
54
+ };
55
+ };
56
+ startFrom: Date;
57
+ startThrough: Date;
58
+ typeOf: factory.actionType;
59
+ }): Promise<IAggregateAction>;
60
+ aggregateCancelReservationAction(params: {
61
+ project?: {
62
+ id?: {
63
+ $ne?: string;
64
+ };
65
+ };
66
+ startFrom: Date;
67
+ startThrough: Date;
68
+ }): Promise<IAggregateAction>;
69
+ /**
70
+ * アクションタイプによる汎用的な集計
71
+ */
72
+ aggregateByTypeOf(params: {
73
+ project?: {
74
+ id?: {
75
+ $ne?: string;
76
+ };
77
+ };
78
+ startFrom: Date;
79
+ startThrough: Date;
80
+ typeOf: factory.actionType;
81
+ }): Promise<IAggregateAction>;
82
+ aggregateCheckMovieTicketAction(params: {
83
+ project?: {
84
+ id?: {
85
+ $ne?: string;
86
+ };
87
+ };
88
+ startFrom: Date;
89
+ startThrough: Date;
90
+ }): Promise<IAggregateAction>;
91
+ aggregatePayMovieTicketAction(params: {
92
+ project?: {
93
+ id?: {
94
+ $ne?: string;
95
+ };
96
+ };
97
+ startFrom: Date;
98
+ startThrough: Date;
99
+ }): Promise<IAggregateAction>;
100
+ private agggregateByStatus;
101
+ }
102
+ export {};
@@ -0,0 +1,379 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AggregateActionRepo = void 0;
27
+ const factory = __importStar(require("../factory"));
28
+ // import { MONGO_MAX_TIME_MS } from '../../settings';
29
+ const action_1 = require("./mongoose/schemas/action");
30
+ /**
31
+ * アクション集計リポジトリ
32
+ */
33
+ class AggregateActionRepo {
34
+ actionModel;
35
+ // private readonly actionRecipeModel: IActionRecipeModel;
36
+ constructor(connection) {
37
+ this.actionModel = connection.model(action_1.modelName, (0, action_1.createSchema)());
38
+ // this.actionRecipeModel = connection.model(recipeModelName, createRecipeSchema());
39
+ }
40
+ /**
41
+ * イベントと入場ゲート指定で予約使用アクションを集計する
42
+ * discontinue(2024-12-26~)
43
+ */
44
+ // public async countUseActionsByEntranceGate(params: {
45
+ // event: { id: string };
46
+ // entranceGateIdentifier: string;
47
+ // }): Promise<IUseActionCountByOffer[]> {
48
+ // return this.actionModel.aggregate([
49
+ // {
50
+ // $match: {
51
+ // actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
52
+ // }
53
+ // },
54
+ // {
55
+ // $match: {
56
+ // typeOf: { $eq: factory.actionType.UseAction }
57
+ // }
58
+ // },
59
+ // {
60
+ // $match: {
61
+ // 'object.typeOf': {
62
+ // $exists: true,
63
+ // $eq: factory.reservationType.EventReservation
64
+ // }
65
+ // }
66
+ // },
67
+ // {
68
+ // $match: {
69
+ // 'object.reservationFor.id': {
70
+ // $exists: true,
71
+ // $eq: params.event.id
72
+ // }
73
+ // }
74
+ // },
75
+ // {
76
+ // $match: {
77
+ // 'location.identifier': {
78
+ // $exists: true,
79
+ // $eq: params.entranceGateIdentifier
80
+ // }
81
+ // }
82
+ // },
83
+ // {
84
+ // $group: {
85
+ // _id: '$object.id',
86
+ // object: { $first: '$object' }
87
+ // }
88
+ // },
89
+ // {
90
+ // $group: {
91
+ // _id: '$object.reservedTicket.ticketType.id',
92
+ // useActionCount: {
93
+ // $sum: 1
94
+ // }
95
+ // }
96
+ // }
97
+ // ])
98
+ // .exec();
99
+ // }
100
+ async aggregateAuthorizeEventServiceOfferAction(params) {
101
+ const statuses = await Promise.all([
102
+ factory.actionStatusType.CompletedActionStatus,
103
+ factory.actionStatusType.CanceledActionStatus,
104
+ factory.actionStatusType.FailedActionStatus
105
+ ].map(async (actionStatus) => {
106
+ const matchConditions = {
107
+ startDate: {
108
+ $gte: params.startFrom,
109
+ $lte: params.startThrough
110
+ },
111
+ typeOf: { $eq: params.typeOf },
112
+ actionStatus: { $eq: actionStatus },
113
+ 'object.typeOf': {
114
+ $exists: true,
115
+ $eq: factory.action.authorize.offer.eventService.ObjectType.SeatReservation
116
+ },
117
+ ...(typeof params.project?.id?.$ne === 'string')
118
+ ? { 'project.id': { $ne: params.project.id.$ne } }
119
+ : undefined
120
+ };
121
+ return this.agggregateByStatus({ matchConditions, actionStatus });
122
+ }));
123
+ return { statuses };
124
+ }
125
+ async aggregateAuthorizePaymentAction(params) {
126
+ const statuses = await Promise.all([
127
+ factory.actionStatusType.CompletedActionStatus,
128
+ factory.actionStatusType.CanceledActionStatus,
129
+ factory.actionStatusType.FailedActionStatus
130
+ ].map(async (actionStatus) => {
131
+ const matchConditions = {
132
+ startDate: {
133
+ $gte: params.startFrom,
134
+ $lte: params.startThrough
135
+ },
136
+ typeOf: { $eq: params.typeOf },
137
+ actionStatus: { $eq: actionStatus },
138
+ 'object.typeOf': {
139
+ $exists: true,
140
+ $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
141
+ },
142
+ ...(typeof params.project?.id?.$ne === 'string')
143
+ ? { 'project.id': { $ne: params.project.id.$ne } }
144
+ : undefined
145
+ };
146
+ return this.agggregateByStatus({ matchConditions, actionStatus });
147
+ }));
148
+ return { statuses };
149
+ }
150
+ async aggregateAuthorizeOrderAction(params) {
151
+ const statuses = await Promise.all([
152
+ factory.actionStatusType.CompletedActionStatus,
153
+ factory.actionStatusType.CanceledActionStatus,
154
+ factory.actionStatusType.FailedActionStatus
155
+ ].map(async (actionStatus) => {
156
+ const matchConditions = {
157
+ startDate: {
158
+ $gte: params.startFrom,
159
+ $lte: params.startThrough
160
+ },
161
+ typeOf: { $eq: params.typeOf },
162
+ actionStatus: { $eq: actionStatus },
163
+ 'object.typeOf': {
164
+ $exists: true,
165
+ $eq: factory.order.OrderType.Order
166
+ },
167
+ ...(typeof params.project?.id?.$ne === 'string')
168
+ ? { 'project.id': { $ne: params.project.id.$ne } }
169
+ : undefined
170
+ };
171
+ return this.agggregateByStatus({ matchConditions, actionStatus });
172
+ }));
173
+ return { statuses };
174
+ }
175
+ async aggregateCancelReservationAction(params) {
176
+ const statuses = await Promise.all([
177
+ factory.actionStatusType.CompletedActionStatus,
178
+ factory.actionStatusType.CanceledActionStatus,
179
+ factory.actionStatusType.FailedActionStatus
180
+ ].map(async (actionStatus) => {
181
+ const matchConditions = {
182
+ startDate: {
183
+ $gte: params.startFrom,
184
+ $lte: params.startThrough
185
+ },
186
+ typeOf: { $eq: factory.actionType.CancelAction },
187
+ actionStatus: { $eq: actionStatus },
188
+ 'object.typeOf': {
189
+ $exists: true,
190
+ $in: [
191
+ factory.reservationType.BusReservation,
192
+ factory.reservationType.EventReservation,
193
+ factory.reservationType.ReservationPackage
194
+ ]
195
+ },
196
+ ...(typeof params.project?.id?.$ne === 'string')
197
+ ? { 'project.id': { $ne: params.project.id.$ne } }
198
+ : undefined
199
+ };
200
+ return this.agggregateByStatus({ matchConditions, actionStatus });
201
+ }));
202
+ return { statuses };
203
+ }
204
+ /**
205
+ * アクションタイプによる汎用的な集計
206
+ */
207
+ async aggregateByTypeOf(params) {
208
+ const statuses = await Promise.all([
209
+ factory.actionStatusType.CompletedActionStatus,
210
+ factory.actionStatusType.CanceledActionStatus,
211
+ factory.actionStatusType.FailedActionStatus
212
+ ].map(async (actionStatus) => {
213
+ const matchConditions = {
214
+ startDate: {
215
+ $gte: params.startFrom,
216
+ $lte: params.startThrough
217
+ },
218
+ typeOf: { $eq: params.typeOf },
219
+ actionStatus: { $eq: actionStatus },
220
+ ...(typeof params.project?.id?.$ne === 'string')
221
+ ? { 'project.id': { $ne: params.project.id.$ne } }
222
+ : undefined
223
+ };
224
+ return this.agggregateByStatus({ matchConditions, actionStatus });
225
+ }));
226
+ return { statuses };
227
+ }
228
+ async aggregateCheckMovieTicketAction(params) {
229
+ const statuses = await Promise.all([
230
+ factory.actionStatusType.CompletedActionStatus,
231
+ factory.actionStatusType.CanceledActionStatus,
232
+ factory.actionStatusType.FailedActionStatus
233
+ ].map(async (actionStatus) => {
234
+ const matchConditions = {
235
+ startDate: {
236
+ $gte: params.startFrom,
237
+ $lte: params.startThrough
238
+ },
239
+ typeOf: { $eq: factory.actionType.CheckAction },
240
+ 'object.typeOf': {
241
+ $exists: true,
242
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
243
+ },
244
+ actionStatus: { $eq: actionStatus },
245
+ ...(typeof params.project?.id?.$ne === 'string')
246
+ ? { 'project.id': { $ne: params.project.id.$ne } }
247
+ : undefined
248
+ };
249
+ return this.agggregateByStatus({ matchConditions, actionStatus });
250
+ }));
251
+ return { statuses };
252
+ }
253
+ async aggregatePayMovieTicketAction(params) {
254
+ const statuses = await Promise.all([
255
+ factory.actionStatusType.CompletedActionStatus,
256
+ factory.actionStatusType.CanceledActionStatus,
257
+ factory.actionStatusType.FailedActionStatus
258
+ ].map(async (actionStatus) => {
259
+ const matchConditions = {
260
+ startDate: {
261
+ $gte: params.startFrom,
262
+ $lte: params.startThrough
263
+ },
264
+ typeOf: { $eq: factory.actionType.PayAction },
265
+ 'object.typeOf': {
266
+ $exists: true,
267
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
268
+ },
269
+ actionStatus: { $eq: actionStatus },
270
+ ...(typeof params.project?.id?.$ne === 'string')
271
+ ? { 'project.id': { $ne: params.project.id.$ne } }
272
+ : undefined
273
+ };
274
+ return this.agggregateByStatus({ matchConditions, actionStatus });
275
+ }));
276
+ return { statuses };
277
+ }
278
+ async agggregateByStatus(params) {
279
+ const aggregations = await this.actionModel.aggregate([
280
+ { $match: params.matchConditions },
281
+ {
282
+ $project: {
283
+ duration: { $subtract: ['$endDate', '$startDate'] },
284
+ actionStatus: '$actionStatus',
285
+ startDate: '$startDate',
286
+ endDate: '$endDate',
287
+ typeOf: '$typeOf'
288
+ }
289
+ },
290
+ {
291
+ $group: {
292
+ _id: '$typeOf',
293
+ actionCount: { $sum: 1 },
294
+ maxDuration: { $max: '$duration' },
295
+ minDuration: { $min: '$duration' },
296
+ avgDuration: { $avg: '$duration' }
297
+ }
298
+ },
299
+ {
300
+ $project: {
301
+ _id: 0,
302
+ actionCount: '$actionCount',
303
+ avgDuration: '$avgDuration',
304
+ maxDuration: '$maxDuration',
305
+ minDuration: '$minDuration'
306
+ }
307
+ }
308
+ ])
309
+ .exec();
310
+ const percents = [50, 95, 99];
311
+ if (aggregations.length === 0) {
312
+ return {
313
+ status: params.actionStatus,
314
+ aggregation: {
315
+ actionCount: 0,
316
+ avgDuration: 0,
317
+ maxDuration: 0,
318
+ minDuration: 0,
319
+ percentilesDuration: percents.map((percent) => {
320
+ return {
321
+ name: String(percent),
322
+ value: 0
323
+ };
324
+ })
325
+ }
326
+ };
327
+ }
328
+ const ranks4percentile = percents.map((percentile) => {
329
+ return {
330
+ percentile,
331
+ rank: Math.floor(aggregations[0].actionCount * percentile / 100)
332
+ };
333
+ });
334
+ const aggregations2 = await this.actionModel.aggregate([
335
+ {
336
+ $match: params.matchConditions
337
+ },
338
+ {
339
+ $project: {
340
+ duration: { $subtract: ['$endDate', '$startDate'] },
341
+ actionStatus: '$actionStatus',
342
+ startDate: '$startDate',
343
+ endDate: '$endDate',
344
+ typeOf: '$typeOf'
345
+ }
346
+ },
347
+ { $sort: { duration: 1 } },
348
+ {
349
+ $group: {
350
+ _id: '$typeOf',
351
+ durations: { $push: '$duration' }
352
+ }
353
+ },
354
+ {
355
+ $project: {
356
+ _id: 0,
357
+ avgSmallDuration: '$avgSmallDuration',
358
+ avgMediumDuration: '$avgMediumDuration',
359
+ avgLargeDuration: '$avgLargeDuration',
360
+ percentilesDuration: ranks4percentile.map((rank) => {
361
+ return {
362
+ name: String(rank.percentile),
363
+ value: { $arrayElemAt: ['$durations', rank.rank] }
364
+ };
365
+ })
366
+ }
367
+ }
368
+ ])
369
+ .exec();
370
+ return {
371
+ status: params.actionStatus,
372
+ aggregation: {
373
+ ...aggregations[0],
374
+ ...aggregations2[0]
375
+ }
376
+ };
377
+ }
378
+ }
379
+ exports.AggregateActionRepo = AggregateActionRepo;
@@ -163,6 +163,37 @@ const indexes = [
163
163
  }
164
164
  }
165
165
  ],
166
+ [
167
+ // 注文取引のobject.orderNumberも発行されている場合ユニークなはず(2026-02-21~)
168
+ {
169
+ typeOf: 1,
170
+ 'object.orderNumber': 1
171
+ },
172
+ {
173
+ name: 'uniquePlacingOrderNumber20260221',
174
+ unique: true,
175
+ partialFilterExpression: {
176
+ typeOf: factory.transactionType.PlaceOrder,
177
+ 'object.orderNumber': { $exists: true },
178
+ startDate: { $gte: new Date('2026-02-21T11:00:00Z') }
179
+ }
180
+ }
181
+ ],
182
+ [
183
+ // 注文取引のobject.orderNumberも発行されている場合ユニークなはず(2026-02-21~)
184
+ {
185
+ typeOf: 1,
186
+ 'object.orderNumber': 1
187
+ },
188
+ {
189
+ name: 'uniquePlacingOrderNumber',
190
+ unique: true,
191
+ partialFilterExpression: {
192
+ typeOf: factory.transactionType.PlaceOrder,
193
+ 'object.orderNumber': { $exists: true }
194
+ }
195
+ }
196
+ ],
166
197
  [
167
198
  // ひとつの注文取引に対する確定返品取引はユニークなはず
168
199
  { 'object.order.orderNumber': 1 },
@@ -28,6 +28,10 @@ export declare class OrderInTransactionRepo {
28
28
  * 注文を受注する
29
29
  */
30
30
  placeOrder(order: IPlacingOrder): Promise<void>;
31
+ /**
32
+ * 注文documentがなければ作成し、受け入れられたオファーを追加する
33
+ * このメソッドでdocumentが初めて生成される(typeOf:PlaceOrderとして)
34
+ */
31
35
  acceptOffer(params: Pick<IOrderInTransaction, 'acceptedOffers' | 'orderNumber' | 'project'>): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
32
36
  /**
33
37
  * serialNumberからオファーを除外する
@@ -45,6 +49,10 @@ export declare class OrderInTransactionRepo {
45
49
  setCustomer(params: Pick<IOrderInTransaction, 'orderNumber' | 'project'> & {
46
50
  customer: factory.order.ICustomer;
47
51
  }): Promise<import("mongoose").UpdateWriteOpResult>;
52
+ /**
53
+ * 注文ドキュメントからcustomer属性を参照する
54
+ * customer未設定であれば、NotFound
55
+ */
48
56
  findCustomerByOrderNumber(params: {
49
57
  orderNumber: {
50
58
  $eq: string;
@@ -66,6 +66,10 @@ class OrderInTransactionRepo {
66
66
  }, { $set: setFields }, {})
67
67
  .exec();
68
68
  }
69
+ /**
70
+ * 注文documentがなければ作成し、受け入れられたオファーを追加する
71
+ * このメソッドでdocumentが初めて生成される(typeOf:PlaceOrderとして)
72
+ */
69
73
  async acceptOffer(params) {
70
74
  if (!Array.isArray(params.acceptedOffers) || params.acceptedOffers.length === 0) {
71
75
  return;
@@ -78,7 +82,10 @@ class OrderInTransactionRepo {
78
82
  };
79
83
  return this.orderModel.updateOne({
80
84
  typeOf: { $eq: factory.transactionType.PlaceOrder },
81
- orderNumber: { $eq: params.orderNumber }
85
+ orderNumber: { $eq: params.orderNumber },
86
+ // プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
87
+ // 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
88
+ 'project.id': { $eq: params.project.id }
82
89
  }, {
83
90
  $setOnInsert: setOnInsert,
84
91
  $push: {
@@ -130,7 +137,10 @@ class OrderInTransactionRepo {
130
137
  const { customer, orderNumber, project } = params;
131
138
  const filter = {
132
139
  typeOf: { $eq: factory.transactionType.PlaceOrder },
133
- orderNumber: { $eq: orderNumber }
140
+ orderNumber: { $eq: orderNumber },
141
+ // プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
142
+ // 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
143
+ 'project.id': { $eq: project.id }
134
144
  };
135
145
  const setOnInsert = {
136
146
  typeOf: factory.transactionType.PlaceOrder,
@@ -145,6 +155,10 @@ class OrderInTransactionRepo {
145
155
  }, { upsert: true })
146
156
  .exec();
147
157
  }
158
+ /**
159
+ * 注文ドキュメントからcustomer属性を参照する
160
+ * customer未設定であれば、NotFound
161
+ */
148
162
  async findCustomerByOrderNumber(params) {
149
163
  const doc = await this.orderModel.findOne({
150
164
  orderNumber: { $eq: params.orderNumber.$eq }
@@ -9,9 +9,10 @@ export declare class OrderNumberRepo {
9
9
  connection: Connection;
10
10
  });
11
11
  /**
12
- * タイムスタンプから発行する
12
+ * 注文日時から新しい注文番号を発行する
13
+ * グローバルユニークである前提
13
14
  */
14
- publishByTimestamp(params: {
15
+ issueOrderNumber(params: {
15
16
  project: {
16
17
  alternateName: string;
17
18
  };