@chevre/domain 20.4.0-alpha.25 → 20.4.0-alpha.27
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/reIndex.ts +25 -0
- package/example/src/chevre/searchOfferCatalogs.ts +29 -0
- package/lib/chevre/repo/mongoose/model/priceSpecification.js +19 -52
- package/lib/chevre/repo/offerCatalog.d.ts +3 -1
- package/lib/chevre/repo/offerCatalog.js +51 -13
- package/lib/chevre/repo/priceSpecification.d.ts +1 -0
- package/lib/chevre/repo/priceSpecification.js +35 -66
- package/package.json +3 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
8
|
+
|
|
9
|
+
const priceSpecificationRepo = new chevre.repository.PriceSpecification(mongoose.connection);
|
|
10
|
+
const result = await priceSpecificationRepo.reIndex();
|
|
11
|
+
console.log(result);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main()
|
|
15
|
+
.then()
|
|
16
|
+
.catch(console.error);
|
|
17
|
+
// setInterval(
|
|
18
|
+
// () => {
|
|
19
|
+
// main()
|
|
20
|
+
// .then()
|
|
21
|
+
// .catch(console.error);
|
|
22
|
+
// },
|
|
23
|
+
// // tslint:disable-next-line:no-magic-numbers
|
|
24
|
+
// 60000
|
|
25
|
+
// );
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const PROJECT_ID = process.env.PROJECT_ID;
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const catalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
console.log('searching...');
|
|
14
|
+
const catalogs = await catalogRepo.search(
|
|
15
|
+
{
|
|
16
|
+
project: { id: { $eq: PROJECT_ID } },
|
|
17
|
+
identifier: { $eq: '0001' },
|
|
18
|
+
sort: { identifier: chevre.factory.sortType.Descending },
|
|
19
|
+
limit: 2,
|
|
20
|
+
page: 1
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
console.log('catalogs found', catalogs.map((catalog) => `${catalog.identifier} ${catalog.numberOfItems}`));
|
|
24
|
+
console.log(catalogs.length);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
main()
|
|
28
|
+
.then(console.log)
|
|
29
|
+
.catch(console.error);
|
|
@@ -10,29 +10,24 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
|
|
|
10
10
|
*/
|
|
11
11
|
const schema = new mongoose.Schema({
|
|
12
12
|
project: mongoose.SchemaTypes.Mixed,
|
|
13
|
-
typeOf: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
eligibleQuantity: mongoose.SchemaTypes.Mixed,
|
|
18
|
-
eligibleTransactionVolume: [mongoose.SchemaTypes.Mixed],
|
|
19
|
-
maxPrice: Number,
|
|
20
|
-
minPrice: Number,
|
|
21
|
-
price: Number,
|
|
13
|
+
typeOf: { type: String, required: true },
|
|
14
|
+
name: mongoose.SchemaTypes.Mixed,
|
|
15
|
+
price: { type: Number, required: true },
|
|
22
16
|
priceCurrency: String,
|
|
23
17
|
validFrom: Date,
|
|
24
18
|
validThrough: Date,
|
|
25
19
|
valueAddedTaxIncluded: Boolean,
|
|
26
|
-
referenceQuantity: mongoose.SchemaTypes.Mixed,
|
|
27
|
-
appliesToSoundFormat: String,
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
// referenceQuantity: mongoose.SchemaTypes.Mixed,
|
|
21
|
+
// appliesToSoundFormat: String,
|
|
22
|
+
appliesToCategoryCode: mongoose.SchemaTypes.Mixed,
|
|
23
|
+
appliesToMovieTicket: mongoose.SchemaTypes.Mixed,
|
|
24
|
+
appliesToVideoFormat: String
|
|
30
25
|
}, {
|
|
31
26
|
collection: 'priceSpecifications',
|
|
32
27
|
id: true,
|
|
33
28
|
read: 'primaryPreferred',
|
|
34
29
|
writeConcern: writeConcern,
|
|
35
|
-
strict:
|
|
30
|
+
strict: true,
|
|
36
31
|
useNestedStrict: true,
|
|
37
32
|
timestamps: {
|
|
38
33
|
createdAt: 'createdAt',
|
|
@@ -54,53 +49,25 @@ const schema = new mongoose.Schema({
|
|
|
54
49
|
exports.schema = schema;
|
|
55
50
|
schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
|
|
56
51
|
schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
|
|
57
|
-
schema.index({ price: 1 }, {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
price: { $exists: true }
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
schema.index({ 'priceComponent.typeOf': 1 }, {
|
|
64
|
-
name: 'searchByPriceComponentTypeOf',
|
|
65
|
-
partialFilterExpression: {
|
|
66
|
-
'priceComponent.typeOf': { $exists: true }
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
schema.index({ 'project.id': 1, price: 1 }, {
|
|
70
|
-
name: 'searchByProjectId-v20220721'
|
|
71
|
-
});
|
|
72
|
-
schema.index({ typeOf: 1, price: 1 }, {
|
|
73
|
-
name: 'searchByTypeOf-v2',
|
|
74
|
-
partialFilterExpression: {
|
|
75
|
-
price: { $exists: true }
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
schema.index({ appliesToSoundFormat: 1, price: 1 }, {
|
|
79
|
-
name: 'searchByAppliesToSoundFormat',
|
|
80
|
-
partialFilterExpression: {
|
|
81
|
-
appliesToSoundFormat: { $exists: true },
|
|
82
|
-
price: { $exists: true }
|
|
83
|
-
}
|
|
84
|
-
});
|
|
52
|
+
schema.index({ price: 1 }, { name: 'searchByPrice' });
|
|
53
|
+
schema.index({ 'project.id': 1, price: 1 }, { name: 'searchByProjectId' });
|
|
54
|
+
schema.index({ typeOf: 1, price: 1 }, { name: 'searchByTypeOf' });
|
|
85
55
|
schema.index({ appliesToVideoFormat: 1, price: 1 }, {
|
|
86
56
|
name: 'searchByAppliesToVideoFormat',
|
|
87
57
|
partialFilterExpression: {
|
|
88
|
-
appliesToVideoFormat: { $exists: true }
|
|
89
|
-
price: { $exists: true }
|
|
58
|
+
appliesToVideoFormat: { $exists: true }
|
|
90
59
|
}
|
|
91
60
|
});
|
|
92
|
-
schema.index({
|
|
93
|
-
name: '
|
|
61
|
+
schema.index({ 'appliesToMovieTicket.serviceType': 1, price: 1 }, {
|
|
62
|
+
name: 'searchByAppliesToMovieTicketServiceType',
|
|
94
63
|
partialFilterExpression: {
|
|
95
|
-
|
|
96
|
-
price: { $exists: true }
|
|
64
|
+
'appliesToMovieTicket.serviceType': { $exists: true }
|
|
97
65
|
}
|
|
98
66
|
});
|
|
99
|
-
schema.index({ 'appliesToMovieTicket.
|
|
100
|
-
name: '
|
|
67
|
+
schema.index({ 'appliesToMovieTicket.serviceOutput.typeOf': 1, price: 1 }, {
|
|
68
|
+
name: 'searchByAppliesToMovieTicketServiceOutputTypeOf',
|
|
101
69
|
partialFilterExpression: {
|
|
102
|
-
'appliesToMovieTicket.
|
|
103
|
-
price: { $exists: true }
|
|
70
|
+
'appliesToMovieTicket.serviceOutput.typeOf': { $exists: true }
|
|
104
71
|
}
|
|
105
72
|
});
|
|
106
73
|
schema.index({ appliesToCategoryCode: 1, price: 1 }, {
|
|
@@ -32,7 +32,9 @@ export declare class MongoRepository {
|
|
|
32
32
|
id: string;
|
|
33
33
|
}): Promise<factory.offerCatalog.IOfferCatalog>;
|
|
34
34
|
count(params: factory.offerCatalog.ISearchConditions): Promise<number>;
|
|
35
|
-
search(params: factory.offerCatalog.ISearchConditions): Promise<factory.offerCatalog.IOfferCatalog
|
|
35
|
+
search(params: factory.offerCatalog.ISearchConditions): Promise<(Omit<factory.offerCatalog.IOfferCatalog, 'itemListElement'> & {
|
|
36
|
+
numberOfItems?: number;
|
|
37
|
+
})[]>;
|
|
36
38
|
deleteById(params: {
|
|
37
39
|
id: string;
|
|
38
40
|
}): Promise<void>;
|
|
@@ -205,24 +205,62 @@ class MongoRepository {
|
|
|
205
205
|
search(params) {
|
|
206
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
207
|
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
createdAt: 0,
|
|
211
|
-
updatedAt: 0
|
|
208
|
+
const matchStages = conditions.map((condition) => {
|
|
209
|
+
return { $match: condition };
|
|
212
210
|
});
|
|
211
|
+
// numberOfItems集計(2023-02-28~)
|
|
212
|
+
const aggregate = this.offerCatalogModel.aggregate([
|
|
213
|
+
...(params.sort !== undefined) ? [{ $sort: params.sort }] : [],
|
|
214
|
+
...matchStages,
|
|
215
|
+
{
|
|
216
|
+
$project: {
|
|
217
|
+
_id: 0,
|
|
218
|
+
name: '$name',
|
|
219
|
+
description: '$description',
|
|
220
|
+
project: '$project',
|
|
221
|
+
typeOf: '$typeOf',
|
|
222
|
+
id: '$_id',
|
|
223
|
+
identifier: '$identifier',
|
|
224
|
+
// itemListElement: '$itemListElement',
|
|
225
|
+
itemOffered: '$itemOffered',
|
|
226
|
+
additionalProperty: '$additionalProperty',
|
|
227
|
+
numberOfItems: {
|
|
228
|
+
$cond: {
|
|
229
|
+
if: { $isArray: '$itemListElement' },
|
|
230
|
+
then: { $size: '$itemListElement' },
|
|
231
|
+
else: 0
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
]);
|
|
213
237
|
if (typeof params.limit === 'number') {
|
|
214
238
|
const page = (typeof params.page === 'number') ? params.page : 1;
|
|
215
|
-
|
|
239
|
+
aggregate.limit(params.limit * page)
|
|
216
240
|
.skip(params.limit * (page - 1));
|
|
217
241
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
242
|
+
return aggregate.exec();
|
|
243
|
+
// const query = this.offerCatalogModel.find(
|
|
244
|
+
// (conditions.length > 0) ? { $and: conditions } : {},
|
|
245
|
+
// {
|
|
246
|
+
// __v: 0,
|
|
247
|
+
// createdAt: 0,
|
|
248
|
+
// updatedAt: 0
|
|
249
|
+
// }
|
|
250
|
+
// );
|
|
251
|
+
// if (typeof params.limit === 'number') {
|
|
252
|
+
// const page: number = (typeof params.page === 'number') ? params.page : 1;
|
|
253
|
+
// query.limit(params.limit)
|
|
254
|
+
// .skip(params.limit * (page - 1));
|
|
255
|
+
// }
|
|
256
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
257
|
+
// /* istanbul ignore else */
|
|
258
|
+
// if (params.sort !== undefined) {
|
|
259
|
+
// query.sort(params.sort);
|
|
260
|
+
// }
|
|
261
|
+
// return query.setOptions({ maxTimeMS: 10000 })
|
|
262
|
+
// .exec()
|
|
263
|
+
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
226
264
|
});
|
|
227
265
|
}
|
|
228
266
|
deleteById(params) {
|
|
@@ -32,37 +32,23 @@ class MongoRepository {
|
|
|
32
32
|
}
|
|
33
33
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
34
34
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
35
36
|
const andConditions = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (params.project.id !== undefined && params.project.id !== null) {
|
|
40
|
-
if (typeof params.project.id.$eq === 'string') {
|
|
41
|
-
andConditions.push({
|
|
42
|
-
'project.id': {
|
|
43
|
-
$eq: params.project.id.$eq
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
37
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
38
|
+
if (typeof projectIdEq === 'string') {
|
|
39
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
48
40
|
}
|
|
49
41
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
50
42
|
/* istanbul ignore else */
|
|
51
43
|
if (params.id !== undefined && params.id !== null) {
|
|
52
44
|
if (typeof params.id.$eq === 'string') {
|
|
53
|
-
andConditions.push({
|
|
54
|
-
_id: {
|
|
55
|
-
$eq: params.id.$eq
|
|
56
|
-
}
|
|
57
|
-
});
|
|
45
|
+
andConditions.push({ _id: { $eq: params.id.$eq } });
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
61
49
|
/* istanbul ignore else */
|
|
62
50
|
if (params.typeOf !== undefined) {
|
|
63
|
-
andConditions.push({
|
|
64
|
-
typeOf: params.typeOf
|
|
65
|
-
});
|
|
51
|
+
andConditions.push({ typeOf: params.typeOf });
|
|
66
52
|
}
|
|
67
53
|
if (params.appliesToCategoryCode !== undefined && params.appliesToCategoryCode !== null) {
|
|
68
54
|
if (params.appliesToCategoryCode.$elemMatch !== undefined && params.appliesToCategoryCode.$elemMatch !== null) {
|
|
@@ -122,15 +108,23 @@ class MongoRepository {
|
|
|
122
108
|
}
|
|
123
109
|
});
|
|
124
110
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
111
|
+
const appliesToMovieTicketServiceTypeIn = (_c = params.appliesToMovieTicket) === null || _c === void 0 ? void 0 : _c.serviceTypes;
|
|
112
|
+
if (Array.isArray(appliesToMovieTicketServiceTypeIn)) {
|
|
113
|
+
andConditions.push({
|
|
114
|
+
'appliesToMovieTicket.serviceType': {
|
|
115
|
+
$exists: true,
|
|
116
|
+
$in: appliesToMovieTicketServiceTypeIn
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const appliesToMovieTicketServiceOutputTypeOfEq = (_f = (_e = (_d = params.appliesToMovieTicket) === null || _d === void 0 ? void 0 : _d.serviceOutput) === null || _e === void 0 ? void 0 : _e.typeOf) === null || _f === void 0 ? void 0 : _f.$eq;
|
|
121
|
+
if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
|
|
122
|
+
andConditions.push({
|
|
123
|
+
'appliesToMovieTicket.serviceOutput.typeOf': {
|
|
124
|
+
$exists: true,
|
|
125
|
+
$eq: appliesToMovieTicketServiceOutputTypeOfEq
|
|
126
|
+
}
|
|
127
|
+
});
|
|
134
128
|
}
|
|
135
129
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
136
130
|
/* istanbul ignore else */
|
|
@@ -152,45 +146,12 @@ class MongoRepository {
|
|
|
152
146
|
}
|
|
153
147
|
});
|
|
154
148
|
}
|
|
149
|
+
const priceEq = (_g = params.price) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
150
|
+
if (typeof priceEq === 'number') {
|
|
151
|
+
andConditions.push({ price: { $eq: priceEq } });
|
|
152
|
+
}
|
|
155
153
|
return andConditions;
|
|
156
154
|
}
|
|
157
|
-
// public async countCompoundPriceSpecifications<T extends factory.priceSpecificationType>(
|
|
158
|
-
// params: factory.compoundPriceSpecification.ISearchConditions<T>
|
|
159
|
-
// ): Promise<number> {
|
|
160
|
-
// const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
|
|
161
|
-
// return this.priceSpecificationModel.countDocuments(
|
|
162
|
-
// { $and: conditions }
|
|
163
|
-
// )
|
|
164
|
-
// .setOptions({ maxTimeMS: 10000 })
|
|
165
|
-
// .exec();
|
|
166
|
-
// }
|
|
167
|
-
// public async searchCompoundPriceSpecifications<T extends factory.priceSpecificationType>(
|
|
168
|
-
// params: factory.compoundPriceSpecification.ISearchConditions<T>
|
|
169
|
-
// ): Promise<factory.compoundPriceSpecification.IPriceSpecification<T>[]> {
|
|
170
|
-
// const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
|
|
171
|
-
// const query = this.priceSpecificationModel.find(
|
|
172
|
-
// { $and: conditions },
|
|
173
|
-
// {
|
|
174
|
-
// __v: 0,
|
|
175
|
-
// createdAt: 0,
|
|
176
|
-
// updatedAt: 0
|
|
177
|
-
// }
|
|
178
|
-
// );
|
|
179
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
180
|
-
// /* istanbul ignore else */
|
|
181
|
-
// if (params.limit !== undefined && params.page !== undefined) {
|
|
182
|
-
// query.limit(params.limit)
|
|
183
|
-
// .skip(params.limit * (params.page - 1));
|
|
184
|
-
// }
|
|
185
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
186
|
-
// /* istanbul ignore else */
|
|
187
|
-
// if (params.sort !== undefined) {
|
|
188
|
-
// query.sort(params.sort);
|
|
189
|
-
// }
|
|
190
|
-
// return query.setOptions({ maxTimeMS: 10000 })
|
|
191
|
-
// .exec()
|
|
192
|
-
// .then((docs) => docs.map((doc) => doc.toObject()));
|
|
193
|
-
// }
|
|
194
155
|
count(params) {
|
|
195
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
157
|
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
@@ -291,5 +252,13 @@ class MongoRepository {
|
|
|
291
252
|
.sort({ price: factory.sortType.Ascending })
|
|
292
253
|
.cursor();
|
|
293
254
|
}
|
|
255
|
+
reIndex() {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
// return this.priceSpecificationModel.collection.name;
|
|
258
|
+
return this.priceSpecificationModel.db.db.command({
|
|
259
|
+
reIndex: this.priceSpecificationModel.collection.name
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
294
263
|
}
|
|
295
264
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
12
|
+
"@chevre/factory": "4.291.0",
|
|
13
|
+
"@cinerino/sdk": "3.141.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"postversion": "git push origin --tags",
|
|
121
121
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
122
122
|
},
|
|
123
|
-
"version": "20.4.0-alpha.
|
|
123
|
+
"version": "20.4.0-alpha.27"
|
|
124
124
|
}
|