@chevre/domain 21.17.0-alpha.6 → 21.17.0-alpha.7
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.
|
@@ -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);
|