@chevre/domain 20.2.0-alpha.16 → 20.2.0-alpha.18
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/aggregateAuthorizeActionsGlobally.ts +87 -0
- package/example/src/chevre/aggregation/aggregateAuthorizePaymentActionsGlobally.ts +87 -0
- package/example/src/chevre/{aggregateOrdersGlobally.ts → aggregation/aggregateOrdersGlobally.ts} +35 -5
- package/example/src/chevre/{aggregateReservationsGlobally.ts → aggregation/aggregateReservationsGlobally.ts} +2 -2
- package/example/src/chevre/aggregation/aggregateTransactionsGlobally.ts +104 -0
- package/lib/chevre/repo/action.d.ts +38 -0
- package/lib/chevre/repo/action.js +146 -0
- package/lib/chevre/repo/event.d.ts +0 -1
- package/lib/chevre/repo/event.js +36 -105
- package/lib/chevre/repo/mongoose/model/event.js +2 -2
- package/lib/chevre/repo/order.d.ts +6 -1
- package/lib/chevre/repo/order.js +10 -3
- package/lib/chevre/repo/transaction.d.ts +18 -0
- package/lib/chevre/repo/transaction.js +136 -0
- package/lib/chevre/service/event.d.ts +0 -4
- package/lib/chevre/service/event.js +1 -2
- package/lib/chevre/settings.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment-timezone';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: <string>process.env.PROJECT_ID };
|
|
8
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
|
|
10
|
+
|
|
11
|
+
interface IAggregation {
|
|
12
|
+
typeOf: 'AggregateAuthorizeEventServiceOfferAction';
|
|
13
|
+
project: { id: string; typeOf: chevre.factory.organizationType.Project };
|
|
14
|
+
aggregateDate: Date;
|
|
15
|
+
aggregateDuration: string;
|
|
16
|
+
aggregateStart: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
21
|
+
|
|
22
|
+
const now: Date = new Date();
|
|
23
|
+
|
|
24
|
+
const aggregationRepo = new chevre.repository.Aggregation(mongoose.connection);
|
|
25
|
+
const actionRepo = new chevre.repository.Action(mongoose.connection);
|
|
26
|
+
|
|
27
|
+
let i = 0;
|
|
28
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
29
|
+
while (i < AGGREGATE_DAYS) {
|
|
30
|
+
i += 1;
|
|
31
|
+
|
|
32
|
+
const startFrom: Date = moment()
|
|
33
|
+
// .tz('Asia/Tokyo')
|
|
34
|
+
.add(-i, 'days')
|
|
35
|
+
.startOf('day')
|
|
36
|
+
.toDate();
|
|
37
|
+
const startThrough: Date = moment()
|
|
38
|
+
// .tz('Asia/Tokyo')
|
|
39
|
+
.add(-i, 'days')
|
|
40
|
+
.endOf('day')
|
|
41
|
+
.toDate();
|
|
42
|
+
const aggregateResult = await actionRepo.aggregateAuthorizeEventServiceOfferAction({
|
|
43
|
+
project: { id: <any>{ $ne: EXCLUDED_PROJECT_ID } },
|
|
44
|
+
startFrom,
|
|
45
|
+
startThrough,
|
|
46
|
+
typeOf: chevre.factory.actionType.AuthorizeAction
|
|
47
|
+
});
|
|
48
|
+
console.log('aggregateResult', aggregateResult, aggregateResult.statuses[0]?.aggregation.percentilesDuration, startFrom);
|
|
49
|
+
|
|
50
|
+
const aggregation: IAggregation = {
|
|
51
|
+
typeOf: 'AggregateAuthorizeEventServiceOfferAction',
|
|
52
|
+
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
53
|
+
aggregateDuration: moment.duration(1, 'days')
|
|
54
|
+
.toISOString(),
|
|
55
|
+
aggregateStart: startFrom,
|
|
56
|
+
aggregateDate: now,
|
|
57
|
+
...aggregateResult
|
|
58
|
+
};
|
|
59
|
+
const { typeOf, project, aggregateDuration, aggregateStart, ...setFields } = aggregation;
|
|
60
|
+
const doc = await aggregationRepo.aggregationModel.findOneAndUpdate(
|
|
61
|
+
{
|
|
62
|
+
typeOf: { $eq: aggregation.typeOf },
|
|
63
|
+
'project.id': { $eq: aggregation.project.id },
|
|
64
|
+
aggregateStart: { $eq: aggregation.aggregateStart },
|
|
65
|
+
aggregateDuration: { $eq: aggregation.aggregateDuration }
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
$setOnInsert: {
|
|
69
|
+
typeOf: aggregation.typeOf,
|
|
70
|
+
project: aggregation.project,
|
|
71
|
+
aggregateDuration: aggregation.aggregateDuration,
|
|
72
|
+
aggregateStart: aggregation.aggregateStart
|
|
73
|
+
},
|
|
74
|
+
$set: setFields
|
|
75
|
+
},
|
|
76
|
+
{ upsert: true, new: true }
|
|
77
|
+
)
|
|
78
|
+
.exec();
|
|
79
|
+
console.log(doc);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main()
|
|
84
|
+
.then(() => {
|
|
85
|
+
console.log('success!');
|
|
86
|
+
})
|
|
87
|
+
.catch(console.error);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment-timezone';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: <string>process.env.PROJECT_ID };
|
|
8
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
|
|
10
|
+
|
|
11
|
+
interface IAggregation {
|
|
12
|
+
typeOf: 'AggregateAuthorizePaymentAction';
|
|
13
|
+
project: { id: string; typeOf: chevre.factory.organizationType.Project };
|
|
14
|
+
aggregateDate: Date;
|
|
15
|
+
aggregateDuration: string;
|
|
16
|
+
aggregateStart: Date;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
21
|
+
|
|
22
|
+
const now: Date = new Date();
|
|
23
|
+
|
|
24
|
+
const aggregationRepo = new chevre.repository.Aggregation(mongoose.connection);
|
|
25
|
+
const actionRepo = new chevre.repository.Action(mongoose.connection);
|
|
26
|
+
|
|
27
|
+
let i = 0;
|
|
28
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
29
|
+
while (i < AGGREGATE_DAYS) {
|
|
30
|
+
i += 1;
|
|
31
|
+
|
|
32
|
+
const startFrom: Date = moment()
|
|
33
|
+
// .tz('Asia/Tokyo')
|
|
34
|
+
.add(-i, 'days')
|
|
35
|
+
.startOf('day')
|
|
36
|
+
.toDate();
|
|
37
|
+
const startThrough: Date = moment()
|
|
38
|
+
// .tz('Asia/Tokyo')
|
|
39
|
+
.add(-i, 'days')
|
|
40
|
+
.endOf('day')
|
|
41
|
+
.toDate();
|
|
42
|
+
const aggregateResult = await actionRepo.aggregateAuthorizePaymentAction({
|
|
43
|
+
project: { id: <any>{ $ne: EXCLUDED_PROJECT_ID } },
|
|
44
|
+
startFrom,
|
|
45
|
+
startThrough,
|
|
46
|
+
typeOf: chevre.factory.actionType.AuthorizeAction
|
|
47
|
+
});
|
|
48
|
+
console.log('aggregateResult', aggregateResult, aggregateResult.statuses[0]?.aggregation.percentilesDuration, startFrom);
|
|
49
|
+
|
|
50
|
+
const aggregation: IAggregation = {
|
|
51
|
+
typeOf: 'AggregateAuthorizePaymentAction',
|
|
52
|
+
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
53
|
+
aggregateDuration: moment.duration(1, 'days')
|
|
54
|
+
.toISOString(),
|
|
55
|
+
aggregateStart: startFrom,
|
|
56
|
+
aggregateDate: now,
|
|
57
|
+
...aggregateResult
|
|
58
|
+
};
|
|
59
|
+
const { typeOf, project, aggregateDuration, aggregateStart, ...setFields } = aggregation;
|
|
60
|
+
const doc = await aggregationRepo.aggregationModel.findOneAndUpdate(
|
|
61
|
+
{
|
|
62
|
+
typeOf: { $eq: aggregation.typeOf },
|
|
63
|
+
'project.id': { $eq: aggregation.project.id },
|
|
64
|
+
aggregateStart: { $eq: aggregation.aggregateStart },
|
|
65
|
+
aggregateDuration: { $eq: aggregation.aggregateDuration }
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
$setOnInsert: {
|
|
69
|
+
typeOf: aggregation.typeOf,
|
|
70
|
+
project: aggregation.project,
|
|
71
|
+
aggregateDuration: aggregation.aggregateDuration,
|
|
72
|
+
aggregateStart: aggregation.aggregateStart
|
|
73
|
+
},
|
|
74
|
+
$set: setFields
|
|
75
|
+
},
|
|
76
|
+
{ upsert: true, new: true }
|
|
77
|
+
)
|
|
78
|
+
.exec();
|
|
79
|
+
console.log(doc);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main()
|
|
84
|
+
.then(() => {
|
|
85
|
+
console.log('success!');
|
|
86
|
+
})
|
|
87
|
+
.catch(console.error);
|
package/example/src/chevre/{aggregateOrdersGlobally.ts → aggregation/aggregateOrdersGlobally.ts}
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as moment from 'moment-timezone';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
|
|
5
|
-
import { chevre } from '
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
6
|
|
|
7
7
|
// const project = { id: <string>process.env.PROJECT_ID };
|
|
8
8
|
interface IAggregation {
|
|
@@ -13,6 +13,11 @@ interface IAggregation {
|
|
|
13
13
|
aggregateStart: Date;
|
|
14
14
|
orderCount: number;
|
|
15
15
|
acceptedOfferCount: number;
|
|
16
|
+
avgAcceptedOfferCount: number;
|
|
17
|
+
totalPrice: number;
|
|
18
|
+
maxPrice: number;
|
|
19
|
+
minPrice: number;
|
|
20
|
+
avgPrice: number;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
async function main() {
|
|
@@ -25,7 +30,7 @@ async function main() {
|
|
|
25
30
|
|
|
26
31
|
let i = 0;
|
|
27
32
|
// tslint:disable-next-line:no-magic-numbers
|
|
28
|
-
while (i <
|
|
33
|
+
while (i < 365) {
|
|
29
34
|
i += 1;
|
|
30
35
|
|
|
31
36
|
const orderDateFrom: Date = moment()
|
|
@@ -46,6 +51,7 @@ async function main() {
|
|
|
46
51
|
$lte: orderDateThrough
|
|
47
52
|
}
|
|
48
53
|
});
|
|
54
|
+
console.log('aggregateResult', aggregateResult);
|
|
49
55
|
|
|
50
56
|
const aggregation: IAggregation = {
|
|
51
57
|
typeOf: 'AggregateOrder',
|
|
@@ -55,9 +61,24 @@ async function main() {
|
|
|
55
61
|
aggregateStart: orderDateFrom,
|
|
56
62
|
aggregateDate: now,
|
|
57
63
|
orderCount: (aggregateResult.length > 0) ? aggregateResult[0].orderCount : 0,
|
|
58
|
-
acceptedOfferCount: (aggregateResult.length > 0) ? aggregateResult[0].acceptedOfferCount : 0
|
|
64
|
+
acceptedOfferCount: (aggregateResult.length > 0) ? aggregateResult[0].acceptedOfferCount : 0,
|
|
65
|
+
avgAcceptedOfferCount: (aggregateResult.length > 0) ? aggregateResult[0].avgAcceptedOfferCount : 0,
|
|
66
|
+
totalPrice: (aggregateResult.length > 0) ? aggregateResult[0].totalPrice : 0,
|
|
67
|
+
maxPrice: (aggregateResult.length > 0) ? aggregateResult[0].maxPrice : 0,
|
|
68
|
+
minPrice: (aggregateResult.length > 0) ? aggregateResult[0].minPrice : 0,
|
|
69
|
+
avgPrice: (aggregateResult.length > 0) ? aggregateResult[0].avgPrice : 0
|
|
59
70
|
};
|
|
60
|
-
const {
|
|
71
|
+
const {
|
|
72
|
+
avgAcceptedOfferCount,
|
|
73
|
+
totalPrice,
|
|
74
|
+
maxPrice,
|
|
75
|
+
minPrice,
|
|
76
|
+
avgPrice,
|
|
77
|
+
acceptedOfferCount,
|
|
78
|
+
orderCount,
|
|
79
|
+
aggregateDate,
|
|
80
|
+
...setOnInsert
|
|
81
|
+
} = aggregation;
|
|
61
82
|
const doc = await aggregationRepo.aggregationModel.findOneAndUpdate(
|
|
62
83
|
{
|
|
63
84
|
typeOf: { $eq: aggregation.typeOf },
|
|
@@ -67,7 +88,16 @@ async function main() {
|
|
|
67
88
|
},
|
|
68
89
|
{
|
|
69
90
|
$setOnInsert: setOnInsert,
|
|
70
|
-
$set: {
|
|
91
|
+
$set: {
|
|
92
|
+
avgAcceptedOfferCount,
|
|
93
|
+
totalPrice,
|
|
94
|
+
maxPrice,
|
|
95
|
+
minPrice,
|
|
96
|
+
avgPrice,
|
|
97
|
+
acceptedOfferCount,
|
|
98
|
+
orderCount,
|
|
99
|
+
aggregateDate
|
|
100
|
+
}
|
|
71
101
|
},
|
|
72
102
|
{ upsert: true }
|
|
73
103
|
)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as moment from 'moment-timezone';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
|
|
5
|
-
import { chevre } from '
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
6
|
|
|
7
7
|
// const project = { id: <string>process.env.PROJECT_ID };
|
|
8
8
|
interface IAggregation {
|
|
@@ -25,7 +25,7 @@ async function main() {
|
|
|
25
25
|
|
|
26
26
|
let i = 0;
|
|
27
27
|
// tslint:disable-next-line:no-magic-numbers
|
|
28
|
-
while (i <
|
|
28
|
+
while (i < 365) {
|
|
29
29
|
i += 1;
|
|
30
30
|
|
|
31
31
|
const bookingFrom: Date = moment()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment-timezone';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: <string>process.env.PROJECT_ID };
|
|
8
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
|
|
10
|
+
|
|
11
|
+
interface IAggregation {
|
|
12
|
+
typeOf: 'AggregatePlaceOrder';
|
|
13
|
+
project: { id: string; typeOf: chevre.factory.organizationType.Project };
|
|
14
|
+
aggregateDate: Date;
|
|
15
|
+
aggregateDuration: string;
|
|
16
|
+
aggregateStart: Date;
|
|
17
|
+
// transactionCount: number;
|
|
18
|
+
// avgDuration: number;
|
|
19
|
+
// maxDuration: number;
|
|
20
|
+
// minDuration: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
25
|
+
|
|
26
|
+
const now: Date = new Date();
|
|
27
|
+
|
|
28
|
+
const aggregationRepo = new chevre.repository.Aggregation(mongoose.connection);
|
|
29
|
+
const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
|
|
30
|
+
|
|
31
|
+
let i = 0;
|
|
32
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
33
|
+
while (i < AGGREGATE_DAYS) {
|
|
34
|
+
i += 1;
|
|
35
|
+
|
|
36
|
+
const startFrom: Date = moment()
|
|
37
|
+
// .tz('Asia/Tokyo')
|
|
38
|
+
.add(-i, 'days')
|
|
39
|
+
.startOf('day')
|
|
40
|
+
.toDate();
|
|
41
|
+
const startThrough: Date = moment()
|
|
42
|
+
// .tz('Asia/Tokyo')
|
|
43
|
+
.add(-i, 'days')
|
|
44
|
+
.endOf('day')
|
|
45
|
+
.toDate();
|
|
46
|
+
|
|
47
|
+
const aggregateResult = await transactionRepo.aggregatePlaceOrder({
|
|
48
|
+
project: { id: <any>{ $ne: EXCLUDED_PROJECT_ID } },
|
|
49
|
+
startFrom,
|
|
50
|
+
startThrough,
|
|
51
|
+
typeOf: chevre.factory.transactionType.PlaceOrder
|
|
52
|
+
});
|
|
53
|
+
console.log('aggregateResult', aggregateResult, aggregateResult.statuses[0]?.aggregation.percentilesDuration, startFrom);
|
|
54
|
+
|
|
55
|
+
const aggregation: IAggregation = {
|
|
56
|
+
typeOf: 'AggregatePlaceOrder',
|
|
57
|
+
project: { id: '*', typeOf: chevre.factory.organizationType.Project },
|
|
58
|
+
aggregateDuration: moment.duration(1, 'days')
|
|
59
|
+
.toISOString(),
|
|
60
|
+
aggregateStart: startFrom,
|
|
61
|
+
aggregateDate: now,
|
|
62
|
+
...aggregateResult
|
|
63
|
+
};
|
|
64
|
+
const { typeOf, project, aggregateDuration, aggregateStart, ...setFields } = aggregation;
|
|
65
|
+
const doc = await aggregationRepo.aggregationModel.findOneAndUpdate(
|
|
66
|
+
{
|
|
67
|
+
typeOf: { $eq: aggregation.typeOf },
|
|
68
|
+
'project.id': { $eq: aggregation.project.id },
|
|
69
|
+
aggregateStart: { $eq: aggregation.aggregateStart },
|
|
70
|
+
aggregateDuration: { $eq: aggregation.aggregateDuration }
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
$setOnInsert: {
|
|
74
|
+
typeOf: aggregation.typeOf,
|
|
75
|
+
project: aggregation.project,
|
|
76
|
+
aggregateDuration: aggregation.aggregateDuration,
|
|
77
|
+
aggregateStart: aggregation.aggregateStart
|
|
78
|
+
},
|
|
79
|
+
$set: setFields,
|
|
80
|
+
$unset: {
|
|
81
|
+
avgLargeDuration: 1,
|
|
82
|
+
avgMediumDuration: 1,
|
|
83
|
+
avgSmallDuration: 1,
|
|
84
|
+
stdDevDuration: 1,
|
|
85
|
+
transactionCountByStatus: 1,
|
|
86
|
+
transactionCount: 12,
|
|
87
|
+
avgDuration: 1,
|
|
88
|
+
maxDuration: 1,
|
|
89
|
+
minDuration: 1,
|
|
90
|
+
percentilesDuration: 1
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{ upsert: true, new: true }
|
|
94
|
+
)
|
|
95
|
+
.exec();
|
|
96
|
+
console.log(doc);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
main()
|
|
101
|
+
.then(() => {
|
|
102
|
+
console.log('success!');
|
|
103
|
+
})
|
|
104
|
+
.catch(console.error);
|
|
@@ -7,6 +7,23 @@ export interface IUseActionCountByOffer {
|
|
|
7
7
|
_id: string[];
|
|
8
8
|
useActionCount?: number;
|
|
9
9
|
}
|
|
10
|
+
interface IAggregationByStatus {
|
|
11
|
+
actionCount: number;
|
|
12
|
+
avgDuration: number;
|
|
13
|
+
maxDuration: number;
|
|
14
|
+
minDuration: number;
|
|
15
|
+
percentilesDuration: {
|
|
16
|
+
name: string;
|
|
17
|
+
value: number;
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
interface IStatus {
|
|
21
|
+
status: factory.actionStatusType;
|
|
22
|
+
aggregation: IAggregationByStatus;
|
|
23
|
+
}
|
|
24
|
+
interface IAggregateAction {
|
|
25
|
+
statuses: IStatus[];
|
|
26
|
+
}
|
|
10
27
|
export { modelName };
|
|
11
28
|
/**
|
|
12
29
|
* アクションリポジトリ
|
|
@@ -107,4 +124,25 @@ export declare class MongoRepository {
|
|
|
107
124
|
deleteEndDatePassedCertainPeriod(params: {
|
|
108
125
|
$lt: Date;
|
|
109
126
|
}): Promise<void>;
|
|
127
|
+
aggregateAuthorizeEventServiceOfferAction(params: {
|
|
128
|
+
project?: {
|
|
129
|
+
id?: {
|
|
130
|
+
$ne?: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
startFrom: Date;
|
|
134
|
+
startThrough: Date;
|
|
135
|
+
typeOf: factory.actionType;
|
|
136
|
+
}): Promise<IAggregateAction>;
|
|
137
|
+
aggregateAuthorizePaymentAction(params: {
|
|
138
|
+
project?: {
|
|
139
|
+
id?: {
|
|
140
|
+
$ne?: string;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
startFrom: Date;
|
|
144
|
+
startThrough: Date;
|
|
145
|
+
typeOf: factory.actionType;
|
|
146
|
+
}): Promise<IAggregateAction>;
|
|
147
|
+
private agggregateByStatus;
|
|
110
148
|
}
|
|
@@ -677,5 +677,151 @@ class MongoRepository {
|
|
|
677
677
|
.exec();
|
|
678
678
|
});
|
|
679
679
|
}
|
|
680
|
+
aggregateAuthorizeEventServiceOfferAction(params) {
|
|
681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
682
|
+
const statuses = yield Promise.all([
|
|
683
|
+
factory.actionStatusType.CanceledActionStatus,
|
|
684
|
+
factory.actionStatusType.CompletedActionStatus,
|
|
685
|
+
factory.actionStatusType.FailedActionStatus
|
|
686
|
+
].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
687
|
+
var _a, _b;
|
|
688
|
+
const matchConditions = Object.assign({ startDate: {
|
|
689
|
+
$gte: params.startFrom,
|
|
690
|
+
$lte: params.startThrough
|
|
691
|
+
}, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
|
|
692
|
+
$exists: true,
|
|
693
|
+
$eq: factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation
|
|
694
|
+
} }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
695
|
+
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
696
|
+
: undefined);
|
|
697
|
+
return this.agggregateByStatus({ matchConditions, actionStatus });
|
|
698
|
+
})));
|
|
699
|
+
return { statuses };
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
aggregateAuthorizePaymentAction(params) {
|
|
703
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
704
|
+
const statuses = yield Promise.all([
|
|
705
|
+
factory.actionStatusType.CanceledActionStatus,
|
|
706
|
+
factory.actionStatusType.CompletedActionStatus,
|
|
707
|
+
factory.actionStatusType.FailedActionStatus
|
|
708
|
+
].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
709
|
+
var _a, _b;
|
|
710
|
+
const matchConditions = Object.assign({ startDate: {
|
|
711
|
+
$gte: params.startFrom,
|
|
712
|
+
$lte: params.startThrough
|
|
713
|
+
}, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
|
|
714
|
+
$exists: true,
|
|
715
|
+
$eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
|
|
716
|
+
} }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
717
|
+
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
718
|
+
: undefined);
|
|
719
|
+
return this.agggregateByStatus({ matchConditions, actionStatus });
|
|
720
|
+
})));
|
|
721
|
+
return { statuses };
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
// tslint:disable-next-line:max-func-body-length
|
|
725
|
+
agggregateByStatus(params) {
|
|
726
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
727
|
+
const aggregations = yield this.actionModel.aggregate([
|
|
728
|
+
{ $match: params.matchConditions },
|
|
729
|
+
{
|
|
730
|
+
$project: {
|
|
731
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
732
|
+
actionStatus: '$actionStatus',
|
|
733
|
+
startDate: '$startDate',
|
|
734
|
+
endDate: '$endDate',
|
|
735
|
+
typeOf: '$typeOf'
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
$group: {
|
|
740
|
+
_id: '$typeOf',
|
|
741
|
+
actionCount: { $sum: 1 },
|
|
742
|
+
maxDuration: { $max: '$duration' },
|
|
743
|
+
minDuration: { $min: '$duration' },
|
|
744
|
+
avgDuration: { $avg: '$duration' }
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
$project: {
|
|
749
|
+
_id: 0,
|
|
750
|
+
actionCount: '$actionCount',
|
|
751
|
+
avgDuration: '$avgDuration',
|
|
752
|
+
maxDuration: '$maxDuration',
|
|
753
|
+
minDuration: '$minDuration'
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
])
|
|
757
|
+
.exec();
|
|
758
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
759
|
+
const percents = [50, 95, 99];
|
|
760
|
+
if (aggregations.length === 0) {
|
|
761
|
+
return {
|
|
762
|
+
status: params.actionStatus,
|
|
763
|
+
aggregation: {
|
|
764
|
+
actionCount: 0,
|
|
765
|
+
avgDuration: 0,
|
|
766
|
+
maxDuration: 0,
|
|
767
|
+
minDuration: 0,
|
|
768
|
+
percentilesDuration: percents.map((percent) => {
|
|
769
|
+
return {
|
|
770
|
+
name: String(percent),
|
|
771
|
+
value: 0
|
|
772
|
+
};
|
|
773
|
+
})
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
778
|
+
return {
|
|
779
|
+
percentile,
|
|
780
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
781
|
+
rank: Math.floor(aggregations[0].actionCount * percentile / 100)
|
|
782
|
+
};
|
|
783
|
+
});
|
|
784
|
+
const aggregations2 = yield this.actionModel.aggregate([
|
|
785
|
+
{
|
|
786
|
+
$match: params.matchConditions
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
$project: {
|
|
790
|
+
duration: { $subtract: ['$endDate', '$startDate'] },
|
|
791
|
+
actionStatus: '$actionStatus',
|
|
792
|
+
startDate: '$startDate',
|
|
793
|
+
endDate: '$endDate',
|
|
794
|
+
typeOf: '$typeOf'
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
{ $sort: { duration: 1 } },
|
|
798
|
+
{
|
|
799
|
+
$group: {
|
|
800
|
+
_id: '$typeOf',
|
|
801
|
+
durations: { $push: '$duration' }
|
|
802
|
+
}
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
$project: {
|
|
806
|
+
_id: 0,
|
|
807
|
+
avgSmallDuration: '$avgSmallDuration',
|
|
808
|
+
avgMediumDuration: '$avgMediumDuration',
|
|
809
|
+
avgLargeDuration: '$avgLargeDuration',
|
|
810
|
+
percentilesDuration: ranks4percentile.map((rank) => {
|
|
811
|
+
return {
|
|
812
|
+
name: String(rank.percentile),
|
|
813
|
+
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
814
|
+
};
|
|
815
|
+
})
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
])
|
|
819
|
+
.exec();
|
|
820
|
+
return {
|
|
821
|
+
status: params.actionStatus,
|
|
822
|
+
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
823
|
+
};
|
|
824
|
+
});
|
|
825
|
+
}
|
|
680
826
|
}
|
|
681
827
|
exports.MongoRepository = MongoRepository;
|
|
@@ -70,7 +70,6 @@ export declare class MongoRepository {
|
|
|
70
70
|
save4ttts(params: {
|
|
71
71
|
oldEventId: string;
|
|
72
72
|
attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
|
|
73
|
-
useOldEventId: boolean;
|
|
74
73
|
}): Promise<factory.event.IEvent<factory.eventType.ScreeningEvent>>;
|
|
75
74
|
count<T extends factory.eventType>(params: ISearchConditions<T>): Promise<number>;
|
|
76
75
|
/**
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -24,7 +24,6 @@ exports.MongoRepository = void 0;
|
|
|
24
24
|
const uniqid = require("uniqid");
|
|
25
25
|
const factory = require("../factory");
|
|
26
26
|
const event_1 = require("./mongoose/model/event");
|
|
27
|
-
const USE_DEPRECATED_EVENT_SEARCH_CONDITIONS = process.env.USE_DEPRECATED_EVENT_SEARCH_CONDITIONS === '1';
|
|
28
27
|
/**
|
|
29
28
|
* イベントリポジトリ
|
|
30
29
|
*/
|
|
@@ -34,7 +33,7 @@ class MongoRepository {
|
|
|
34
33
|
}
|
|
35
34
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
36
35
|
static CREATE_MONGO_CONDITIONS(conditions) {
|
|
37
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35;
|
|
38
37
|
const andConditions = [{ typeOf: { $eq: conditions.typeOf } }];
|
|
39
38
|
const projectIdEq = (_b = (_a = conditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
40
39
|
if (typeof projectIdEq === 'string') {
|
|
@@ -135,12 +134,12 @@ class MongoRepository {
|
|
|
135
134
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
136
135
|
/* istanbul ignore else */
|
|
137
136
|
if (params.offers !== undefined) {
|
|
138
|
-
const
|
|
139
|
-
if (Array.isArray(
|
|
137
|
+
const itemOfferedIdIn4event = (_k = (_j = params.offers.itemOffered) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$in;
|
|
138
|
+
if (Array.isArray(itemOfferedIdIn4event)) {
|
|
140
139
|
andConditions.push({
|
|
141
140
|
'offers.itemOffered.id': {
|
|
142
141
|
$exists: true,
|
|
143
|
-
$in:
|
|
142
|
+
$in: itemOfferedIdIn4event
|
|
144
143
|
}
|
|
145
144
|
});
|
|
146
145
|
}
|
|
@@ -289,103 +288,35 @@ class MongoRepository {
|
|
|
289
288
|
});
|
|
290
289
|
}
|
|
291
290
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (params.offers.availableFrom instanceof Date) {
|
|
299
|
-
andConditions.push({
|
|
300
|
-
'offers.availabilityEnds': {
|
|
301
|
-
$exists: true,
|
|
302
|
-
$gte: params.offers.availableFrom
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
307
|
-
/* istanbul ignore else */
|
|
308
|
-
if (params.offers.availableThrough instanceof Date) {
|
|
309
|
-
andConditions.push({
|
|
310
|
-
'offers.availabilityStarts': {
|
|
311
|
-
$exists: true,
|
|
312
|
-
$lte: params.offers.availableThrough
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
317
|
-
/* istanbul ignore else */
|
|
318
|
-
if (params.offers.validFrom instanceof Date) {
|
|
319
|
-
andConditions.push({
|
|
320
|
-
'offers.validThrough': {
|
|
321
|
-
$exists: true,
|
|
322
|
-
$gte: params.offers.validFrom
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
327
|
-
/* istanbul ignore else */
|
|
328
|
-
if (params.offers.validThrough instanceof Date) {
|
|
329
|
-
andConditions.push({
|
|
330
|
-
'offers.validFrom': {
|
|
331
|
-
$exists: true,
|
|
332
|
-
$lte: params.offers.validThrough
|
|
333
|
-
}
|
|
334
|
-
});
|
|
291
|
+
const itemOfferedIdIn = (_12 = (_11 = (_10 = params.offers) === null || _10 === void 0 ? void 0 : _10.itemOffered) === null || _11 === void 0 ? void 0 : _11.id) === null || _12 === void 0 ? void 0 : _12.$in;
|
|
292
|
+
if (Array.isArray(itemOfferedIdIn)) {
|
|
293
|
+
andConditions.push({
|
|
294
|
+
'offers.itemOffered.id': {
|
|
295
|
+
$exists: true,
|
|
296
|
+
$in: itemOfferedIdIn
|
|
335
297
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
347
|
-
/* istanbul ignore else */
|
|
348
|
-
if (params.offers.itemOffered !== undefined) {
|
|
349
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
350
|
-
/* istanbul ignore else */
|
|
351
|
-
if (params.offers.itemOffered.serviceOutput !== undefined) {
|
|
352
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
353
|
-
/* istanbul ignore else */
|
|
354
|
-
if (params.offers.itemOffered.serviceOutput.reservedTicket !== undefined) {
|
|
355
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
356
|
-
/* istanbul ignore else */
|
|
357
|
-
if (params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat !== undefined) {
|
|
358
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
359
|
-
/* istanbul ignore else */
|
|
360
|
-
if (Array.isArray(params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs)) {
|
|
361
|
-
andConditions.push({
|
|
362
|
-
'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
|
|
363
|
-
$exists: true,
|
|
364
|
-
$in: params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const itemOfferedTicketedSeatTypeOfIn = (_17 = (_16 = (_15 = (_14 = (_13 = params.offers) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.serviceOutput) === null || _15 === void 0 ? void 0 : _15.reservedTicket) === null || _16 === void 0 ? void 0 : _16.ticketedSeat) === null || _17 === void 0 ? void 0 : _17.typeOfs;
|
|
301
|
+
if (Array.isArray(itemOfferedTicketedSeatTypeOfIn)) {
|
|
302
|
+
andConditions.push({
|
|
303
|
+
'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
|
|
304
|
+
$exists: true,
|
|
305
|
+
$in: itemOfferedTicketedSeatTypeOfIn
|
|
370
306
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
$exists: true,
|
|
380
|
-
$in: params.offers.itemOffered.serviceType.ids
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const itemOfferedServiceTypeIdIn = (_20 = (_19 = (_18 = params.offers) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceType) === null || _20 === void 0 ? void 0 : _20.ids;
|
|
310
|
+
if (Array.isArray(itemOfferedServiceTypeIdIn)) {
|
|
311
|
+
andConditions.push({
|
|
312
|
+
'offers.itemOffered.serviceType.id': {
|
|
313
|
+
$exists: true,
|
|
314
|
+
$in: itemOfferedServiceTypeIdIn
|
|
384
315
|
}
|
|
385
|
-
}
|
|
316
|
+
});
|
|
386
317
|
}
|
|
387
|
-
const sellerMakesOfferElemMatch = (
|
|
388
|
-
if (typeof ((
|
|
318
|
+
const sellerMakesOfferElemMatch = (_23 = (_22 = (_21 = params.offers) === null || _21 === void 0 ? void 0 : _21.seller) === null || _22 === void 0 ? void 0 : _22.makesOffer) === null || _23 === void 0 ? void 0 : _23.$elemMatch;
|
|
319
|
+
if (typeof ((_24 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _24 === void 0 ? void 0 : _24.$eq) === 'string') {
|
|
389
320
|
andConditions.push({
|
|
390
321
|
'offers.seller.makesOffer': {
|
|
391
322
|
$exists: true,
|
|
@@ -422,7 +353,7 @@ class MongoRepository {
|
|
|
422
353
|
]
|
|
423
354
|
});
|
|
424
355
|
}
|
|
425
|
-
const locationIdEq = (
|
|
356
|
+
const locationIdEq = (_26 = (_25 = params.location) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$eq;
|
|
426
357
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
427
358
|
/* istanbul ignore else */
|
|
428
359
|
if (typeof locationIdEq === 'string') {
|
|
@@ -444,7 +375,7 @@ class MongoRepository {
|
|
|
444
375
|
});
|
|
445
376
|
}
|
|
446
377
|
}
|
|
447
|
-
const workPerformedIdentifierIn = (
|
|
378
|
+
const workPerformedIdentifierIn = (_27 = params.workPerformed) === null || _27 === void 0 ? void 0 : _27.identifiers;
|
|
448
379
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
449
380
|
/* istanbul ignore else */
|
|
450
381
|
if (Array.isArray(workPerformedIdentifierIn)) {
|
|
@@ -455,7 +386,7 @@ class MongoRepository {
|
|
|
455
386
|
}
|
|
456
387
|
});
|
|
457
388
|
}
|
|
458
|
-
const videoFormatTypeOfEq = (
|
|
389
|
+
const videoFormatTypeOfEq = (_29 = (_28 = params.videoFormat) === null || _28 === void 0 ? void 0 : _28.typeOf) === null || _29 === void 0 ? void 0 : _29.$eq;
|
|
459
390
|
if (typeof videoFormatTypeOfEq === 'string') {
|
|
460
391
|
andConditions.push({
|
|
461
392
|
'videoFormat.typeOf': {
|
|
@@ -464,7 +395,7 @@ class MongoRepository {
|
|
|
464
395
|
}
|
|
465
396
|
});
|
|
466
397
|
}
|
|
467
|
-
const videoFormatTypeOfIn = (
|
|
398
|
+
const videoFormatTypeOfIn = (_31 = (_30 = params.videoFormat) === null || _30 === void 0 ? void 0 : _30.typeOf) === null || _31 === void 0 ? void 0 : _31.$in;
|
|
468
399
|
if (Array.isArray(videoFormatTypeOfIn)) {
|
|
469
400
|
andConditions.push({
|
|
470
401
|
'videoFormat.typeOf': {
|
|
@@ -473,7 +404,7 @@ class MongoRepository {
|
|
|
473
404
|
}
|
|
474
405
|
});
|
|
475
406
|
}
|
|
476
|
-
const soundFormatTypeOfEq = (
|
|
407
|
+
const soundFormatTypeOfEq = (_33 = (_32 = params.soundFormat) === null || _32 === void 0 ? void 0 : _32.typeOf) === null || _33 === void 0 ? void 0 : _33.$eq;
|
|
477
408
|
if (typeof soundFormatTypeOfEq === 'string') {
|
|
478
409
|
andConditions.push({
|
|
479
410
|
'soundFormat.typeOf': {
|
|
@@ -482,7 +413,7 @@ class MongoRepository {
|
|
|
482
413
|
}
|
|
483
414
|
});
|
|
484
415
|
}
|
|
485
|
-
const soundFormatTypeOfIn = (
|
|
416
|
+
const soundFormatTypeOfIn = (_35 = (_34 = params.soundFormat) === null || _34 === void 0 ? void 0 : _34.typeOf) === null || _35 === void 0 ? void 0 : _35.$in;
|
|
486
417
|
if (Array.isArray(soundFormatTypeOfIn)) {
|
|
487
418
|
andConditions.push({
|
|
488
419
|
'soundFormat.typeOf': {
|
|
@@ -618,7 +549,7 @@ class MongoRepository {
|
|
|
618
549
|
return __awaiter(this, void 0, void 0, function* () {
|
|
619
550
|
let doc;
|
|
620
551
|
const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
|
|
621
|
-
const id =
|
|
552
|
+
const id = uniqid();
|
|
622
553
|
doc = yield this.eventModel.findOneAndUpdate({
|
|
623
554
|
typeOf: params.attributes.typeOf,
|
|
624
555
|
// 追加特性をキーに更新
|
|
@@ -30,8 +30,8 @@ const schema = new mongoose.Schema({
|
|
|
30
30
|
startDate: Date,
|
|
31
31
|
workPerformed: mongoose.SchemaTypes.Mixed,
|
|
32
32
|
superEvent: mongoose.SchemaTypes.Mixed,
|
|
33
|
-
videoFormat:
|
|
34
|
-
soundFormat:
|
|
33
|
+
videoFormat: mongoose.SchemaTypes.Mixed,
|
|
34
|
+
soundFormat: mongoose.SchemaTypes.Mixed,
|
|
35
35
|
subtitleLanguage: mongoose.SchemaTypes.Mixed,
|
|
36
36
|
dubLanguage: mongoose.SchemaTypes.Mixed,
|
|
37
37
|
kanaName: String,
|
|
@@ -77,7 +77,12 @@ export declare class MongoRepository {
|
|
|
77
77
|
};
|
|
78
78
|
}): Promise<(string)[]>;
|
|
79
79
|
aggregateOrder(params: factory.order.ISearchConditions): Promise<{
|
|
80
|
-
acceptedOfferCount: number;
|
|
81
80
|
orderCount: number;
|
|
81
|
+
acceptedOfferCount: number;
|
|
82
|
+
avgAcceptedOfferCount: number;
|
|
83
|
+
totalPrice: number;
|
|
84
|
+
maxPrice: number;
|
|
85
|
+
minPrice: number;
|
|
86
|
+
avgPrice: number;
|
|
82
87
|
}[]>;
|
|
83
88
|
}
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -940,9 +940,16 @@ class MongoRepository {
|
|
|
940
940
|
$cond: { if: { $isArray: '$acceptedOffers' }, then: { $size: '$acceptedOffers' }, else: 0 }
|
|
941
941
|
}
|
|
942
942
|
},
|
|
943
|
-
|
|
944
|
-
$
|
|
945
|
-
|
|
943
|
+
avgAcceptedOfferCount: {
|
|
944
|
+
$avg: {
|
|
945
|
+
$cond: { if: { $isArray: '$acceptedOffers' }, then: { $size: '$acceptedOffers' }, else: 0 }
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
orderCount: { $sum: 1 },
|
|
949
|
+
totalPrice: { $sum: '$price' },
|
|
950
|
+
maxPrice: { $max: '$price' },
|
|
951
|
+
minPrice: { $min: '$price' },
|
|
952
|
+
avgPrice: { $avg: '$price' }
|
|
946
953
|
}
|
|
947
954
|
}
|
|
948
955
|
])
|
|
@@ -2,6 +2,23 @@ import { Connection } from 'mongoose';
|
|
|
2
2
|
import * as factory from '../factory';
|
|
3
3
|
import { modelName } from './mongoose/model/transaction';
|
|
4
4
|
export { modelName };
|
|
5
|
+
interface IAggregationByStatus {
|
|
6
|
+
transactionCount: number;
|
|
7
|
+
avgDuration: number;
|
|
8
|
+
maxDuration: number;
|
|
9
|
+
minDuration: number;
|
|
10
|
+
percentilesDuration: {
|
|
11
|
+
name: string;
|
|
12
|
+
value: number;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
interface IStatus {
|
|
16
|
+
status: factory.transactionStatusType;
|
|
17
|
+
aggregation: IAggregationByStatus;
|
|
18
|
+
}
|
|
19
|
+
interface IAggregatePlaceOrder {
|
|
20
|
+
statuses: IStatus[];
|
|
21
|
+
}
|
|
5
22
|
/**
|
|
6
23
|
* 取引リポジトリ
|
|
7
24
|
*/
|
|
@@ -129,4 +146,5 @@ export declare class MongoRepository {
|
|
|
129
146
|
findByIdAndDelete(params: {
|
|
130
147
|
id: string;
|
|
131
148
|
}): Promise<void>;
|
|
149
|
+
aggregatePlaceOrder(params: factory.transaction.placeOrder.ISearchConditions): Promise<IAggregatePlaceOrder>;
|
|
132
150
|
}
|
|
@@ -600,5 +600,141 @@ class MongoRepository {
|
|
|
600
600
|
.exec();
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
|
+
// tslint:disable-next-line:max-func-body-length
|
|
604
|
+
aggregatePlaceOrder(params) {
|
|
605
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
+
const statuses = yield Promise.all([
|
|
607
|
+
factory.transactionStatusType.Canceled,
|
|
608
|
+
factory.transactionStatusType.Expired,
|
|
609
|
+
factory.transactionStatusType.Confirmed
|
|
610
|
+
// tslint:disable-next-line:max-func-body-length
|
|
611
|
+
].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
612
|
+
var _a, _b, _c, _d;
|
|
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: {
|
|
618
|
+
$gte: params.startFrom,
|
|
619
|
+
$lte: params.startThrough
|
|
620
|
+
},
|
|
621
|
+
typeOf: { $eq: params.typeOf },
|
|
622
|
+
status: {
|
|
623
|
+
$in: [transactionStatus]
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const aggregations = yield this.transactionModel.aggregate([
|
|
627
|
+
{
|
|
628
|
+
$match: matchConditions
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
$project: {
|
|
632
|
+
duration: {
|
|
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
|
+
}
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
$project: {
|
|
658
|
+
_id: 0,
|
|
659
|
+
transactionCount: '$transactionCount',
|
|
660
|
+
avgDuration: '$avgDuration',
|
|
661
|
+
maxDuration: '$maxDuration',
|
|
662
|
+
minDuration: '$minDuration'
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
])
|
|
666
|
+
.exec();
|
|
667
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
668
|
+
const percents = [50, 95, 99];
|
|
669
|
+
if (aggregations.length === 0) {
|
|
670
|
+
return {
|
|
671
|
+
status: transactionStatus,
|
|
672
|
+
aggregation: {
|
|
673
|
+
transactionCount: 0,
|
|
674
|
+
avgDuration: 0,
|
|
675
|
+
maxDuration: 0,
|
|
676
|
+
minDuration: 0,
|
|
677
|
+
percentilesDuration: percents.map((percent) => {
|
|
678
|
+
return {
|
|
679
|
+
name: String(percent),
|
|
680
|
+
value: 0
|
|
681
|
+
};
|
|
682
|
+
})
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
687
|
+
return {
|
|
688
|
+
percentile,
|
|
689
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
690
|
+
rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
|
|
691
|
+
};
|
|
692
|
+
});
|
|
693
|
+
const aggregations2 = yield this.transactionModel.aggregate([
|
|
694
|
+
{
|
|
695
|
+
$match: matchConditions
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
$project: {
|
|
699
|
+
duration: {
|
|
700
|
+
$subtract: ['$endDate', '$startDate']
|
|
701
|
+
},
|
|
702
|
+
status: '$status',
|
|
703
|
+
startDate: '$startDate',
|
|
704
|
+
endDate: '$endDate',
|
|
705
|
+
typeOf: '$typeOf'
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
{ $sort: { duration: 1 } },
|
|
709
|
+
{
|
|
710
|
+
$group: {
|
|
711
|
+
_id: '$typeOf',
|
|
712
|
+
durations: { $push: '$duration' }
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
$project: {
|
|
717
|
+
_id: 0,
|
|
718
|
+
avgSmallDuration: '$avgSmallDuration',
|
|
719
|
+
avgMediumDuration: '$avgMediumDuration',
|
|
720
|
+
avgLargeDuration: '$avgLargeDuration',
|
|
721
|
+
percentilesDuration: ranks4percentile.map((rank) => {
|
|
722
|
+
return {
|
|
723
|
+
name: String(rank.percentile),
|
|
724
|
+
value: { $arrayElemAt: ['$durations', rank.rank] }
|
|
725
|
+
};
|
|
726
|
+
})
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
])
|
|
730
|
+
.exec();
|
|
731
|
+
return {
|
|
732
|
+
status: transactionStatus,
|
|
733
|
+
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
734
|
+
};
|
|
735
|
+
})));
|
|
736
|
+
return { statuses };
|
|
737
|
+
});
|
|
738
|
+
}
|
|
603
739
|
}
|
|
604
740
|
exports.MongoRepository = MongoRepository;
|
|
@@ -743,8 +743,7 @@ function updateEvent4ttts(params) {
|
|
|
743
743
|
try {
|
|
744
744
|
event = yield repos.event.save4ttts({
|
|
745
745
|
oldEventId: params.oldEventId,
|
|
746
|
-
attributes: params.attributes
|
|
747
|
-
useOldEventId: params.useOldEventId
|
|
746
|
+
attributes: params.attributes
|
|
748
747
|
});
|
|
749
748
|
}
|
|
750
749
|
catch (error) {
|
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