@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
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AdminTaskRepo = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
4
8
|
const factory_1 = require("../factory");
|
|
5
9
|
const settings_1 = require("../settings");
|
|
6
10
|
const task_1 = require("./mongoose/schemas/task");
|
|
7
11
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
8
|
-
'alternateName',
|
|
9
12
|
'identifier',
|
|
10
13
|
'description',
|
|
11
14
|
'project',
|
|
@@ -19,7 +22,7 @@ const AVAILABLE_PROJECT_FIELDS = [
|
|
|
19
22
|
'executor',
|
|
20
23
|
'data',
|
|
21
24
|
'dateAborted',
|
|
22
|
-
'expires'
|
|
25
|
+
// 'expires' // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
23
26
|
];
|
|
24
27
|
/**
|
|
25
28
|
* タスク管理リポジトリ
|
|
@@ -65,12 +68,12 @@ class AdminTaskRepo {
|
|
|
65
68
|
if (params.runsThrough instanceof Date) {
|
|
66
69
|
andConditions.push({ runsAt: { $lte: params.runsThrough } });
|
|
67
70
|
}
|
|
68
|
-
if (params.lastTriedFrom instanceof Date) {
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
if (params.lastTriedThrough instanceof Date) {
|
|
72
|
-
|
|
73
|
-
}
|
|
71
|
+
// if (params.lastTriedFrom instanceof Date) {
|
|
72
|
+
// andConditions.push({ lastTriedAt: { $type: 'date', $gte: params.lastTriedFrom } });
|
|
73
|
+
// }
|
|
74
|
+
// if (params.lastTriedThrough instanceof Date) {
|
|
75
|
+
// andConditions.push({ lastTriedAt: { $type: 'date', $lte: params.lastTriedThrough } });
|
|
76
|
+
// }
|
|
74
77
|
const dateAbortedGte = params.dateAborted?.$gte;
|
|
75
78
|
if (dateAbortedGte instanceof Date) {
|
|
76
79
|
andConditions.push({ dateAborted: { $type: 'date', $gte: dateAbortedGte } });
|
|
@@ -79,30 +82,6 @@ class AdminTaskRepo {
|
|
|
79
82
|
if (dateAbortedLte instanceof Date) {
|
|
80
83
|
andConditions.push({ dateAborted: { $type: 'date', $lte: dateAbortedLte } });
|
|
81
84
|
}
|
|
82
|
-
const objectIdEq = params.data?.object?.id?.$eq;
|
|
83
|
-
if (typeof objectIdEq === 'string') {
|
|
84
|
-
andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
|
|
85
|
-
}
|
|
86
|
-
const objectOrderNumberEq = params.data?.object?.orderNumber?.$eq;
|
|
87
|
-
if (typeof objectOrderNumberEq === 'string') {
|
|
88
|
-
andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
|
|
89
|
-
}
|
|
90
|
-
const objectTransactionNumberEq = params.data?.object?.transactionNumber?.$eq;
|
|
91
|
-
if (typeof objectTransactionNumberEq === 'string') {
|
|
92
|
-
andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
|
|
93
|
-
}
|
|
94
|
-
const objectPurposeIdEq = params.data?.purpose?.id?.$eq;
|
|
95
|
-
if (typeof objectPurposeIdEq === 'string') {
|
|
96
|
-
andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
|
|
97
|
-
}
|
|
98
|
-
const objectPurposeOrderNumberEq = params.data?.purpose?.orderNumber?.$eq;
|
|
99
|
-
if (typeof objectPurposeOrderNumberEq === 'string') {
|
|
100
|
-
andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
|
|
101
|
-
}
|
|
102
|
-
const alternateNameRegex = params.alternateName?.$regex;
|
|
103
|
-
if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
|
|
104
|
-
andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
|
|
105
|
-
}
|
|
106
85
|
const identifierRegex = params.identifier?.$regex;
|
|
107
86
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
108
87
|
andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
|
|
@@ -150,6 +129,26 @@ class AdminTaskRepo {
|
|
|
150
129
|
.lean() // lean(2024-09-26~)
|
|
151
130
|
.exec();
|
|
152
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* cron:notifyLatency専用
|
|
134
|
+
*/
|
|
135
|
+
async countDelayedTasks(params) {
|
|
136
|
+
const { limit } = params;
|
|
137
|
+
const runsAtLt = (0, moment_1.default)()
|
|
138
|
+
.add(-params.delayInSeconds, 'seconds')
|
|
139
|
+
.toDate();
|
|
140
|
+
const query = this.taskModel.countDocuments({
|
|
141
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
142
|
+
runsAt: { $lt: runsAtLt },
|
|
143
|
+
...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
|
|
144
|
+
});
|
|
145
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
146
|
+
query.limit(limit);
|
|
147
|
+
}
|
|
148
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
149
|
+
.exec();
|
|
150
|
+
return { count };
|
|
151
|
+
}
|
|
153
152
|
getCursor(conditions, projection) {
|
|
154
153
|
return this.taskModel.find(conditions, projection)
|
|
155
154
|
.sort({ runsAt: factory_1.factory.sortType.Ascending })
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
import { IDocType } from './mongoose/schemas/transaction';
|
|
4
|
+
/**
|
|
5
|
+
* 取引管理リポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class AdminTransactionRepo {
|
|
8
|
+
private readonly transactionModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
countPotentiallyExportTasks(params: {
|
|
11
|
+
endDate: {
|
|
12
|
+
$lt: Date;
|
|
13
|
+
};
|
|
14
|
+
limit?: number;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
count: number;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
|
|
20
|
+
* PotentialActionStatusに変更する
|
|
21
|
+
* 2025-03-10~
|
|
22
|
+
*/
|
|
23
|
+
reExportAction(params: {
|
|
24
|
+
startDate: {
|
|
25
|
+
$lt: Date;
|
|
26
|
+
};
|
|
27
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
28
|
+
/**
|
|
29
|
+
* add(2025-03-13~)
|
|
30
|
+
*/
|
|
31
|
+
countPotentiallyExpired(params: {
|
|
32
|
+
expires: {
|
|
33
|
+
$lt: Date;
|
|
34
|
+
};
|
|
35
|
+
limit?: number;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
count: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* add(2025-03-03~)
|
|
41
|
+
*/
|
|
42
|
+
makeOneExpiredIfExists(params: {
|
|
43
|
+
expires: {
|
|
44
|
+
$lt: Date;
|
|
45
|
+
};
|
|
46
|
+
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | undefined>;
|
|
47
|
+
findByIdAndDelete(params: {
|
|
48
|
+
id: string;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
unsetUnnecessaryFields(params: {
|
|
51
|
+
filter: any;
|
|
52
|
+
$unset: any;
|
|
53
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
54
|
+
getCursor(conditions: any, projection: any, sort?: factory.sortType): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
55
|
+
object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
|
|
56
|
+
error?: any;
|
|
57
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
58
|
+
seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
|
|
59
|
+
typeOf: factory.transactionType.PlaceOrder;
|
|
60
|
+
expires: Date;
|
|
61
|
+
result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
|
|
62
|
+
startDate: Date;
|
|
63
|
+
endDate?: Date | undefined;
|
|
64
|
+
instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
|
|
65
|
+
agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
|
|
66
|
+
status: factory.transactionStatusType;
|
|
67
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
68
|
+
potentialActions?: undefined;
|
|
69
|
+
} & {
|
|
70
|
+
_id: import("mongoose").Types.ObjectId;
|
|
71
|
+
} & {
|
|
72
|
+
__v: number;
|
|
73
|
+
}) | ({
|
|
74
|
+
object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
|
|
75
|
+
error?: any;
|
|
76
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
77
|
+
seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
|
|
78
|
+
typeOf: factory.transactionType.ReturnOrder;
|
|
79
|
+
expires: Date;
|
|
80
|
+
result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
|
|
81
|
+
startDate: Date;
|
|
82
|
+
endDate?: Date | undefined;
|
|
83
|
+
agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
|
|
84
|
+
recipient?: undefined;
|
|
85
|
+
status: factory.transactionStatusType;
|
|
86
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
87
|
+
potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
|
|
88
|
+
} & {
|
|
89
|
+
_id: import("mongoose").Types.ObjectId;
|
|
90
|
+
} & {
|
|
91
|
+
__v: number;
|
|
92
|
+
})), import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
93
|
+
object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
|
|
94
|
+
error?: any;
|
|
95
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
96
|
+
seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
|
|
97
|
+
typeOf: factory.transactionType.PlaceOrder;
|
|
98
|
+
expires: Date;
|
|
99
|
+
result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
|
|
100
|
+
startDate: Date;
|
|
101
|
+
endDate?: Date | undefined;
|
|
102
|
+
instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
|
|
103
|
+
agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
|
|
104
|
+
status: factory.transactionStatusType;
|
|
105
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
106
|
+
potentialActions?: undefined;
|
|
107
|
+
} & {
|
|
108
|
+
_id: import("mongoose").Types.ObjectId;
|
|
109
|
+
} & {
|
|
110
|
+
__v: number;
|
|
111
|
+
}) | ({
|
|
112
|
+
object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
|
|
113
|
+
error?: any;
|
|
114
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
115
|
+
seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
|
|
116
|
+
typeOf: factory.transactionType.ReturnOrder;
|
|
117
|
+
expires: Date;
|
|
118
|
+
result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
|
|
119
|
+
startDate: Date;
|
|
120
|
+
endDate?: Date | undefined;
|
|
121
|
+
agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
|
|
122
|
+
recipient?: undefined;
|
|
123
|
+
status: factory.transactionStatusType;
|
|
124
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
125
|
+
potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
|
|
126
|
+
} & {
|
|
127
|
+
_id: import("mongoose").Types.ObjectId;
|
|
128
|
+
} & {
|
|
129
|
+
__v: number;
|
|
130
|
+
}))) | null>;
|
|
131
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminTransactionRepo = void 0;
|
|
4
|
+
const transaction_1 = require("../eventEmitter/transaction");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
7
|
+
const transaction_2 = require("./mongoose/schemas/transaction");
|
|
8
|
+
/**
|
|
9
|
+
* 取引管理リポジトリ
|
|
10
|
+
*/
|
|
11
|
+
class AdminTransactionRepo {
|
|
12
|
+
transactionModel;
|
|
13
|
+
constructor(connection) {
|
|
14
|
+
this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
|
|
15
|
+
}
|
|
16
|
+
async countPotentiallyExportTasks(params) {
|
|
17
|
+
const { endDate, limit } = params;
|
|
18
|
+
const endDateLt = endDate?.$lt;
|
|
19
|
+
if (!(endDateLt instanceof Date)) {
|
|
20
|
+
throw new factory_1.factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
21
|
+
}
|
|
22
|
+
const query = this.transactionModel.countDocuments({
|
|
23
|
+
status: {
|
|
24
|
+
$in: [
|
|
25
|
+
factory_1.factory.transactionStatusType.Canceled,
|
|
26
|
+
factory_1.factory.transactionStatusType.Confirmed,
|
|
27
|
+
factory_1.factory.transactionStatusType.Expired
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
'tasksExportAction.actionStatus': {
|
|
31
|
+
$exists: true,
|
|
32
|
+
$eq: factory_1.factory.actionStatusType.PotentialActionStatus
|
|
33
|
+
},
|
|
34
|
+
endDate: { $exists: true, $lt: endDateLt }
|
|
35
|
+
});
|
|
36
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
37
|
+
query.limit(limit);
|
|
38
|
+
}
|
|
39
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
40
|
+
.exec();
|
|
41
|
+
return { count };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
|
|
45
|
+
* PotentialActionStatusに変更する
|
|
46
|
+
* 2025-03-10~
|
|
47
|
+
*/
|
|
48
|
+
async reExportAction(params) {
|
|
49
|
+
const { startDate } = params;
|
|
50
|
+
if (!(startDate.$lt instanceof Date)) {
|
|
51
|
+
throw new factory_1.factory.errors.Argument('startDate.$lt', 'must be Date');
|
|
52
|
+
}
|
|
53
|
+
return this.transactionModel.updateMany({
|
|
54
|
+
'tasksExportAction.actionStatus': {
|
|
55
|
+
$exists: true,
|
|
56
|
+
$eq: factory_1.factory.actionStatusType.ActiveActionStatus
|
|
57
|
+
},
|
|
58
|
+
'tasksExportAction.startDate': {
|
|
59
|
+
$exists: true,
|
|
60
|
+
$lt: startDate.$lt
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
$set: {
|
|
64
|
+
tasksExportAction: {
|
|
65
|
+
actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.exec();
|
|
70
|
+
}
|
|
71
|
+
// /**
|
|
72
|
+
// * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
|
|
73
|
+
// */
|
|
74
|
+
// public async exportTasksMany(params: {
|
|
75
|
+
// now: Date;
|
|
76
|
+
// delayInSeconds: number;
|
|
77
|
+
// status: {
|
|
78
|
+
// $in: factory.transactionStatusType[];
|
|
79
|
+
// };
|
|
80
|
+
// limit: number;
|
|
81
|
+
// }) {
|
|
82
|
+
// const delayedTransactions = await this.transactionModel.find({
|
|
83
|
+
// status: { $in: params.status.$in },
|
|
84
|
+
// 'tasksExportAction.actionStatus': {
|
|
85
|
+
// $exists: true,
|
|
86
|
+
// $eq: factory.actionStatusType.PotentialActionStatus
|
|
87
|
+
// },
|
|
88
|
+
// endDate: {
|
|
89
|
+
// $exists: true,
|
|
90
|
+
// $lt: moment(params.now)
|
|
91
|
+
// .add(-params.delayInSeconds, 'seconds')
|
|
92
|
+
// .toDate()
|
|
93
|
+
// }
|
|
94
|
+
// })
|
|
95
|
+
// .select({
|
|
96
|
+
// _id: 0,
|
|
97
|
+
// id: { $toString: '$_id' },
|
|
98
|
+
// typeOf: 1,
|
|
99
|
+
// status: 1
|
|
100
|
+
// })
|
|
101
|
+
// .limit(params.limit)
|
|
102
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
103
|
+
// .lean<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'status' | 'typeOf'>[]>()
|
|
104
|
+
// .exec();
|
|
105
|
+
// if (delayedTransactions.length > 0) {
|
|
106
|
+
// delayedTransactions.forEach((delayedTransaction) => {
|
|
107
|
+
// transactionEventEmitter.emitTransactionStatusChanged({
|
|
108
|
+
// id: delayedTransaction.id,
|
|
109
|
+
// typeOf: delayedTransaction.typeOf,
|
|
110
|
+
// status: delayedTransaction.status
|
|
111
|
+
// });
|
|
112
|
+
// });
|
|
113
|
+
// }
|
|
114
|
+
// return delayedTransactions;
|
|
115
|
+
// }
|
|
116
|
+
/**
|
|
117
|
+
* add(2025-03-13~)
|
|
118
|
+
*/
|
|
119
|
+
async countPotentiallyExpired(params) {
|
|
120
|
+
const { expires, limit } = params;
|
|
121
|
+
const query = this.transactionModel.countDocuments({
|
|
122
|
+
status: { $eq: factory_1.factory.transactionStatusType.InProgress },
|
|
123
|
+
expires: { $lt: expires.$lt }
|
|
124
|
+
});
|
|
125
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
126
|
+
query.limit(limit);
|
|
127
|
+
}
|
|
128
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
129
|
+
.exec();
|
|
130
|
+
return { count };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* add(2025-03-03~)
|
|
134
|
+
*/
|
|
135
|
+
async makeOneExpiredIfExists(params) {
|
|
136
|
+
const endDate = new Date();
|
|
137
|
+
const sort = {
|
|
138
|
+
expires: factory_1.factory.sortType.Ascending
|
|
139
|
+
};
|
|
140
|
+
const doc = await this.transactionModel.findOneAndUpdate({
|
|
141
|
+
status: { $eq: factory_1.factory.transactionStatusType.InProgress },
|
|
142
|
+
expires: { $lt: params.expires.$lt }
|
|
143
|
+
}, {
|
|
144
|
+
status: factory_1.factory.transactionStatusType.Expired,
|
|
145
|
+
endDate
|
|
146
|
+
}, {
|
|
147
|
+
new: true,
|
|
148
|
+
projection: {
|
|
149
|
+
_id: 0,
|
|
150
|
+
id: { $toString: '$_id' },
|
|
151
|
+
typeOf: 1
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
.sort(sort)
|
|
155
|
+
.lean()
|
|
156
|
+
.exec();
|
|
157
|
+
if (doc === null) {
|
|
158
|
+
// no op
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
163
|
+
id: doc.id,
|
|
164
|
+
typeOf: doc.typeOf,
|
|
165
|
+
status: factory_1.factory.transactionStatusType.Expired
|
|
166
|
+
});
|
|
167
|
+
return doc;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// /**
|
|
171
|
+
// * 取引を期限切れにする
|
|
172
|
+
// */
|
|
173
|
+
// public async makeExpired(params: {
|
|
174
|
+
// expires: { $lt: Date };
|
|
175
|
+
// limit: number; // add limit(2025-02-27~)
|
|
176
|
+
// }): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'>[]> {
|
|
177
|
+
// if (typeof params.limit !== 'number' || params.limit === 0) {
|
|
178
|
+
// throw new factory.errors.ArgumentNull('limit');
|
|
179
|
+
// }
|
|
180
|
+
// const sort: { [key in keyof factory.transaction.ITransaction<factory.transactionType>]?: factory.sortType } = {
|
|
181
|
+
// expires: factory.sortType.Ascending
|
|
182
|
+
// };
|
|
183
|
+
// // IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
184
|
+
// const expiringTransactions =
|
|
185
|
+
// await this.transactionModel.find({
|
|
186
|
+
// status: { $eq: factory.transactionStatusType.InProgress },
|
|
187
|
+
// expires: { $lt: params.expires.$lt }
|
|
188
|
+
// })
|
|
189
|
+
// .select({
|
|
190
|
+
// _id: 0,
|
|
191
|
+
// id: { $toString: '$_id' },
|
|
192
|
+
// typeOf: 1
|
|
193
|
+
// })
|
|
194
|
+
// .limit(params.limit)
|
|
195
|
+
// .sort(sort) // sort(2025-03-03~)
|
|
196
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
197
|
+
// .lean<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'>[]>()
|
|
198
|
+
// .exec();
|
|
199
|
+
// if (expiringTransactions.length > 0) {
|
|
200
|
+
// // ステータスと期限を見て更新
|
|
201
|
+
// await this.transactionModel.updateMany(
|
|
202
|
+
// {
|
|
203
|
+
// _id: { $in: expiringTransactions.map((t) => t.id) },
|
|
204
|
+
// status: { $eq: factory.transactionStatusType.InProgress },
|
|
205
|
+
// expires: { $lt: params.expires.$lt }
|
|
206
|
+
// },
|
|
207
|
+
// {
|
|
208
|
+
// status: factory.transactionStatusType.Expired,
|
|
209
|
+
// endDate: new Date()
|
|
210
|
+
// }
|
|
211
|
+
// )
|
|
212
|
+
// .exec();
|
|
213
|
+
// expiringTransactions.forEach((expiringTransaction) => {
|
|
214
|
+
// transactionEventEmitter.emitTransactionStatusChanged({
|
|
215
|
+
// id: expiringTransaction.id,
|
|
216
|
+
// typeOf: expiringTransaction.typeOf,
|
|
217
|
+
// status: factory.transactionStatusType.Expired
|
|
218
|
+
// });
|
|
219
|
+
// });
|
|
220
|
+
// }
|
|
221
|
+
// return expiringTransactions;
|
|
222
|
+
// }
|
|
223
|
+
async findByIdAndDelete(params) {
|
|
224
|
+
await this.transactionModel.findByIdAndDelete(params.id)
|
|
225
|
+
.exec();
|
|
226
|
+
}
|
|
227
|
+
async unsetUnnecessaryFields(params) {
|
|
228
|
+
return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
229
|
+
.exec();
|
|
230
|
+
}
|
|
231
|
+
getCursor(conditions, projection, sort) {
|
|
232
|
+
return this.transactionModel.find(conditions, projection)
|
|
233
|
+
.sort({ startDate: (sort === factory_1.factory.sortType.Ascending) ? sort : factory_1.factory.sortType.Descending })
|
|
234
|
+
.cursor();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.AdminTransactionRepo = AdminTransactionRepo;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
reservationCount: number;
|
|
13
|
+
avgGraceTime: number;
|
|
14
|
+
maxGraceTime: number;
|
|
15
|
+
minGraceTime: number;
|
|
16
|
+
}
|
|
17
|
+
interface IStatus {
|
|
18
|
+
status: factory.transactionStatusType;
|
|
19
|
+
aggregation: IAggregationByStatus;
|
|
20
|
+
}
|
|
21
|
+
export interface IAggregateReserve {
|
|
22
|
+
statuses: IStatus[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 資産取引集計リポジトリ
|
|
26
|
+
*/
|
|
27
|
+
export declare class AggregateAssetTransactionRepo {
|
|
28
|
+
private readonly transactionModel;
|
|
29
|
+
constructor(connection: Connection);
|
|
30
|
+
aggregateAssetTransaction(params: {
|
|
31
|
+
project?: {
|
|
32
|
+
id?: {
|
|
33
|
+
$eq?: string;
|
|
34
|
+
$ne?: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
startFrom: Date;
|
|
38
|
+
startThrough: Date;
|
|
39
|
+
typeOf: factory.assetTransactionType;
|
|
40
|
+
}): Promise<IAggregateReserve>;
|
|
41
|
+
private agggregateByStatus;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateAssetTransactionRepo = void 0;
|
|
4
|
+
const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
|
+
/**
|
|
7
|
+
* 資産取引集計リポジトリ
|
|
8
|
+
*/
|
|
9
|
+
class AggregateAssetTransactionRepo {
|
|
10
|
+
transactionModel;
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
this.transactionModel = connection.model(assetTransaction_1.modelName, (0, assetTransaction_1.createSchema)());
|
|
13
|
+
}
|
|
14
|
+
async aggregateAssetTransaction(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.project?.id?.$eq === 'string')
|
|
31
|
+
? { 'project.id': { $eq: params.project.id.$eq } }
|
|
32
|
+
: undefined
|
|
33
|
+
};
|
|
34
|
+
return this.agggregateByStatus({ matchConditions, status: transactionStatus });
|
|
35
|
+
}));
|
|
36
|
+
return { statuses };
|
|
37
|
+
}
|
|
38
|
+
async agggregateByStatus(params) {
|
|
39
|
+
const matchConditions = params.matchConditions;
|
|
40
|
+
const transactionStatus = params.status;
|
|
41
|
+
const aggregations = await this.transactionModel.aggregate([
|
|
42
|
+
{
|
|
43
|
+
$match: matchConditions
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
$project: {
|
|
47
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
48
|
+
graceTime: {
|
|
49
|
+
$cond: {
|
|
50
|
+
if: { $eq: ['$typeOf', factory_1.factory.assetTransactionType.Reserve] },
|
|
51
|
+
then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
|
|
52
|
+
else: 0
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
status: '$status',
|
|
56
|
+
startDate: '$startDate',
|
|
57
|
+
endDate: '$endDate',
|
|
58
|
+
typeOf: '$typeOf',
|
|
59
|
+
reservationCount: {
|
|
60
|
+
$cond: {
|
|
61
|
+
if: { $isArray: '$object.subReservation' },
|
|
62
|
+
then: { $size: '$object.subReservation' },
|
|
63
|
+
else: 0
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
$group: {
|
|
70
|
+
_id: '$typeOf',
|
|
71
|
+
transactionCount: { $sum: 1 },
|
|
72
|
+
maxDuration: { $max: '$duration' },
|
|
73
|
+
minDuration: { $min: '$duration' },
|
|
74
|
+
avgDuration: { $avg: '$duration' },
|
|
75
|
+
reservationCount: { $sum: '$reservationCount' },
|
|
76
|
+
maxGraceTime: { $max: '$graceTime' },
|
|
77
|
+
minGraceTime: { $min: '$graceTime' },
|
|
78
|
+
avgGraceTime: { $avg: '$graceTime' }
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
$project: {
|
|
83
|
+
_id: 0,
|
|
84
|
+
transactionCount: '$transactionCount',
|
|
85
|
+
avgDuration: '$avgDuration',
|
|
86
|
+
maxDuration: '$maxDuration',
|
|
87
|
+
minDuration: '$minDuration',
|
|
88
|
+
reservationCount: '$reservationCount',
|
|
89
|
+
avgGraceTime: '$avgGraceTime',
|
|
90
|
+
maxGraceTime: '$maxGraceTime',
|
|
91
|
+
minGraceTime: '$minGraceTime'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
])
|
|
95
|
+
.exec();
|
|
96
|
+
const percents = [50, 95, 99];
|
|
97
|
+
if (aggregations.length === 0) {
|
|
98
|
+
return {
|
|
99
|
+
status: transactionStatus,
|
|
100
|
+
aggregation: {
|
|
101
|
+
transactionCount: 0,
|
|
102
|
+
avgDuration: 0,
|
|
103
|
+
maxDuration: 0,
|
|
104
|
+
minDuration: 0,
|
|
105
|
+
percentilesDuration: percents.map((percent) => {
|
|
106
|
+
return {
|
|
107
|
+
name: String(percent),
|
|
108
|
+
value: 0
|
|
109
|
+
};
|
|
110
|
+
}),
|
|
111
|
+
reservationCount: 0,
|
|
112
|
+
avgGraceTime: 0,
|
|
113
|
+
maxGraceTime: 0,
|
|
114
|
+
minGraceTime: 0
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
119
|
+
return {
|
|
120
|
+
percentile,
|
|
121
|
+
rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
const aggregations2 = await this.transactionModel.aggregate([
|
|
125
|
+
{
|
|
126
|
+
$match: matchConditions
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
$project: {
|
|
130
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
131
|
+
status: '$status',
|
|
132
|
+
startDate: '$startDate',
|
|
133
|
+
endDate: '$endDate',
|
|
134
|
+
typeOf: '$typeOf'
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{ $sort: { duration: 1 } },
|
|
138
|
+
{
|
|
139
|
+
$group: {
|
|
140
|
+
_id: '$typeOf',
|
|
141
|
+
durations: { $push: '$duration' }
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
$project: {
|
|
146
|
+
_id: 0,
|
|
147
|
+
percentilesDuration: ranks4percentile.map((rank) => {
|
|
148
|
+
return {
|
|
149
|
+
name: String(rank.percentile),
|
|
150
|
+
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
151
|
+
};
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
])
|
|
156
|
+
.exec();
|
|
157
|
+
return {
|
|
158
|
+
status: transactionStatus,
|
|
159
|
+
aggregation: {
|
|
160
|
+
...aggregations[0],
|
|
161
|
+
...aggregations2[0]
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.AggregateAssetTransactionRepo = AggregateAssetTransactionRepo;
|