@chevre/domain 20.3.0-alpha.1 → 20.3.0-alpha.2
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.
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
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 offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
await offerCatalogRepo.updateManyById({
|
|
12
|
+
id: { $in: ['0002'] },
|
|
13
|
+
$pull: {
|
|
14
|
+
itemListElement: {
|
|
15
|
+
$elemMatch: {
|
|
16
|
+
id: {
|
|
17
|
+
$in: [
|
|
18
|
+
// 'al96nqj7z',
|
|
19
|
+
// 'akxecjgeu'
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
$push: {
|
|
26
|
+
itemListElement: {
|
|
27
|
+
$each: [
|
|
28
|
+
{ typeOf: chevre.factory.offerType.Offer, id: 'al96nqj7z' },
|
|
29
|
+
{ typeOf: chevre.factory.offerType.Offer, id: 'akxecjgeu' }
|
|
30
|
+
],
|
|
31
|
+
$slice: 200
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
console.log('updated');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
main()
|
|
39
|
+
.then(console.log)
|
|
40
|
+
.catch(console.error);
|
|
@@ -8,6 +8,26 @@ export declare class MongoRepository {
|
|
|
8
8
|
constructor(connection: Connection);
|
|
9
9
|
static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
|
|
10
10
|
save(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
|
|
11
|
+
updateManyById(params: {
|
|
12
|
+
id: {
|
|
13
|
+
$in: string[];
|
|
14
|
+
};
|
|
15
|
+
$push: {
|
|
16
|
+
itemListElement: {
|
|
17
|
+
$each: factory.offerCatalog.IItemListElement[];
|
|
18
|
+
$slice: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
$pull: {
|
|
22
|
+
itemListElement: {
|
|
23
|
+
$elemMatch: {
|
|
24
|
+
id: {
|
|
25
|
+
$in: string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}): Promise<void>;
|
|
11
31
|
findById(params: {
|
|
12
32
|
id: string;
|
|
13
33
|
}): Promise<factory.offerCatalog.IOfferCatalog>;
|
|
@@ -144,6 +144,40 @@ class MongoRepository {
|
|
|
144
144
|
return doc.toObject();
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
+
updateManyById(params) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const pushItemListElementIds = params.$push.itemListElement.$each.map((element) => element.id);
|
|
153
|
+
yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in } }, (pushItemListElementIds.length > 0)
|
|
154
|
+
// itemListElementのユニークネスを保証する
|
|
155
|
+
? {
|
|
156
|
+
'itemListElement.id': {
|
|
157
|
+
$nin: pushItemListElementIds
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
: undefined), Object.assign(Object.assign({}, (pushItemListElementIds.length > 0)
|
|
161
|
+
? {
|
|
162
|
+
$push: {
|
|
163
|
+
itemListElement: {
|
|
164
|
+
$each: params.$push.itemListElement.$each,
|
|
165
|
+
$slice: params.$push.itemListElement.$slice
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
: undefined), (params.$pull.itemListElement.$elemMatch.id.$in.length > 0)
|
|
170
|
+
? {
|
|
171
|
+
$pull: {
|
|
172
|
+
itemListElement: {
|
|
173
|
+
id: { $in: params.$pull.itemListElement.$elemMatch.id.$in }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
: undefined))
|
|
178
|
+
.exec();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
147
181
|
findById(params) {
|
|
148
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
183
|
const doc = yield this.offerCatalogModel.findOne({
|
package/package.json
CHANGED