@chevre/domain 26.0.0-alpha.3 → 26.0.0-alpha.30

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 (189) 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/actionProcess.d.ts +1 -1
  6. package/lib/chevre/repo/action/inform.d.ts +45 -0
  7. package/lib/chevre/repo/action/inform.js +159 -0
  8. package/lib/chevre/repo/action/update.d.ts +56 -0
  9. package/lib/chevre/repo/action/update.js +173 -0
  10. package/lib/chevre/repo/action.d.ts +3 -19
  11. package/lib/chevre/repo/action.js +0 -298
  12. package/lib/chevre/repo/adminAssetTransaction.d.ts +126 -0
  13. package/lib/chevre/repo/adminAssetTransaction.js +491 -0
  14. package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
  15. package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
  16. package/lib/chevre/repo/adminTask.d.ts +25 -8
  17. package/lib/chevre/repo/adminTask.js +31 -32
  18. package/lib/chevre/repo/adminTransaction.d.ts +131 -0
  19. package/lib/chevre/repo/adminTransaction.js +237 -0
  20. package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
  21. package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
  22. package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
  23. package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
  24. package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
  25. package/lib/chevre/repo/aggregateTransaction.js +166 -0
  26. package/lib/chevre/repo/aggregation.d.ts +0 -8
  27. package/lib/chevre/repo/aggregation.js +0 -10
  28. package/lib/chevre/repo/assetTransaction.d.ts +10 -235
  29. package/lib/chevre/repo/assetTransaction.js +48 -636
  30. package/lib/chevre/repo/asyncAction.d.ts +2 -2
  31. package/lib/chevre/repo/authorization.d.ts +0 -6
  32. package/lib/chevre/repo/authorization.js +15 -27
  33. package/lib/chevre/repo/message.d.ts +0 -7
  34. package/lib/chevre/repo/message.js +0 -38
  35. package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → action/inform.d.ts} +5 -5
  36. package/lib/chevre/repo/mongoose/schemas/action/inform.js +81 -0
  37. package/lib/chevre/repo/mongoose/schemas/action/update.d.ts +12 -0
  38. package/lib/chevre/repo/mongoose/schemas/action/update.js +107 -0
  39. package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
  40. package/lib/chevre/repo/mongoose/schemas/action.js +8 -1
  41. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +7 -0
  42. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
  43. package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
  44. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +95 -76
  45. package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
  46. package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
  47. package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
  48. package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
  49. package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
  50. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
  51. package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
  52. package/lib/chevre/repo/mongoose/schemas/task.js +134 -118
  53. package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
  54. package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
  55. package/lib/chevre/repo/orderInTransaction.js +30 -22
  56. package/lib/chevre/repo/scheduledTask.d.ts +5 -2
  57. package/lib/chevre/repo/scheduledTask.js +3 -25
  58. package/lib/chevre/repo/task.d.ts +45 -171
  59. package/lib/chevre/repo/task.js +20 -475
  60. package/lib/chevre/repo/taskDelayed.d.ts +74 -0
  61. package/lib/chevre/repo/taskDelayed.js +195 -0
  62. package/lib/chevre/repo/taskRunning.d.ts +35 -0
  63. package/lib/chevre/repo/taskRunning.js +89 -0
  64. package/lib/chevre/repo/ticket.d.ts +0 -6
  65. package/lib/chevre/repo/ticket.js +0 -11
  66. package/lib/chevre/repo/transaction.d.ts +1 -187
  67. package/lib/chevre/repo/transaction.js +2 -383
  68. package/lib/chevre/repository.d.ts +35 -5
  69. package/lib/chevre/repository.js +79 -13
  70. package/lib/chevre/service/aggregation/system.d.ts +17 -9
  71. package/lib/chevre/service/aggregation/system.js +46 -4
  72. package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
  73. package/lib/chevre/service/assetTransaction/refund.js +2 -2
  74. package/lib/chevre/service/asyncAction.d.ts +2 -2
  75. package/lib/chevre/service/asyncAction.js +1 -4
  76. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
  77. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
  78. package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
  79. package/lib/chevre/service/asyncActionHandler.js +11 -13
  80. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +4 -2
  81. package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
  82. package/lib/chevre/service/event.d.ts +4 -2
  83. package/lib/chevre/service/event.js +3 -3
  84. package/lib/chevre/service/notification/triggerWebhook.d.ts +4 -2
  85. package/lib/chevre/service/notification/triggerWebhook.js +5 -16
  86. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
  87. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  88. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  89. package/lib/chevre/service/offer/onEventChanged.js +0 -2
  90. package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
  91. package/lib/chevre/service/order/deleteOrder.js +0 -1
  92. package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
  93. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
  94. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +2 -4
  95. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +2 -4
  96. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
  97. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
  98. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
  99. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
  100. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +3 -5
  101. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
  102. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  103. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +5 -7
  104. package/lib/chevre/service/order/onOrderUpdated/factory.js +0 -3
  105. package/lib/chevre/service/order/returnOrder.d.ts +0 -2
  106. package/lib/chevre/service/order/returnOrder.js +8 -40
  107. package/lib/chevre/service/order/sendOrder.d.ts +0 -2
  108. package/lib/chevre/service/order/sendOrder.js +41 -55
  109. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  110. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  111. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  112. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  113. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  114. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  115. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
  116. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
  117. package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
  118. package/lib/chevre/service/project.d.ts +0 -3
  119. package/lib/chevre/service/project.js +0 -1
  120. package/lib/chevre/service/reserve/cancelReservation.js +3 -3
  121. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  122. package/lib/chevre/service/reserve/confirmReservation.js +1 -1
  123. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
  124. package/lib/chevre/service/reserve/useReservation.js +1 -1
  125. package/lib/chevre/service/scheduledTask.d.ts +1 -4
  126. package/lib/chevre/service/scheduledTask.js +3 -10
  127. package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
  128. package/lib/chevre/service/scheduledTaskHandler.js +0 -13
  129. package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
  130. package/lib/chevre/service/task/authorizePayment.js +1 -7
  131. package/lib/chevre/service/task/checkMovieTicket.js +1 -7
  132. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
  133. package/lib/chevre/service/task/deleteTransaction.js +8 -39
  134. package/lib/chevre/service/task/importEventsFromCOA.js +4 -2
  135. package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
  136. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.d.ts +4 -2
  137. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +4 -4
  138. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +4 -2
  139. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +4 -4
  140. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +4 -2
  141. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +4 -4
  142. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +4 -2
  143. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +4 -4
  144. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +4 -2
  145. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +4 -4
  146. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +4 -2
  147. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +4 -4
  148. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +4 -2
  149. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +4 -4
  150. package/lib/chevre/service/task/onResourceDeleted.js +4 -3
  151. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +0 -1
  152. package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +0 -1
  153. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +0 -1
  154. package/lib/chevre/service/task/onResourceUpdated.js +0 -8
  155. package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
  156. package/lib/chevre/service/task/returnOrder.js +2 -5
  157. package/lib/chevre/service/task/returnPayTransaction.js +2 -2
  158. package/lib/chevre/service/task/sendOrder.js +2 -2
  159. package/lib/chevre/service/task/syncResourcesFromCOA.js +31 -23
  160. package/lib/chevre/service/task/triggerWebhook.js +4 -2
  161. package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
  162. package/lib/chevre/service/task.d.ts +3 -22
  163. package/lib/chevre/service/task.js +8 -40
  164. package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +0 -1
  165. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
  166. package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
  167. package/lib/chevre/service/taskHandler.d.ts +1 -2
  168. package/lib/chevre/service/taskHandler.js +7 -19
  169. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
  170. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
  171. package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -2
  172. package/lib/chevre/service/transaction/deleteTransaction.js +5 -5
  173. package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
  174. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  175. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  176. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  177. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
  178. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  179. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  180. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  181. package/lib/chevre/service/transaction/returnOrder.js +15 -13
  182. package/lib/chevre/service/transaction.d.ts +2 -0
  183. package/lib/chevre/service/transaction.js +0 -2
  184. package/lib/chevre/service/validation/validateOrder.js +2 -2
  185. package/lib/chevre/taskSettings.d.ts +4 -4
  186. package/package.json +2 -2
  187. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -227
  188. package/lib/chevre/repo/ownershipInfo.d.ts +0 -122
  189. package/lib/chevre/repo/ownershipInfo.js +0 -466
