@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.
- package/lib/chevre/eventEmitter/task.d.ts +8 -23
- package/lib/chevre/eventEmitter/task.js +2 -2
- package/lib/chevre/repo/acceptedOffer.d.ts +0 -7
- package/lib/chevre/repo/acceptedOffer.js +27 -27
- package/lib/chevre/repo/action/actionProcess.d.ts +1 -1
- package/lib/chevre/repo/action/inform.d.ts +45 -0
- package/lib/chevre/repo/action/inform.js +159 -0
- package/lib/chevre/repo/action/update.d.ts +56 -0
- package/lib/chevre/repo/action/update.js +173 -0
- package/lib/chevre/repo/action.d.ts +3 -19
- package/lib/chevre/repo/action.js +0 -298
- package/lib/chevre/repo/adminAssetTransaction.d.ts +126 -0
- package/lib/chevre/repo/adminAssetTransaction.js +491 -0
- package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
- package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
- package/lib/chevre/repo/adminTask.d.ts +25 -8
- package/lib/chevre/repo/adminTask.js +31 -32
- package/lib/chevre/repo/adminTransaction.d.ts +131 -0
- package/lib/chevre/repo/adminTransaction.js +237 -0
- package/lib/chevre/repo/aggregateAssetTransaction.d.ts +43 -0
- package/lib/chevre/repo/aggregateAssetTransaction.js +166 -0
- package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
- package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
- package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
- package/lib/chevre/repo/aggregateTransaction.js +166 -0
- package/lib/chevre/repo/aggregation.d.ts +0 -8
- package/lib/chevre/repo/aggregation.js +0 -10
- package/lib/chevre/repo/assetTransaction.d.ts +10 -235
- package/lib/chevre/repo/assetTransaction.js +48 -636
- package/lib/chevre/repo/asyncAction.d.ts +2 -2
- package/lib/chevre/repo/authorization.d.ts +0 -6
- package/lib/chevre/repo/authorization.js +15 -27
- package/lib/chevre/repo/message.d.ts +0 -7
- package/lib/chevre/repo/message.js +0 -38
- package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → action/inform.d.ts} +5 -5
- package/lib/chevre/repo/mongoose/schemas/action/inform.js +81 -0
- package/lib/chevre/repo/mongoose/schemas/action/update.d.ts +12 -0
- package/lib/chevre/repo/mongoose/schemas/action/update.js +107 -0
- package/lib/chevre/repo/mongoose/schemas/action.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/action.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
- package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +95 -76
- package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
- package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
- package/lib/chevre/repo/mongoose/schemas/task.js +134 -118
- package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
- package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
- package/lib/chevre/repo/orderInTransaction.js +30 -22
- package/lib/chevre/repo/scheduledTask.d.ts +5 -2
- package/lib/chevre/repo/scheduledTask.js +3 -25
- package/lib/chevre/repo/task.d.ts +45 -171
- package/lib/chevre/repo/task.js +20 -475
- package/lib/chevre/repo/taskDelayed.d.ts +74 -0
- package/lib/chevre/repo/taskDelayed.js +195 -0
- package/lib/chevre/repo/taskRunning.d.ts +35 -0
- package/lib/chevre/repo/taskRunning.js +89 -0
- package/lib/chevre/repo/ticket.d.ts +0 -6
- package/lib/chevre/repo/ticket.js +0 -11
- package/lib/chevre/repo/transaction.d.ts +1 -187
- package/lib/chevre/repo/transaction.js +2 -383
- package/lib/chevre/repository.d.ts +35 -5
- package/lib/chevre/repository.js +79 -13
- package/lib/chevre/service/aggregation/system.d.ts +17 -9
- package/lib/chevre/service/aggregation/system.js +46 -4
- package/lib/chevre/service/assetTransaction/cancelReservation/start.js +10 -17
- package/lib/chevre/service/assetTransaction/refund.js +2 -2
- package/lib/chevre/service/asyncAction.d.ts +2 -2
- package/lib/chevre/service/asyncAction.js +1 -4
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
- package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
- package/lib/chevre/service/asyncActionHandler.js +11 -13
- package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +4 -2
- package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
- package/lib/chevre/service/event.d.ts +4 -2
- package/lib/chevre/service/event.js +3 -3
- package/lib/chevre/service/notification/triggerWebhook.d.ts +4 -2
- package/lib/chevre/service/notification/triggerWebhook.js +5 -16
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -3
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
- package/lib/chevre/service/offer/onEventChanged.js +0 -2
- package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
- package/lib/chevre/service/order/deleteOrder.js +0 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +1 -49
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +2 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.js +2 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +3 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +5 -7
- package/lib/chevre/service/order/onOrderUpdated/factory.js +0 -3
- package/lib/chevre/service/order/returnOrder.d.ts +0 -2
- package/lib/chevre/service/order/returnOrder.js +8 -40
- package/lib/chevre/service/order/sendOrder.d.ts +0 -2
- package/lib/chevre/service/order/sendOrder.js +41 -55
- package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
- package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
- package/lib/chevre/service/payment/any/processVoidPayTransaction.js +1 -1
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/project.d.ts +0 -3
- package/lib/chevre/service/project.js +0 -1
- package/lib/chevre/service/reserve/cancelReservation.js +3 -3
- package/lib/chevre/service/reserve/checkInReservation.js +2 -2
- package/lib/chevre/service/reserve/confirmReservation.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
- package/lib/chevre/service/reserve/useReservation.js +1 -1
- package/lib/chevre/service/scheduledTask.d.ts +1 -4
- package/lib/chevre/service/scheduledTask.js +3 -10
- package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
- package/lib/chevre/service/scheduledTaskHandler.js +0 -13
- package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
- package/lib/chevre/service/task/authorizePayment.js +1 -7
- package/lib/chevre/service/task/checkMovieTicket.js +1 -7
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
- package/lib/chevre/service/task/deleteTransaction.js +8 -39
- package/lib/chevre/service/task/importEventsFromCOA.js +4 -2
- package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByAggregateOffer.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +4 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +4 -4
- package/lib/chevre/service/task/onResourceDeleted.js +4 -3
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +0 -1
- package/lib/chevre/service/task/onResourceUpdated.js +0 -8
- package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
- package/lib/chevre/service/task/returnOrder.js +2 -5
- package/lib/chevre/service/task/returnPayTransaction.js +2 -2
- package/lib/chevre/service/task/sendOrder.js +2 -2
- package/lib/chevre/service/task/syncResourcesFromCOA.js +31 -23
- package/lib/chevre/service/task/triggerWebhook.js +4 -2
- package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
- package/lib/chevre/service/task.d.ts +3 -22
- package/lib/chevre/service/task.js +8 -40
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +0 -1
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
- package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
- package/lib/chevre/service/taskHandler.d.ts +1 -2
- package/lib/chevre/service/taskHandler.js +7 -19
- package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +2 -2
- package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +2 -2
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -2
- package/lib/chevre/service/transaction/deleteTransaction.js +5 -5
- package/lib/chevre/service/transaction/placeOrder/confirm.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
- package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
- package/lib/chevre/service/transaction/returnOrder.js +15 -13
- package/lib/chevre/service/transaction.d.ts +2 -0
- package/lib/chevre/service/transaction.js +0 -2
- package/lib/chevre/service/validation/validateOrder.js +2 -2
- package/lib/chevre/taskSettings.d.ts +4 -4
- package/package.json +2 -2
- package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -227
- package/lib/chevre/repo/ownershipInfo.d.ts +0 -122
- 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();
|