@chevre/domain 20.2.0-alpha.17 → 20.2.0-alpha.19
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/example/src/chevre/aggregation/aggregateSystem.ts +72 -0
- package/lib/chevre/repo/action.d.ts +48 -0
- package/lib/chevre/repo/action.js +165 -0
- package/lib/chevre/repo/aggregation.d.ts +20 -0
- package/lib/chevre/repo/aggregation.js +51 -1
- package/lib/chevre/repo/order.d.ts +1 -1
- package/lib/chevre/repo/order.js +14 -1
- package/lib/chevre/repo/transaction.d.ts +11 -1
- package/lib/chevre/repo/transaction.js +108 -121
- package/lib/chevre/service/aggregation/system.d.ts +66 -0
- package/lib/chevre/service/aggregation/system.js +220 -0
- package/lib/chevre/service/aggregation.d.ts +2 -0
- package/lib/chevre/service/aggregation.js +3 -1
- package/lib/chevre/settings.js +4 -1
- package/package.json +1 -1
- package/example/src/chevre/aggregation/aggregateOrdersGlobally.ts +0 -113
- package/example/src/chevre/aggregation/aggregateReservationsGlobally.ts +0 -84
- package/example/src/chevre/aggregation/aggregateTransactionsGlobally.ts +0 -104
|
@@ -600,142 +600,129 @@ class MongoRepository {
|
|
|
600
600
|
.exec();
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
|
-
// tslint:disable-next-line:max-func-body-length
|
|
604
603
|
aggregatePlaceOrder(params) {
|
|
605
604
|
return __awaiter(this, void 0, void 0, function* () {
|
|
606
605
|
const statuses = yield Promise.all([
|
|
607
606
|
factory.transactionStatusType.Canceled,
|
|
608
607
|
factory.transactionStatusType.Expired,
|
|
609
608
|
factory.transactionStatusType.Confirmed
|
|
610
|
-
// tslint:disable-next-line:max-func-body-length
|
|
611
609
|
].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
612
|
-
var _a, _b
|
|
613
|
-
const matchConditions = {
|
|
614
|
-
'project.id': Object.assign({}, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
615
|
-
? { $ne: (_d = (_c = params.project) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$ne }
|
|
616
|
-
: undefined),
|
|
617
|
-
startDate: {
|
|
610
|
+
var _a, _b;
|
|
611
|
+
const matchConditions = Object.assign({ startDate: {
|
|
618
612
|
$gte: params.startFrom,
|
|
619
613
|
$lte: params.startThrough
|
|
620
|
-
},
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
614
|
+
}, typeOf: { $eq: params.typeOf }, status: { $eq: transactionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
615
|
+
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
616
|
+
: undefined);
|
|
617
|
+
return this.agggregateByStatus({ matchConditions, status: transactionStatus });
|
|
618
|
+
})));
|
|
619
|
+
return { statuses };
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
// tslint:disable-next-line:max-func-body-length
|
|
623
|
+
agggregateByStatus(params) {
|
|
624
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
625
|
+
const matchConditions = params.matchConditions;
|
|
626
|
+
const transactionStatus = params.status;
|
|
627
|
+
const aggregations = yield this.transactionModel.aggregate([
|
|
628
|
+
{
|
|
629
|
+
$match: matchConditions
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
$project: {
|
|
633
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
634
|
+
status: '$status',
|
|
635
|
+
startDate: '$startDate',
|
|
636
|
+
endDate: '$endDate',
|
|
637
|
+
typeOf: '$typeOf'
|
|
624
638
|
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
{
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
$
|
|
632
|
-
|
|
633
|
-
$subtract: ['$endDate', '$startDate']
|
|
634
|
-
},
|
|
635
|
-
status: '$status',
|
|
636
|
-
startDate: '$startDate',
|
|
637
|
-
endDate: '$endDate',
|
|
638
|
-
typeOf: '$typeOf'
|
|
639
|
-
}
|
|
640
|
-
},
|
|
641
|
-
{
|
|
642
|
-
$group: {
|
|
643
|
-
_id: '$typeOf',
|
|
644
|
-
transactionCount: { $sum: 1 },
|
|
645
|
-
maxDuration: {
|
|
646
|
-
$max: '$duration'
|
|
647
|
-
},
|
|
648
|
-
minDuration: {
|
|
649
|
-
$min: '$duration'
|
|
650
|
-
},
|
|
651
|
-
avgDuration: {
|
|
652
|
-
$avg: '$duration'
|
|
653
|
-
},
|
|
654
|
-
stdDevDuration: { $stdDevPop: '$duration' }
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
{
|
|
658
|
-
$project: {
|
|
659
|
-
_id: 0,
|
|
660
|
-
transactionCount: '$transactionCount',
|
|
661
|
-
avgDuration: '$avgDuration',
|
|
662
|
-
maxDuration: '$maxDuration',
|
|
663
|
-
minDuration: '$minDuration',
|
|
664
|
-
stdDevDuration: '$stdDevDuration'
|
|
665
|
-
}
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
$group: {
|
|
642
|
+
_id: '$typeOf',
|
|
643
|
+
transactionCount: { $sum: 1 },
|
|
644
|
+
maxDuration: { $max: '$duration' },
|
|
645
|
+
minDuration: { $min: '$duration' },
|
|
646
|
+
avgDuration: { $avg: '$duration' }
|
|
666
647
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
transactionCount: 0,
|
|
676
|
-
avgDuration: 0,
|
|
677
|
-
maxDuration: 0,
|
|
678
|
-
minDuration: 0,
|
|
679
|
-
percentilesDuration: percents.map((percent) => {
|
|
680
|
-
return {
|
|
681
|
-
name: String(percent),
|
|
682
|
-
value: 0
|
|
683
|
-
};
|
|
684
|
-
})
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
const ranks4percentile = percents.map((percentile) => {
|
|
689
|
-
return {
|
|
690
|
-
percentile,
|
|
691
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
692
|
-
rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
|
|
693
|
-
};
|
|
694
|
-
});
|
|
695
|
-
const aggregations2 = yield this.transactionModel.aggregate([
|
|
696
|
-
{
|
|
697
|
-
$match: matchConditions
|
|
698
|
-
},
|
|
699
|
-
{
|
|
700
|
-
$project: {
|
|
701
|
-
duration: {
|
|
702
|
-
$subtract: ['$endDate', '$startDate']
|
|
703
|
-
},
|
|
704
|
-
status: '$status',
|
|
705
|
-
startDate: '$startDate',
|
|
706
|
-
endDate: '$endDate',
|
|
707
|
-
typeOf: '$typeOf'
|
|
708
|
-
}
|
|
709
|
-
},
|
|
710
|
-
{ $sort: { duration: 1 } },
|
|
711
|
-
{
|
|
712
|
-
$group: {
|
|
713
|
-
_id: '$typeOf',
|
|
714
|
-
durations: { $push: '$duration' }
|
|
715
|
-
}
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
$project: {
|
|
719
|
-
_id: 0,
|
|
720
|
-
avgSmallDuration: '$avgSmallDuration',
|
|
721
|
-
avgMediumDuration: '$avgMediumDuration',
|
|
722
|
-
avgLargeDuration: '$avgLargeDuration',
|
|
723
|
-
percentilesDuration: ranks4percentile.map((rank) => {
|
|
724
|
-
return {
|
|
725
|
-
name: String(rank.percentile),
|
|
726
|
-
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
727
|
-
};
|
|
728
|
-
})
|
|
729
|
-
}
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
$project: {
|
|
651
|
+
_id: 0,
|
|
652
|
+
transactionCount: '$transactionCount',
|
|
653
|
+
avgDuration: '$avgDuration',
|
|
654
|
+
maxDuration: '$maxDuration',
|
|
655
|
+
minDuration: '$minDuration'
|
|
730
656
|
}
|
|
731
|
-
|
|
732
|
-
|
|
657
|
+
}
|
|
658
|
+
])
|
|
659
|
+
.exec();
|
|
660
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
661
|
+
const percents = [50, 95, 99];
|
|
662
|
+
if (aggregations.length === 0) {
|
|
733
663
|
return {
|
|
734
664
|
status: transactionStatus,
|
|
735
|
-
aggregation:
|
|
665
|
+
aggregation: {
|
|
666
|
+
transactionCount: 0,
|
|
667
|
+
avgDuration: 0,
|
|
668
|
+
maxDuration: 0,
|
|
669
|
+
minDuration: 0,
|
|
670
|
+
percentilesDuration: percents.map((percent) => {
|
|
671
|
+
return {
|
|
672
|
+
name: String(percent),
|
|
673
|
+
value: 0
|
|
674
|
+
};
|
|
675
|
+
})
|
|
676
|
+
}
|
|
736
677
|
};
|
|
737
|
-
}
|
|
738
|
-
|
|
678
|
+
}
|
|
679
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
680
|
+
return {
|
|
681
|
+
percentile,
|
|
682
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
683
|
+
rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
const aggregations2 = yield this.transactionModel.aggregate([
|
|
687
|
+
{
|
|
688
|
+
$match: matchConditions
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
$project: {
|
|
692
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
693
|
+
status: '$status',
|
|
694
|
+
startDate: '$startDate',
|
|
695
|
+
endDate: '$endDate',
|
|
696
|
+
typeOf: '$typeOf'
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
{ $sort: { duration: 1 } },
|
|
700
|
+
{
|
|
701
|
+
$group: {
|
|
702
|
+
_id: '$typeOf',
|
|
703
|
+
durations: { $push: '$duration' }
|
|
704
|
+
}
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
$project: {
|
|
708
|
+
_id: 0,
|
|
709
|
+
avgSmallDuration: '$avgSmallDuration',
|
|
710
|
+
avgMediumDuration: '$avgMediumDuration',
|
|
711
|
+
avgLargeDuration: '$avgLargeDuration',
|
|
712
|
+
percentilesDuration: ranks4percentile.map((rank) => {
|
|
713
|
+
return {
|
|
714
|
+
name: String(rank.percentile),
|
|
715
|
+
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
716
|
+
};
|
|
717
|
+
})
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
])
|
|
721
|
+
.exec();
|
|
722
|
+
return {
|
|
723
|
+
status: transactionStatus,
|
|
724
|
+
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
725
|
+
};
|
|
739
726
|
});
|
|
740
727
|
}
|
|
741
728
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MongoRepository as ActionRepo } from '../../repo/action';
|
|
2
|
+
import { MongoRepository as AggregationRepo } from '../../repo/aggregation';
|
|
3
|
+
import { MongoRepository as OrderRepo } from '../../repo/order';
|
|
4
|
+
import { MongoRepository as ReservationRepo } from '../../repo/reservation';
|
|
5
|
+
import { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
6
|
+
/**
|
|
7
|
+
* 注文取引集計
|
|
8
|
+
*/
|
|
9
|
+
declare function aggregatePlaceOrder(params: {
|
|
10
|
+
aggregationDays: number;
|
|
11
|
+
excludedProjectId?: string;
|
|
12
|
+
}): (repos: {
|
|
13
|
+
agregation: AggregationRepo;
|
|
14
|
+
transaction: TransactionRepo;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* 興行オファー承認アクション集計
|
|
18
|
+
*/
|
|
19
|
+
declare function aggregateAuthorizeEventServiceOfferAction(params: {
|
|
20
|
+
aggregationDays: number;
|
|
21
|
+
excludedProjectId?: string;
|
|
22
|
+
}): (repos: {
|
|
23
|
+
agregation: AggregationRepo;
|
|
24
|
+
action: ActionRepo;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 決済承認アクション集計
|
|
28
|
+
*/
|
|
29
|
+
declare function aggregateAuthorizePaymentAction(params: {
|
|
30
|
+
aggregationDays: number;
|
|
31
|
+
excludedProjectId?: string;
|
|
32
|
+
}): (repos: {
|
|
33
|
+
agregation: AggregationRepo;
|
|
34
|
+
action: ActionRepo;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 使用アクション集計
|
|
38
|
+
*/
|
|
39
|
+
declare function aggregateUseAction(params: {
|
|
40
|
+
aggregationDays: number;
|
|
41
|
+
excludedProjectId?: string;
|
|
42
|
+
}): (repos: {
|
|
43
|
+
agregation: AggregationRepo;
|
|
44
|
+
action: ActionRepo;
|
|
45
|
+
}) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 注文集計
|
|
48
|
+
*/
|
|
49
|
+
declare function aggregateOrder(params: {
|
|
50
|
+
aggregationDays: number;
|
|
51
|
+
excludedProjectId?: string;
|
|
52
|
+
}): (repos: {
|
|
53
|
+
agregation: AggregationRepo;
|
|
54
|
+
order: OrderRepo;
|
|
55
|
+
}) => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* 予約集計
|
|
58
|
+
*/
|
|
59
|
+
declare function aggregateReservation(params: {
|
|
60
|
+
aggregationDays: number;
|
|
61
|
+
excludedProjectId?: string;
|
|
62
|
+
}): (repos: {
|
|
63
|
+
agregation: AggregationRepo;
|
|
64
|
+
reservation: ReservationRepo;
|
|
65
|
+
}) => Promise<void>;
|
|
66
|
+
export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizePaymentAction, aggregateOrder, aggregatePlaceOrder, aggregateReservation, aggregateUseAction };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.aggregateUseAction = exports.aggregateReservation = exports.aggregatePlaceOrder = exports.aggregateOrder = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const moment = require("moment-timezone");
|
|
15
|
+
const factory = require("../../factory");
|
|
16
|
+
const aggregation_1 = require("../../repo/aggregation");
|
|
17
|
+
const debug = createDebug('chevre-domain:service:aggregation:system');
|
|
18
|
+
/**
|
|
19
|
+
* 注文取引集計
|
|
20
|
+
*/
|
|
21
|
+
function aggregatePlaceOrder(params) {
|
|
22
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
const aggregateDate = new Date();
|
|
25
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
26
|
+
.toISOString();
|
|
27
|
+
let i = -1;
|
|
28
|
+
while (i < params.aggregationDays) {
|
|
29
|
+
i += 1;
|
|
30
|
+
const startFrom = moment()
|
|
31
|
+
// .tz('Asia/Tokyo')
|
|
32
|
+
.add(-i, 'days')
|
|
33
|
+
.startOf('day')
|
|
34
|
+
.toDate();
|
|
35
|
+
const startThrough = moment()
|
|
36
|
+
// .tz('Asia/Tokyo')
|
|
37
|
+
.add(-i, 'days')
|
|
38
|
+
.endOf('day')
|
|
39
|
+
.toDate();
|
|
40
|
+
const aggregateResult = yield repos.transaction.aggregatePlaceOrder({
|
|
41
|
+
project: { id: { $ne: params.excludedProjectId } },
|
|
42
|
+
startFrom,
|
|
43
|
+
startThrough,
|
|
44
|
+
typeOf: factory.transactionType.PlaceOrder
|
|
45
|
+
});
|
|
46
|
+
debug('aggregatePlaceOrder:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
|
|
47
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePlaceOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.aggregatePlaceOrder = aggregatePlaceOrder;
|
|
52
|
+
/**
|
|
53
|
+
* 興行オファー承認アクション集計
|
|
54
|
+
*/
|
|
55
|
+
function aggregateAuthorizeEventServiceOfferAction(params) {
|
|
56
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
const aggregateDate = new Date();
|
|
59
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
60
|
+
.toISOString();
|
|
61
|
+
let i = -1;
|
|
62
|
+
while (i < params.aggregationDays) {
|
|
63
|
+
i += 1;
|
|
64
|
+
const startFrom = moment()
|
|
65
|
+
// .tz('Asia/Tokyo')
|
|
66
|
+
.add(-i, 'days')
|
|
67
|
+
.startOf('day')
|
|
68
|
+
.toDate();
|
|
69
|
+
const startThrough = moment()
|
|
70
|
+
// .tz('Asia/Tokyo')
|
|
71
|
+
.add(-i, 'days')
|
|
72
|
+
.endOf('day')
|
|
73
|
+
.toDate();
|
|
74
|
+
const aggregateResult = yield repos.action.aggregateAuthorizeEventServiceOfferAction({
|
|
75
|
+
project: { id: { $ne: params.excludedProjectId } },
|
|
76
|
+
startFrom,
|
|
77
|
+
startThrough,
|
|
78
|
+
typeOf: factory.actionType.AuthorizeAction
|
|
79
|
+
});
|
|
80
|
+
debug('aggregateAuthorizeEventServiceOfferAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
|
|
81
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateAuthorizeEventServiceOfferAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
exports.aggregateAuthorizeEventServiceOfferAction = aggregateAuthorizeEventServiceOfferAction;
|
|
86
|
+
/**
|
|
87
|
+
* 決済承認アクション集計
|
|
88
|
+
*/
|
|
89
|
+
function aggregateAuthorizePaymentAction(params) {
|
|
90
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
var _a;
|
|
92
|
+
const aggregateDate = new Date();
|
|
93
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
94
|
+
.toISOString();
|
|
95
|
+
let i = -1;
|
|
96
|
+
while (i < params.aggregationDays) {
|
|
97
|
+
i += 1;
|
|
98
|
+
const startFrom = moment()
|
|
99
|
+
// .tz('Asia/Tokyo')
|
|
100
|
+
.add(-i, 'days')
|
|
101
|
+
.startOf('day')
|
|
102
|
+
.toDate();
|
|
103
|
+
const startThrough = moment()
|
|
104
|
+
// .tz('Asia/Tokyo')
|
|
105
|
+
.add(-i, 'days')
|
|
106
|
+
.endOf('day')
|
|
107
|
+
.toDate();
|
|
108
|
+
const aggregateResult = yield repos.action.aggregateAuthorizePaymentAction({
|
|
109
|
+
project: { id: { $ne: params.excludedProjectId } },
|
|
110
|
+
startFrom,
|
|
111
|
+
startThrough,
|
|
112
|
+
typeOf: factory.actionType.AuthorizeAction
|
|
113
|
+
});
|
|
114
|
+
debug('aggregateAuthorizePaymentAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
|
|
115
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateAuthorizePaymentAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
exports.aggregateAuthorizePaymentAction = aggregateAuthorizePaymentAction;
|
|
120
|
+
/**
|
|
121
|
+
* 使用アクション集計
|
|
122
|
+
*/
|
|
123
|
+
function aggregateUseAction(params) {
|
|
124
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
const aggregateDate = new Date();
|
|
127
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
128
|
+
.toISOString();
|
|
129
|
+
let i = -1;
|
|
130
|
+
while (i < params.aggregationDays) {
|
|
131
|
+
i += 1;
|
|
132
|
+
const startFrom = moment()
|
|
133
|
+
// .tz('Asia/Tokyo')
|
|
134
|
+
.add(-i, 'days')
|
|
135
|
+
.startOf('day')
|
|
136
|
+
.toDate();
|
|
137
|
+
const startThrough = moment()
|
|
138
|
+
// .tz('Asia/Tokyo')
|
|
139
|
+
.add(-i, 'days')
|
|
140
|
+
.endOf('day')
|
|
141
|
+
.toDate();
|
|
142
|
+
const aggregateResult = yield repos.action.aggregateUseAction({
|
|
143
|
+
project: { id: { $ne: params.excludedProjectId } },
|
|
144
|
+
startFrom,
|
|
145
|
+
startThrough,
|
|
146
|
+
typeOf: factory.actionType.UseAction
|
|
147
|
+
});
|
|
148
|
+
debug('aggregateUseAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
|
|
149
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateUseAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.aggregateUseAction = aggregateUseAction;
|
|
154
|
+
/**
|
|
155
|
+
* 注文集計
|
|
156
|
+
*/
|
|
157
|
+
function aggregateOrder(params) {
|
|
158
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const aggregateDate = new Date();
|
|
160
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
161
|
+
.toISOString();
|
|
162
|
+
let i = -1;
|
|
163
|
+
while (i < params.aggregationDays) {
|
|
164
|
+
i += 1;
|
|
165
|
+
const orderDateFrom = moment()
|
|
166
|
+
// .tz('Asia/Tokyo')
|
|
167
|
+
.add(-i, 'days')
|
|
168
|
+
.startOf('day')
|
|
169
|
+
.toDate();
|
|
170
|
+
const orderDateThrough = moment()
|
|
171
|
+
// .tz('Asia/Tokyo')
|
|
172
|
+
.add(-i, 'days')
|
|
173
|
+
.endOf('day')
|
|
174
|
+
.toDate();
|
|
175
|
+
const aggregateResult = yield repos.order.aggregateOrder({
|
|
176
|
+
orderDate: {
|
|
177
|
+
$gte: orderDateFrom,
|
|
178
|
+
$lte: orderDateThrough
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
debug('aggregateOrder:result', aggregateResult);
|
|
182
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: orderDateFrom, aggregateDate }, aggregateResult));
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
exports.aggregateOrder = aggregateOrder;
|
|
187
|
+
/**
|
|
188
|
+
* 予約集計
|
|
189
|
+
*/
|
|
190
|
+
function aggregateReservation(params) {
|
|
191
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const aggregateDate = new Date();
|
|
193
|
+
const aggregateDuration = moment.duration(1, 'days')
|
|
194
|
+
.toISOString();
|
|
195
|
+
let i = -1;
|
|
196
|
+
while (i < params.aggregationDays) {
|
|
197
|
+
i += 1;
|
|
198
|
+
const bookingFrom = moment()
|
|
199
|
+
// .tz('Asia/Tokyo')
|
|
200
|
+
.add(-i, 'days')
|
|
201
|
+
.startOf('day')
|
|
202
|
+
.toDate();
|
|
203
|
+
const bookingThrough = moment()
|
|
204
|
+
// .tz('Asia/Tokyo')
|
|
205
|
+
.add(-i, 'days')
|
|
206
|
+
.endOf('day')
|
|
207
|
+
.toDate();
|
|
208
|
+
// i日前の予約検索
|
|
209
|
+
const reservationCount = yield repos.reservation.count({
|
|
210
|
+
typeOf: factory.reservationType.EventReservation,
|
|
211
|
+
reservationStatus: { $eq: factory.reservationStatusType.ReservationConfirmed },
|
|
212
|
+
bookingFrom,
|
|
213
|
+
bookingThrough
|
|
214
|
+
});
|
|
215
|
+
const aggregateResult = { reservationCount };
|
|
216
|
+
yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateReservation, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: bookingFrom, aggregateDate }, aggregateResult));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
exports.aggregateReservation = aggregateReservation;
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as EventAggregation from './aggregation/event';
|
|
5
5
|
import * as ProjectAggregation from './aggregation/project';
|
|
6
|
+
import * as SystemAggregation from './aggregation/system';
|
|
6
7
|
export import event = EventAggregation;
|
|
7
8
|
export import project = ProjectAggregation;
|
|
9
|
+
export import system = SystemAggregation;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.project = exports.event = void 0;
|
|
3
|
+
exports.system = exports.project = exports.event = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 集計サービス
|
|
6
6
|
*/
|
|
7
7
|
const EventAggregation = require("./aggregation/event");
|
|
8
8
|
const ProjectAggregation = require("./aggregation/project");
|
|
9
|
+
const SystemAggregation = require("./aggregation/system");
|
|
9
10
|
exports.event = EventAggregation;
|
|
10
11
|
exports.project = ProjectAggregation;
|
|
12
|
+
exports.system = SystemAggregation;
|
package/lib/chevre/settings.js
CHANGED
|
@@ -43,7 +43,10 @@ exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = 365;
|
|
|
43
43
|
/**
|
|
44
44
|
* 取引保管期間(Canceled)
|
|
45
45
|
*/
|
|
46
|
-
exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS =
|
|
46
|
+
exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = (typeof process.env.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS === 'string')
|
|
47
|
+
? Number(process.env.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS)
|
|
48
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
49
|
+
: 7;
|
|
47
50
|
exports.DEFAULT_SENDER_EMAIL = process.env.DEFAULT_SENDER_EMAIL;
|
|
48
51
|
exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = String(process.env.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD);
|
|
49
52
|
exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
package/package.json
CHANGED