@chevre/domain 21.17.0-alpha.6 → 21.17.0-alpha.8
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/lib/chevre/repo/aggregateOffer.js +2 -2
- package/lib/chevre/repo/offer.js +2 -2
- package/lib/chevre/repo/offerCatalog.d.ts +0 -4
- package/lib/chevre/repo/offerCatalog.js +39 -29
- package/lib/chevre/repo/offerCatalogItem.d.ts +20 -0
- package/lib/chevre/repo/offerCatalogItem.js +34 -0
- package/package.json +1 -1
- package/example/src/chevre/optimizeCatalogs.ts +0 -54
|
@@ -437,14 +437,14 @@ class MongoRepository {
|
|
|
437
437
|
count(params) {
|
|
438
438
|
return __awaiter(this, void 0, void 0, function* () {
|
|
439
439
|
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
440
|
-
const
|
|
440
|
+
const result = yield this.aggregateOfferModel.aggregate([
|
|
441
441
|
...matchStages,
|
|
442
442
|
{
|
|
443
443
|
$count: 'offerCount'
|
|
444
444
|
}
|
|
445
445
|
])
|
|
446
446
|
.exec();
|
|
447
|
-
return offerCount;
|
|
447
|
+
return (result.length > 0) ? result[0].offerCount : 0;
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
450
|
search(params, projection) {
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -678,7 +678,7 @@ class MongoRepository {
|
|
|
678
678
|
count(params) {
|
|
679
679
|
return __awaiter(this, void 0, void 0, function* () {
|
|
680
680
|
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
681
|
-
const
|
|
681
|
+
const result = yield this.aggregateOfferModel.aggregate([
|
|
682
682
|
{
|
|
683
683
|
$unwind: { path: '$offers' }
|
|
684
684
|
},
|
|
@@ -688,7 +688,7 @@ class MongoRepository {
|
|
|
688
688
|
}
|
|
689
689
|
])
|
|
690
690
|
.exec();
|
|
691
|
-
return offerCount;
|
|
691
|
+
return (result.length > 0) ? result[0].offerCount : 0;
|
|
692
692
|
});
|
|
693
693
|
}
|
|
694
694
|
search(params, projection) {
|
|
@@ -176,35 +176,45 @@ class MongoRepository {
|
|
|
176
176
|
.exec();
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
optimizeAll() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
179
|
+
// /**
|
|
180
|
+
// * 型を統一する
|
|
181
|
+
// */
|
|
182
|
+
// public async optimizeAll(): Promise<void> {
|
|
183
|
+
// let result = await this.offerCatalogModel.updateMany(
|
|
184
|
+
// { typeOf: { $ne: 'OfferCatalog' } },
|
|
185
|
+
// { $set: { typeOf: 'OfferCatalog' } }
|
|
186
|
+
// )
|
|
187
|
+
// .exec();
|
|
188
|
+
// // tslint:disable-next-line:no-console
|
|
189
|
+
// console.log(result);
|
|
190
|
+
// result = await this.offerCatalogModel.updateMany(
|
|
191
|
+
// { ticketTypes: { $exists: true } },
|
|
192
|
+
// {
|
|
193
|
+
// $unset: { ticketTypes: 1 }
|
|
194
|
+
// }
|
|
195
|
+
// )
|
|
196
|
+
// .exec();
|
|
197
|
+
// // tslint:disable-next-line:no-console
|
|
198
|
+
// console.log(result);
|
|
199
|
+
// result = await this.offerCatalogModel.updateMany(
|
|
200
|
+
// { id: { $exists: true } },
|
|
201
|
+
// {
|
|
202
|
+
// $unset: { id: 1 }
|
|
203
|
+
// }
|
|
204
|
+
// )
|
|
205
|
+
// .exec();
|
|
206
|
+
// // tslint:disable-next-line:no-console
|
|
207
|
+
// console.log(result);
|
|
208
|
+
// result = await this.offerCatalogModel.updateMany(
|
|
209
|
+
// { 'itemOffered.serviceType': { $exists: true } },
|
|
210
|
+
// {
|
|
211
|
+
// $unset: { 'itemOffered.serviceType': 1 }
|
|
212
|
+
// }
|
|
213
|
+
// )
|
|
214
|
+
// .exec();
|
|
215
|
+
// // tslint:disable-next-line:no-console
|
|
216
|
+
// console.log(result);
|
|
217
|
+
// }
|
|
208
218
|
updateManyById(params) {
|
|
209
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
220
|
if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
|
|
@@ -27,6 +27,26 @@ export declare class MongoRepository {
|
|
|
27
27
|
id: string;
|
|
28
28
|
dateSynced: Date;
|
|
29
29
|
}): Promise<void>;
|
|
30
|
+
updateManyById(params: {
|
|
31
|
+
id: {
|
|
32
|
+
$in: string[];
|
|
33
|
+
};
|
|
34
|
+
$push: {
|
|
35
|
+
itemListElement: {
|
|
36
|
+
$each: factory.offerCatalog.IItemListElement[];
|
|
37
|
+
$slice: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
$pull: {
|
|
41
|
+
itemListElement: {
|
|
42
|
+
$elemMatch: {
|
|
43
|
+
id: {
|
|
44
|
+
$in: string[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}): Promise<void>;
|
|
30
50
|
count(params: Omit<factory.offerCatalog.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
|
|
31
51
|
search(params: factory.offerCatalog.ISearchConditions, projection: IProjection): Promise<IAggregatedOfferCatalog[]>;
|
|
32
52
|
findItemListElementById(params: {
|
|
@@ -147,6 +147,40 @@ class MongoRepository {
|
|
|
147
147
|
.exec();
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
+
updateManyById(params) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const pushItemListElementIds = params.$push.itemListElement.$each.map((element) => element.id);
|
|
156
|
+
yield this.offerCatalogItemModel.updateMany(Object.assign({ _id: { $in: params.id.$in } }, (pushItemListElementIds.length > 0)
|
|
157
|
+
// itemListElementのユニークネスを保証する
|
|
158
|
+
? {
|
|
159
|
+
'itemListElement.id': {
|
|
160
|
+
$nin: pushItemListElementIds
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
: undefined), Object.assign(Object.assign({}, (pushItemListElementIds.length > 0)
|
|
164
|
+
? {
|
|
165
|
+
$push: {
|
|
166
|
+
itemListElement: {
|
|
167
|
+
$each: params.$push.itemListElement.$each,
|
|
168
|
+
$slice: params.$push.itemListElement.$slice
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
: undefined), (params.$pull.itemListElement.$elemMatch.id.$in.length > 0)
|
|
173
|
+
? {
|
|
174
|
+
$pull: {
|
|
175
|
+
itemListElement: {
|
|
176
|
+
id: { $in: params.$pull.itemListElement.$elemMatch.id.$in }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
: undefined))
|
|
181
|
+
.exec();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
150
184
|
count(params) {
|
|
151
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
186
|
const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
package/package.json
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
// tslint:disable-next-line:max-func-body-length
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const cursor = offerCatalogRepo.getCursor(
|
|
15
|
-
{
|
|
16
|
-
// 'project.id': { $eq: project.id }
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
__v: 0,
|
|
20
|
-
createdAt: 0,
|
|
21
|
-
updatedAt: 0
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
console.log('catalogs found');
|
|
25
|
-
|
|
26
|
-
let i = 0;
|
|
27
|
-
let updateCount = 0;
|
|
28
|
-
await cursor.eachAsync(async (doc) => {
|
|
29
|
-
i += 1;
|
|
30
|
-
const { _id, ...offerCatalog } = <chevre.factory.offerCatalog.IOfferCatalog & { _id: string }>doc.toObject();
|
|
31
|
-
|
|
32
|
-
let itemListElementTypeOfEqOffer = false;
|
|
33
|
-
itemListElementTypeOfEqOffer = offerCatalog.itemListElement.every((element) => element.typeOf === chevre.factory.offerType.Offer);
|
|
34
|
-
if (!itemListElementTypeOfEqOffer) {
|
|
35
|
-
throw new Error(`itemListElementTypeOfEqOffer: false. ${offerCatalog.project.id} ${offerCatalog.id}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const itemOfferedKeys = Object.keys(offerCatalog.itemOffered);
|
|
39
|
-
console.log(itemOfferedKeys);
|
|
40
|
-
if (itemOfferedKeys.length > 1) {
|
|
41
|
-
console.log(itemOfferedKeys, offerCatalog.project.id, offerCatalog.id);
|
|
42
|
-
updateCount += 1;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
console.log(i, 'catalogs checked');
|
|
47
|
-
console.log(updateCount, 'catalogs synced');
|
|
48
|
-
|
|
49
|
-
await offerCatalogRepo.optimizeAll();
|
|
50
|
-
console.log('optmized');
|
|
51
|
-
}
|
|
52
|
-
main()
|
|
53
|
-
.then()
|
|
54
|
-
.catch(console.error);
|