@chevre/domain 20.4.0-alpha.26 → 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/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 +13 -1
- package/package.json +2 -2
|
@@ -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);
|
|
@@ -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,7 +32,7 @@ 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;
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
36
|
const andConditions = [];
|
|
37
37
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
38
38
|
if (typeof projectIdEq === 'string') {
|
|
@@ -146,6 +146,10 @@ class MongoRepository {
|
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
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
|
+
}
|
|
149
153
|
return andConditions;
|
|
150
154
|
}
|
|
151
155
|
count(params) {
|
|
@@ -248,5 +252,13 @@ class MongoRepository {
|
|
|
248
252
|
.sort({ price: factory.sortType.Ascending })
|
|
249
253
|
.cursor();
|
|
250
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
|
+
}
|
|
251
263
|
}
|
|
252
264
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@chevre/factory": "4.291.0",
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
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
|
}
|