@chevre/domain 22.9.0-alpha.69 → 22.9.0-alpha.70
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/aggregateOrderOfCustomer.ts +124 -0
- package/example/src/chevre/reIndex.ts +1 -2
- package/lib/chevre/repo/aggregateOrder.d.ts +27 -0
- package/lib/chevre/repo/aggregateOrder.js +148 -0
- package/lib/chevre/repo/assetTransaction.d.ts +8 -0
- package/lib/chevre/repo/assetTransaction.js +39 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOrder.d.ts +23 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOrder.js +78 -0
- package/lib/chevre/repo/order.d.ts +21 -0
- package/lib/chevre/repo/order.js +52 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/package.json +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as fs from 'fs';
|
|
3
|
+
import * as moment from 'moment-timezone';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
9
|
+
const AGGREGATE_PERIOD_IN_DAYS = 365;
|
|
10
|
+
|
|
11
|
+
function createAggregation(params: {
|
|
12
|
+
order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'>;
|
|
13
|
+
orderDateGte: Date;
|
|
14
|
+
orderDateLte: Date;
|
|
15
|
+
}) {
|
|
16
|
+
return async (repos: {
|
|
17
|
+
order: chevre.repository.Order;
|
|
18
|
+
}) => {
|
|
19
|
+
const { order, orderDateGte, orderDateLte } = params;
|
|
20
|
+
|
|
21
|
+
return repos.order.aggregateOrderOfCustomer({
|
|
22
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
23
|
+
orderDate: { $gte: orderDateGte, $lte: orderDateLte },
|
|
24
|
+
customer: { email: { $eq: String(order.customer.email) } }
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// tslint:disable-next-line:max-func-body-length
|
|
30
|
+
async function main() {
|
|
31
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
32
|
+
|
|
33
|
+
const aggregateOrderRepo = await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
|
|
34
|
+
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
35
|
+
|
|
36
|
+
const orderDateLte: Date = moment()
|
|
37
|
+
.toDate();
|
|
38
|
+
const orderDateGte: Date = moment(orderDateLte)
|
|
39
|
+
.add(-AGGREGATE_PERIOD_IN_DAYS, 'days')
|
|
40
|
+
.toDate();
|
|
41
|
+
|
|
42
|
+
const cursor = orderRepo.getCursor(
|
|
43
|
+
{
|
|
44
|
+
'project.id': { $eq: PROJECT_ID },
|
|
45
|
+
orderDate: {
|
|
46
|
+
$gte: orderDateGte,
|
|
47
|
+
$lte: orderDateLte
|
|
48
|
+
},
|
|
49
|
+
typeOf: { $eq: chevre.factory.order.OrderType.Order }
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
customer: 1,
|
|
53
|
+
orderDate: 1,
|
|
54
|
+
orderNumber: 1,
|
|
55
|
+
project: 1
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
console.log('docs found');
|
|
59
|
+
|
|
60
|
+
let maxSumGraceTime: number = 0;
|
|
61
|
+
const peopleWithAggregateOrder: {
|
|
62
|
+
identifier: string;
|
|
63
|
+
aggregateOrder: {
|
|
64
|
+
// emailCount: number;
|
|
65
|
+
orderCount: number;
|
|
66
|
+
sumGraceTime: number;
|
|
67
|
+
};
|
|
68
|
+
score?: number;
|
|
69
|
+
}[] = [];
|
|
70
|
+
|
|
71
|
+
let i = 0;
|
|
72
|
+
let updateCount = 0;
|
|
73
|
+
// tslint:disable-next-line:max-func-body-length
|
|
74
|
+
await cursor.eachAsync(async (doc) => {
|
|
75
|
+
i += 1;
|
|
76
|
+
const order: Pick<chevre.factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'project'> = doc.toObject();
|
|
77
|
+
|
|
78
|
+
const { email } = order.customer;
|
|
79
|
+
if (typeof email === 'string') {
|
|
80
|
+
console.log(
|
|
81
|
+
'aggregating...',
|
|
82
|
+
order.project.id, order.orderNumber, order.orderDate, i);
|
|
83
|
+
const aggregateResult = await createAggregation({ order, orderDateGte, orderDateLte })({ order: orderRepo });
|
|
84
|
+
await aggregateOrderRepo.save(
|
|
85
|
+
{
|
|
86
|
+
project: order.project,
|
|
87
|
+
identifier: email,
|
|
88
|
+
typeOf: chevre.factory.personType.Person
|
|
89
|
+
},
|
|
90
|
+
{ $set: { aggregateOrder: aggregateResult.aggregation } }
|
|
91
|
+
);
|
|
92
|
+
updateCount += 1;
|
|
93
|
+
console.log(
|
|
94
|
+
'aggregated.',
|
|
95
|
+
order.project.id, order.orderNumber, order.orderDate, i);
|
|
96
|
+
|
|
97
|
+
const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
|
|
98
|
+
? aggregateResult.aggregation.sumGraceTime
|
|
99
|
+
: 0;
|
|
100
|
+
maxSumGraceTime = Math.max(sumGraceTime, maxSumGraceTime);
|
|
101
|
+
|
|
102
|
+
peopleWithAggregateOrder.push({
|
|
103
|
+
identifier: email,
|
|
104
|
+
aggregateOrder: {
|
|
105
|
+
...aggregateResult.aggregation,
|
|
106
|
+
sumGraceTime
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
console.log('maxSumGraceTime:', maxSumGraceTime);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
console.log(i, 'docs checked');
|
|
114
|
+
console.log(updateCount, 'docs aggregated');
|
|
115
|
+
|
|
116
|
+
// tslint:disable-next-line:non-literal-fs-path no-null-keyword
|
|
117
|
+
// fs.writeFileSync(`${__dirname}/peopleWithAggregateOrder.json`, JSON.stringify(peopleWithAggregateOrder, null, ' '));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main()
|
|
121
|
+
.then(() => {
|
|
122
|
+
console.log('success!');
|
|
123
|
+
})
|
|
124
|
+
.catch(console.error);
|
|
@@ -11,8 +11,7 @@ mongoose.Model.on('index', (...args) => {
|
|
|
11
11
|
async function main() {
|
|
12
12
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
13
|
|
|
14
|
-
await chevre.repository.
|
|
15
|
-
await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
14
|
+
await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
|
|
16
15
|
console.log('success!');
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
import { IDocType } from './mongoose/schemas/aggregateOrder';
|
|
4
|
+
export interface ISortOrder {
|
|
5
|
+
identifier?: factory.sortType;
|
|
6
|
+
'aggregateOrder.orderCount'?: factory.sortType;
|
|
7
|
+
}
|
|
8
|
+
export interface ISearchConditions {
|
|
9
|
+
limit?: number;
|
|
10
|
+
page?: number;
|
|
11
|
+
sort?: ISortOrder;
|
|
12
|
+
project?: {
|
|
13
|
+
id?: {
|
|
14
|
+
$eq?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 注文集計リポジトリ
|
|
20
|
+
*/
|
|
21
|
+
export declare class AggregateOrderRepo {
|
|
22
|
+
private readonly aggregateOrderModel;
|
|
23
|
+
constructor(connection: Connection);
|
|
24
|
+
save(filter: Pick<IDocType, 'project' | 'identifier' | 'typeOf'>, update: {
|
|
25
|
+
$set: Pick<IDocType, 'aggregateOrder'>;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
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.AggregateOrderRepo = void 0;
|
|
13
|
+
const factory = require("../factory");
|
|
14
|
+
const settings_1 = require("../settings");
|
|
15
|
+
const aggregateOrder_1 = require("./mongoose/schemas/aggregateOrder");
|
|
16
|
+
/**
|
|
17
|
+
* 注文集計リポジトリ
|
|
18
|
+
*/
|
|
19
|
+
class AggregateOrderRepo {
|
|
20
|
+
constructor(connection) {
|
|
21
|
+
this.aggregateOrderModel = connection.model(aggregateOrder_1.modelName, (0, aggregateOrder_1.createSchema)());
|
|
22
|
+
}
|
|
23
|
+
// public static CREATE_MONGO_CONDITIONS(
|
|
24
|
+
// conditions: ISearchConditions
|
|
25
|
+
// ): IMatchStage[] {
|
|
26
|
+
// const matchStages: IMatchStage[] = [];
|
|
27
|
+
// const projectIdEq = conditions.project?.id?.$eq;
|
|
28
|
+
// if (typeof projectIdEq === 'string') {
|
|
29
|
+
// matchStages.push({
|
|
30
|
+
// $match: { 'project.id': { $eq: projectIdEq } }
|
|
31
|
+
// });
|
|
32
|
+
// }
|
|
33
|
+
// const typeOfEq = conditions.reservationFor?.typeOf;
|
|
34
|
+
// if (typeof typeOfEq === 'string') {
|
|
35
|
+
// matchStages.push({
|
|
36
|
+
// $match: { 'reservationFor.typeOf': { $eq: typeOfEq } }
|
|
37
|
+
// });
|
|
38
|
+
// }
|
|
39
|
+
// const idEq = conditions.reservationFor?.id?.$eq;
|
|
40
|
+
// if (typeof idEq === 'string') {
|
|
41
|
+
// matchStages.push({
|
|
42
|
+
// $match: { 'reservationFor.id': { $eq: idEq } }
|
|
43
|
+
// });
|
|
44
|
+
// }
|
|
45
|
+
// const idIn = conditions.reservationFor?.id?.$in;
|
|
46
|
+
// if (Array.isArray(idIn)) {
|
|
47
|
+
// matchStages.push({
|
|
48
|
+
// $match: { 'reservationFor.id': { $in: idIn } }
|
|
49
|
+
// });
|
|
50
|
+
// }
|
|
51
|
+
// const reservationForStartDateGte = conditions.reservationFor?.startFrom;
|
|
52
|
+
// if (reservationForStartDateGte instanceof Date) {
|
|
53
|
+
// matchStages.push({
|
|
54
|
+
// $match: { 'reservationFor.startDate': { $gte: reservationForStartDateGte } }
|
|
55
|
+
// });
|
|
56
|
+
// }
|
|
57
|
+
// const reservationForStartDateLte = conditions.reservationFor?.startThrough;
|
|
58
|
+
// if (reservationForStartDateLte instanceof Date) {
|
|
59
|
+
// matchStages.push({
|
|
60
|
+
// $match: { 'reservationFor.startDate': { $lte: reservationForStartDateLte } }
|
|
61
|
+
// });
|
|
62
|
+
// }
|
|
63
|
+
// return matchStages;
|
|
64
|
+
// }
|
|
65
|
+
// /**
|
|
66
|
+
// * 予約集計を検索する
|
|
67
|
+
// */
|
|
68
|
+
// public async searchWithReservationForId(
|
|
69
|
+
// params: ISearchConditions,
|
|
70
|
+
// inclusion: ('aggregateOffer')[]
|
|
71
|
+
// ): Promise<ISearchWithReservationForIdResult[]> {
|
|
72
|
+
// const matchStages = AggregateReservationRepo.CREATE_MONGO_CONDITIONS(params);
|
|
73
|
+
// let projectStage: { [field in IKeyOfProjection]?: AnyExpression } = {
|
|
74
|
+
// _id: 0,
|
|
75
|
+
// id: '$reservationFor.id'
|
|
76
|
+
// };
|
|
77
|
+
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
78
|
+
// inclusion.forEach((field) => {
|
|
79
|
+
// projectStage[field] = { $ifNull: [`$${field}`, '$false'] };
|
|
80
|
+
// // projectStage[field] = 1;
|
|
81
|
+
// });
|
|
82
|
+
// } else {
|
|
83
|
+
// projectStage = {
|
|
84
|
+
// _id: 0,
|
|
85
|
+
// id: '$reservationFor.id',
|
|
86
|
+
// // aggregateEntranceGate: 1, // discontinue(2024-12-23~)
|
|
87
|
+
// aggregateOffer: 1
|
|
88
|
+
// };
|
|
89
|
+
// }
|
|
90
|
+
// const sortByStartDate = params.sort?.['reservationFor.startDate'];
|
|
91
|
+
// const aggregate = this.aggregateReservationModel.aggregate<ISearchWithReservationForIdResult>([
|
|
92
|
+
// ...matchStages,
|
|
93
|
+
// ...(typeof sortByStartDate === 'number')
|
|
94
|
+
// ? [{ $sort: { 'reservationFor.startDate': sortByStartDate } }]
|
|
95
|
+
// : [],
|
|
96
|
+
// // 現時点でreservationFor.idへのunique indexがないので、重複ドキュメント対応として、$group
|
|
97
|
+
// {
|
|
98
|
+
// $group: {
|
|
99
|
+
// _id: '$reservationFor.id',
|
|
100
|
+
// reservationFor: { $first: '$reservationFor' },
|
|
101
|
+
// aggregateEntranceGate: { $first: '$aggregateEntranceGate' },
|
|
102
|
+
// aggregateOffer: { $first: '$aggregateOffer' }
|
|
103
|
+
// }
|
|
104
|
+
// },
|
|
105
|
+
// { $project: projectStage }
|
|
106
|
+
// ]);
|
|
107
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
108
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
109
|
+
// aggregate.limit(params.limit * page)
|
|
110
|
+
// .skip(params.limit * (page - 1));
|
|
111
|
+
// }
|
|
112
|
+
// return aggregate
|
|
113
|
+
// .option({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
114
|
+
// .exec();
|
|
115
|
+
// }
|
|
116
|
+
save(filter, update) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const { $set } = update;
|
|
119
|
+
const setOnInsert = {
|
|
120
|
+
project: { id: filter.project.id, typeOf: factory.organizationType.Project },
|
|
121
|
+
typeOf: filter.typeOf,
|
|
122
|
+
identifier: filter.identifier
|
|
123
|
+
};
|
|
124
|
+
const doc = yield this.aggregateOrderModel.findOneAndUpdate({
|
|
125
|
+
'project.id': { $eq: filter.project.id },
|
|
126
|
+
identifier: { $eq: filter.identifier },
|
|
127
|
+
typeOf: { $eq: filter.typeOf }
|
|
128
|
+
}, {
|
|
129
|
+
$set,
|
|
130
|
+
$setOnInsert: setOnInsert
|
|
131
|
+
}, {
|
|
132
|
+
new: true,
|
|
133
|
+
upsert: true,
|
|
134
|
+
projection: {
|
|
135
|
+
_id: 0,
|
|
136
|
+
id: { $toString: '$_id' }
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
.lean()
|
|
140
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
141
|
+
.exec();
|
|
142
|
+
if (doc === null) {
|
|
143
|
+
throw new factory.errors.NotFound(this.aggregateOrderModel.modelName);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.AggregateOrderRepo = AggregateOrderRepo;
|
|
@@ -118,6 +118,14 @@ export declare class AssetTransactionRepo {
|
|
|
118
118
|
setTasksExportedById(params: {
|
|
119
119
|
id: string;
|
|
120
120
|
}): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* add(2025-03-12~)
|
|
123
|
+
*/
|
|
124
|
+
makeOneExpiredIfExists(params: {
|
|
125
|
+
expires: {
|
|
126
|
+
$lt: Date;
|
|
127
|
+
};
|
|
128
|
+
}): Promise<Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType>, 'id' | 'typeOf'> | void>;
|
|
121
129
|
/**
|
|
122
130
|
* 取引を期限切れにする
|
|
123
131
|
*/
|
|
@@ -632,6 +632,45 @@ class AssetTransactionRepo {
|
|
|
632
632
|
.exec();
|
|
633
633
|
});
|
|
634
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* add(2025-03-12~)
|
|
637
|
+
*/
|
|
638
|
+
makeOneExpiredIfExists(params) {
|
|
639
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
640
|
+
const endDate = new Date();
|
|
641
|
+
const sort = {
|
|
642
|
+
expires: factory.sortType.Ascending
|
|
643
|
+
};
|
|
644
|
+
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
645
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
646
|
+
expires: { $lt: params.expires.$lt }
|
|
647
|
+
}, {
|
|
648
|
+
status: factory.transactionStatusType.Expired,
|
|
649
|
+
endDate
|
|
650
|
+
}, {
|
|
651
|
+
new: true,
|
|
652
|
+
projection: {
|
|
653
|
+
_id: 0,
|
|
654
|
+
id: { $toString: '$_id' },
|
|
655
|
+
typeOf: 1
|
|
656
|
+
}
|
|
657
|
+
})
|
|
658
|
+
.sort(sort)
|
|
659
|
+
.lean()
|
|
660
|
+
.exec();
|
|
661
|
+
if (doc === null) {
|
|
662
|
+
// no op
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
666
|
+
id: doc.id,
|
|
667
|
+
typeOf: doc.typeOf,
|
|
668
|
+
status: factory.transactionStatusType.Expired
|
|
669
|
+
});
|
|
670
|
+
return doc;
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
635
674
|
/**
|
|
636
675
|
* 取引を期限切れにする
|
|
637
676
|
*/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
export interface IAggregateOrder {
|
|
4
|
+
orderCount: number;
|
|
5
|
+
sumGraceTime?: number;
|
|
6
|
+
emailCount?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface IDocType {
|
|
9
|
+
aggregateOrder: factory.event.event.IAggregateOffer;
|
|
10
|
+
identifier: string;
|
|
11
|
+
project: {
|
|
12
|
+
id: string;
|
|
13
|
+
typeOf: factory.organizationType.Project;
|
|
14
|
+
};
|
|
15
|
+
typeOf: factory.personType.Person | factory.placeType.Seat;
|
|
16
|
+
}
|
|
17
|
+
type IModel = Model<IDocType>;
|
|
18
|
+
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
19
|
+
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
20
|
+
declare const modelName = "AggregateOrder";
|
|
21
|
+
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
22
|
+
declare function createSchema(): ISchema;
|
|
23
|
+
export { createSchema, IModel, indexes, modelName };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modelName = exports.indexes = void 0;
|
|
4
|
+
exports.createSchema = createSchema;
|
|
5
|
+
const mongoose_1 = require("mongoose");
|
|
6
|
+
const writeConcern_1 = require("../writeConcern");
|
|
7
|
+
const settings_1 = require("../../../settings");
|
|
8
|
+
const modelName = 'AggregateOrder';
|
|
9
|
+
exports.modelName = modelName;
|
|
10
|
+
const schemaDefinition = {
|
|
11
|
+
aggregateOrder: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
|
+
identifier: { type: String, required: true },
|
|
13
|
+
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
14
|
+
typeOf: { type: String, required: true }
|
|
15
|
+
};
|
|
16
|
+
const schemaOptions = {
|
|
17
|
+
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
18
|
+
autoCreate: false,
|
|
19
|
+
collection: 'aggregateOrders',
|
|
20
|
+
id: true,
|
|
21
|
+
read: settings_1.MONGO_READ_PREFERENCE,
|
|
22
|
+
writeConcern: writeConcern_1.writeConcern,
|
|
23
|
+
strict: true,
|
|
24
|
+
strictQuery: false,
|
|
25
|
+
timestamps: false,
|
|
26
|
+
versionKey: false,
|
|
27
|
+
toJSON: {
|
|
28
|
+
getters: false,
|
|
29
|
+
virtuals: false,
|
|
30
|
+
minimize: false,
|
|
31
|
+
versionKey: false
|
|
32
|
+
},
|
|
33
|
+
toObject: {
|
|
34
|
+
getters: false,
|
|
35
|
+
virtuals: true,
|
|
36
|
+
minimize: false,
|
|
37
|
+
versionKey: false
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const indexes = [
|
|
41
|
+
[
|
|
42
|
+
{ identifier: 1 },
|
|
43
|
+
{ name: 'identifier' }
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
{ 'aggregateOrder.orderCount': 1, identifier: 1 },
|
|
47
|
+
{
|
|
48
|
+
name: 'aggregateOrderOrderCount',
|
|
49
|
+
partialFilterExpression: {
|
|
50
|
+
'aggregateOrder.orderCount': { $exists: true }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
{ 'project.id': 1, identifier: 1 },
|
|
56
|
+
{
|
|
57
|
+
unique: true,
|
|
58
|
+
name: 'uniqueByProjectAndIdentifier'
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
{ typeOf: 1, identifier: 1 },
|
|
63
|
+
{ name: 'typeOf' }
|
|
64
|
+
]
|
|
65
|
+
];
|
|
66
|
+
exports.indexes = indexes;
|
|
67
|
+
let schema;
|
|
68
|
+
function createSchema() {
|
|
69
|
+
if (schema === undefined) {
|
|
70
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
71
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
72
|
+
indexes.forEach((indexParams) => {
|
|
73
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return schema;
|
|
78
|
+
}
|
|
@@ -199,5 +199,26 @@ export declare class OrderRepo {
|
|
|
199
199
|
emailCount?: number;
|
|
200
200
|
};
|
|
201
201
|
}>;
|
|
202
|
+
aggregateOrderOfCustomer(params: {
|
|
203
|
+
project: {
|
|
204
|
+
id: {
|
|
205
|
+
$eq: string;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
orderDate: {
|
|
209
|
+
$gte: Date;
|
|
210
|
+
$lte: Date;
|
|
211
|
+
};
|
|
212
|
+
customer: {
|
|
213
|
+
email: {
|
|
214
|
+
$eq: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
}): Promise<{
|
|
218
|
+
aggregation: Pick<IAggregation, 'orderCount'> & {
|
|
219
|
+
sumGraceTime?: number;
|
|
220
|
+
emailCount?: number;
|
|
221
|
+
};
|
|
222
|
+
}>;
|
|
202
223
|
}
|
|
203
224
|
export {};
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -1170,5 +1170,57 @@ class OrderRepo {
|
|
|
1170
1170
|
};
|
|
1171
1171
|
});
|
|
1172
1172
|
}
|
|
1173
|
+
aggregateOrderOfCustomer(params) {
|
|
1174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1175
|
+
const matchConditions = {
|
|
1176
|
+
orderDate: {
|
|
1177
|
+
$gte: params.orderDate.$gte,
|
|
1178
|
+
$lte: params.orderDate.$lte
|
|
1179
|
+
},
|
|
1180
|
+
typeOf: { $eq: factory.order.OrderType.Order },
|
|
1181
|
+
'project.id': { $eq: params.project.id.$eq },
|
|
1182
|
+
'customer.email': { $exists: true, $eq: params.customer.email.$eq }
|
|
1183
|
+
};
|
|
1184
|
+
const aggregations = yield this.orderModel.aggregate([
|
|
1185
|
+
{ $match: matchConditions },
|
|
1186
|
+
{
|
|
1187
|
+
$project: {
|
|
1188
|
+
typeOf: '$typeOf',
|
|
1189
|
+
graceTime: {
|
|
1190
|
+
$subtract: [
|
|
1191
|
+
{ $first: '$acceptedOffers.itemOffered.reservationFor.startDate' },
|
|
1192
|
+
'$orderDate'
|
|
1193
|
+
]
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
$group: {
|
|
1199
|
+
_id: '$typeOf',
|
|
1200
|
+
orderCount: { $sum: 1 },
|
|
1201
|
+
sumGraceTime: { $sum: '$graceTime' }
|
|
1202
|
+
}
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
$project: {
|
|
1206
|
+
_id: 0,
|
|
1207
|
+
orderCount: '$orderCount',
|
|
1208
|
+
sumGraceTime: '$sumGraceTime'
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
])
|
|
1212
|
+
.exec();
|
|
1213
|
+
if (aggregations.length === 0) {
|
|
1214
|
+
return {
|
|
1215
|
+
aggregation: {
|
|
1216
|
+
orderCount: 0
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
return {
|
|
1221
|
+
aggregation: Object.assign({}, aggregations[0])
|
|
1222
|
+
};
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1173
1225
|
}
|
|
1174
1226
|
exports.OrderRepo = OrderRepo;
|
|
@@ -9,6 +9,7 @@ import type { AccountTransactionRepo } from './repo/accountTransaction';
|
|
|
9
9
|
import type { ActionRepo } from './repo/action';
|
|
10
10
|
import type { AdditionalPropertyRepo } from './repo/additionalProperty';
|
|
11
11
|
import type { AggregateOfferRepo } from './repo/aggregateOffer';
|
|
12
|
+
import type { AggregateOrderRepo } from './repo/aggregateOrder';
|
|
12
13
|
import type { AggregateReservationRepo } from './repo/aggregateReservation';
|
|
13
14
|
import type { AggregationRepo } from './repo/aggregation';
|
|
14
15
|
import type { AssetTransactionRepo } from './repo/assetTransaction';
|
|
@@ -113,6 +114,10 @@ export type AggregateOffer = AggregateOfferRepo;
|
|
|
113
114
|
export declare namespace AggregateOffer {
|
|
114
115
|
function createInstance(...params: ConstructorParameters<typeof AggregateOfferRepo>): Promise<AggregateOfferRepo>;
|
|
115
116
|
}
|
|
117
|
+
export type AggregateOrder = AggregateOrderRepo;
|
|
118
|
+
export declare namespace AggregateOrder {
|
|
119
|
+
function createInstance(...params: ConstructorParameters<typeof AggregateOrderRepo>): Promise<AggregateOrderRepo>;
|
|
120
|
+
}
|
|
116
121
|
export type AggregateReservation = AggregateReservationRepo;
|
|
117
122
|
export declare namespace AggregateReservation {
|
|
118
123
|
function createInstance(...params: ConstructorParameters<typeof AggregateReservationRepo>): Promise<AggregateReservationRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = void 0;
|
|
12
|
+
exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
|
|
13
|
+
exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = void 0;
|
|
14
14
|
var AcceptedOffer;
|
|
15
15
|
(function (AcceptedOffer) {
|
|
16
16
|
let repo;
|
|
@@ -115,6 +115,19 @@ var AggregateOffer;
|
|
|
115
115
|
}
|
|
116
116
|
AggregateOffer.createInstance = createInstance;
|
|
117
117
|
})(AggregateOffer || (exports.AggregateOffer = AggregateOffer = {}));
|
|
118
|
+
var AggregateOrder;
|
|
119
|
+
(function (AggregateOrder) {
|
|
120
|
+
let repo;
|
|
121
|
+
function createInstance(...params) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (repo === undefined) {
|
|
124
|
+
repo = (yield Promise.resolve().then(() => require('./repo/aggregateOrder'))).AggregateOrderRepo;
|
|
125
|
+
}
|
|
126
|
+
return new repo(...params);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
AggregateOrder.createInstance = createInstance;
|
|
130
|
+
})(AggregateOrder || (exports.AggregateOrder = AggregateOrder = {}));
|
|
118
131
|
var AggregateReservation;
|
|
119
132
|
(function (AggregateReservation) {
|
|
120
133
|
let repo;
|
package/package.json
CHANGED