@@ -0,0 +1,32 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ interface IAggregationByStatus {
4
+ taskCount: number;
5
+ avgLatency: number;
6
+ maxLatency: number;
7
+ minLatency: number;
8
+ percentilesLatency: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.taskStatus;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ interface IAggregateTask {
18
+ statuses: IStatus[];
19
+ }
20
+ /**
21
+ * 予定タスク集計リポジトリ
22
+ */
23
+ export declare class AggregateScheduledTaskRepo {
24
+ private readonly scheduledTaskModel;
25
+ constructor(connection: Connection);
26
+ aggregateScheduledTask(params: {
27
+ runsFrom: Date;
28
+ runsThrough: Date;
29
+ }): Promise<IAggregateTask>;
30
+ private agggregateByStatus;
31
+ }
32
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateScheduledTaskRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
6
+ /**
7
+ * 予定タスク集計リポジトリ
8
+ */
9
+ class AggregateScheduledTaskRepo {
10
+ scheduledTaskModel;
11
+ constructor(connection) {
12
+ this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
13
+ }
14
+ async aggregateScheduledTask(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.taskStatus.Executed,
17
+ factory_1.factory.taskStatus.Aborted
18
+ ].map(async (taskStatus) => {
19
+ const matchConditions = {
20
+ status: { $eq: taskStatus },
21
+ runsAt: {
22
+ $gte: params.runsFrom,
23
+ $lte: params.runsThrough
24
+ },
25
+ // ...(typeof params.project?.id?.$ne === 'string')
26
+ // ? { 'project.id': { $ne: params.project.id.$ne } }
27
+ // : undefined
28
+ };
29
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
30
+ }));
31
+ return { statuses };
32
+ }
33
+ async agggregateByStatus(params) {
34
+ const matchConditions = params.matchConditions;
35
+ const taskStatus = params.status;
36
+ const aggregate1 = this.scheduledTaskModel.aggregate([
37
+ {
38
+ $match: matchConditions
39
+ },
40
+ {
41
+ $project: {
42
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
43
+ status: '$status',
44
+ runsAt: '$runsAt',
45
+ lastTriedAt: '$lastTriedAt'
46
+ }
47
+ },
48
+ {
49
+ $group: {
50
+ _id: '$status',
51
+ taskCount: { $sum: 1 },
52
+ maxLatency: { $max: '$latency' },
53
+ minLatency: { $min: '$latency' },
54
+ avgLatency: { $avg: '$latency' }
55
+ }
56
+ },
57
+ {
58
+ $project: {
59
+ _id: 0,
60
+ taskCount: '$taskCount',
61
+ avgLatency: '$avgLatency',
62
+ maxLatency: '$maxLatency',
63
+ minLatency: '$minLatency'
64
+ }
65
+ }
66
+ ]);
67
+ // const explainResult = await aggregate1.explain();
68
+ // console.dir(explainResult, { depth: null });
69
+ // return;
70
+ const aggregations = await aggregate1.exec();
71
+ const percents = [50, 95, 99];
72
+ if (aggregations.length === 0) {
73
+ return {
74
+ status: taskStatus,
75
+ aggregation: {
76
+ taskCount: 0,
77
+ avgLatency: 0,
78
+ maxLatency: 0,
79
+ minLatency: 0,
80
+ percentilesLatency: percents.map((percent) => {
81
+ return {
82
+ name: String(percent),
83
+ value: 0
84
+ };
85
+ })
86
+ }
87
+ };
88
+ }
89
+ const ranks4percentile = percents.map((percentile) => {
90
+ return {
91
+ percentile,
92
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
93
+ };
94
+ });
95
+ const aggregate2 = this.scheduledTaskModel.aggregate([
96
+ {
97
+ $match: matchConditions
98
+ },
99
+ {
100
+ $project: {
101
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
102
+ status: '$status',
103
+ runsAt: '$runsAt',
104
+ lastTriedAt: '$lastTriedAt'
105
+ }
106
+ },
107
+ { $sort: { latency: 1 } },
108
+ {
109
+ $group: {
110
+ _id: '$status',
111
+ latencies: { $push: '$latency' }
112
+ }
113
+ },
114
+ {
115
+ $project: {
116
+ _id: 0,
117
+ percentilesLatency: ranks4percentile.map((rank) => {
118
+ return {
119
+ name: String(rank.percentile),
120
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
121
+ };
122
+ })
123
+ }
124
+ }
125
+ ]);
126
+ const aggregations2 = await aggregate2.exec();
127
+ return {
128
+ status: taskStatus,
129
+ aggregation: {
130
+ ...aggregations[0],
131
+ ...aggregations2[0]
132
+ }
133
+ };
134
+ }
135
+ }
136
+ exports.AggregateScheduledTaskRepo = AggregateScheduledTaskRepo;
@@ -0,0 +1,39 @@
1
+ import type { Connection } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ interface IAggregationByStatus {
4
+ transactionCount: 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.transactionStatusType;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ export interface IAggregatePlaceOrder {
18
+ statuses: IStatus[];
19
+ }
20
+ /**
21
+ * 取引集計リポジトリ
22
+ */
23
+ export declare class AggregateTransactionRepo {
24
+ private readonly transactionModel;
25
+ constructor(connection: Connection);
26
+ aggregatePlaceOrder(params: {
27
+ project?: {
28
+ id?: {
29
+ $ne?: string;
30
+ };
31
+ };
32
+ startFrom: Date;
33
+ startThrough: Date;
34
+ typeOf: factory.transactionType;
35
+ clientId?: string;
36
+ }): Promise<IAggregatePlaceOrder>;
37
+ private agggregateByStatus;
38
+ }
39
+ export {};
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateTransactionRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const transaction_1 = require("./mongoose/schemas/transaction");
6
+ /**
7
+ * 取引集計リポジトリ
8
+ */
9
+ class AggregateTransactionRepo {
10
+ transactionModel;
11
+ constructor(connection) {
12
+ this.transactionModel = connection.model(transaction_1.modelName, (0, transaction_1.createSchema)());
13
+ }
14
+ async aggregatePlaceOrder(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.transactionStatusType.Confirmed,
17
+ factory_1.factory.transactionStatusType.Canceled,
18
+ factory_1.factory.transactionStatusType.Expired
19
+ ].map(async (transactionStatus) => {
20
+ const matchConditions = {
21
+ startDate: {
22
+ $gte: params.startFrom,
23
+ $lte: params.startThrough
24
+ },
25
+ typeOf: { $eq: params.typeOf },
26
+ status: { $eq: transactionStatus },
27
+ ...(typeof params.project?.id?.$ne === 'string')
28
+ ? { 'project.id': { $ne: params.project.id.$ne } }
29
+ : undefined,
30
+ ...(typeof params.clientId === 'string')
31
+ // customerIdentifierAll.push();
32
+ ? {
33
+ 'agent.identifier': {
34
+ $exists: true,
35
+ $all: [{ name: 'clientId', value: params.clientId }]
36
+ }
37
+ }
38
+ : undefined
39
+ };
40
+ return this.agggregateByStatus({ matchConditions, status: transactionStatus });
41
+ }));
42
+ return { statuses };
43
+ }
44
+ async agggregateByStatus(params) {
45
+ const matchConditions = params.matchConditions;
46
+ const transactionStatus = params.status;
47
+ const aggregations = await this.transactionModel.aggregate([
48
+ {
49
+ $match: matchConditions
50
+ },
51
+ {
52
+ $project: {
53
+ duration: { $subtract: ['$endDate', '$startDate'] },
54
+ status: '$status',
55
+ startDate: '$startDate',
56
+ endDate: '$endDate',
57
+ typeOf: '$typeOf'
58
+ }
59
+ },
60
+ {
61
+ $group: {
62
+ _id: '$typeOf',
63
+ transactionCount: { $sum: 1 },
64
+ maxDuration: { $max: '$duration' },
65
+ minDuration: { $min: '$duration' },
66
+ avgDuration: { $avg: '$duration' }
67
+ }
68
+ },
69
+ {
70
+ $project: {
71
+ _id: 0,
72
+ transactionCount: '$transactionCount',
73
+ avgDuration: '$avgDuration',
74
+ maxDuration: '$maxDuration',
75
+ minDuration: '$minDuration'
76
+ }
77
+ }
78
+ ])
79
+ .exec();
80
+ const percents = [50, 95, 99];
81
+ if (aggregations.length === 0) {
82
+ return {
83
+ status: transactionStatus,
84
+ aggregation: {
85
+ transactionCount: 0,
86
+ avgDuration: 0,
87
+ maxDuration: 0,
88
+ minDuration: 0,
89
+ percentilesDuration: percents.map((percent) => {
90
+ return {
91
+ name: String(percent),
92
+ value: 0
93
+ };
94
+ })
95
+ // totalPrice: 0,
96
+ // maxPrice: 0,
97
+ // minPrice: 0,
98
+ // avgPrice: 0
99
+ }
100
+ };
101
+ }
102
+ const ranks4percentile = percents.map((percentile) => {
103
+ return {
104
+ percentile,
105
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
106
+ };
107
+ });
108
+ const aggregations2 = await this.transactionModel.aggregate([
109
+ {
110
+ $match: matchConditions
111
+ },
112
+ {
113
+ $project: {
114
+ duration: { $subtract: ['$endDate', '$startDate'] },
115
+ status: '$status',
116
+ startDate: '$startDate',
117
+ endDate: '$endDate',
118
+ typeOf: '$typeOf'
119
+ // result: '$result',
120
+ // price: {
121
+ // $cond: {
122
+ // if: { $isNumber: '$result.order.price' },
123
+ // then: '$result.order.price',
124
+ // else: 0
125
+ // }
126
+ // }
127
+ }
128
+ },
129
+ { $sort: { duration: 1 } },
130
+ {
131
+ $group: {
132
+ _id: '$typeOf',
133
+ durations: { $push: '$duration' }
134
+ // totalPrice: { $sum: '$price' },
135
+ // maxPrice: { $max: '$price' },
136
+ // minPrice: { $min: '$price' },
137
+ // avgPrice: { $avg: '$price' }
138
+ }
139
+ },
140
+ {
141
+ $project: {
142
+ _id: 0,
143
+ percentilesDuration: ranks4percentile.map((rank) => {
144
+ return {
145
+ name: String(rank.percentile),
146
+ value: { $arrayElemAt: ['$durations', rank.rank] }
147
+ };
148
+ })
149
+ // totalPrice: '$totalPrice',
150
+ // maxPrice: '$maxPrice',
151
+ // minPrice: '$minPrice',
152
+ // avgPrice: '$avgPrice'
153
+ }
154
+ }
155
+ ])
156
+ .exec();
157
+ return {
158
+ status: transactionStatus,
159
+ aggregation: {
160
+ ...aggregations[0],
161
+ ...aggregations2[0]
162
+ }
163
+ };
164
+ }
165
+ }
166
+ exports.AggregateTransactionRepo = AggregateTransactionRepo;
@@ -22,14 +22,6 @@ export declare class AggregationRepo {
22
22
  $lte?: Date;
23
23
  };
24
24
  }): Promise<IAggregation[]>;
25
- /**
26
- * 不要な集計を削除する
27
- */
28
- deleteAggregateStartPassedCertainPeriod(params: {
29
- aggregateStart: {
30
- $lt: Date;
31
- };
32
- }): Promise<import("mongodb").DeleteResult>;
33
25
  unsetUnnecessaryFields(params: {
34
26
  filter: any;
35
27
  $unset: any;
@@ -47,16 +47,6 @@ class AggregationRepo {
47
47
  .sort({ aggregateStart: factory_1.factory.sortType.Ascending })
48
48
  .exec();
49
49
  }
50
- /**
51
- * 不要な集計を削除する
52
- */
53
- async deleteAggregateStartPassedCertainPeriod(params) {
54
- const filter = {
55
- aggregateStart: { $lt: params.aggregateStart.$lt }
56
- };
57
- return this.aggregationModel.deleteMany(filter)
58
- .exec();
59
- }
60
50
  async unsetUnnecessaryFields(params) {
61
51
  return this.aggregationModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
62
52
  .exec();