@chevre/domain 20.4.0-alpha.4 → 20.4.0-alpha.5
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/unsetUnnecessaryFields.ts +26 -0
- package/lib/chevre/repo/account.d.ts +4 -0
- package/lib/chevre/repo/account.js +6 -0
- package/lib/chevre/repo/event.js +4 -13
- package/lib/chevre/repo/serviceOutput.d.ts +4 -0
- package/lib/chevre/repo/serviceOutput.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
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 accountRepo = new chevre.repository.Account(mongoose.connection);
|
|
10
|
+
const permitRepo = new chevre.repository.ServiceOutput(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
let updateResult = await accountRepo.unsetUnnecessaryFields({
|
|
13
|
+
filter: { status: { $exists: true } },
|
|
14
|
+
$unset: { status: 1 }
|
|
15
|
+
});
|
|
16
|
+
console.log('accounts unset.', updateResult);
|
|
17
|
+
updateResult = await permitRepo.unsetUnnecessaryFields({
|
|
18
|
+
filter: { 'paymentAccount.accountType': { $exists: true } },
|
|
19
|
+
$unset: { 'paymentAccount.accountType': 1 }
|
|
20
|
+
});
|
|
21
|
+
console.log('permits unset', updateResult);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
main()
|
|
25
|
+
.then()
|
|
26
|
+
.catch(console.error);
|
|
@@ -124,4 +124,8 @@ export declare class MongoRepository {
|
|
|
124
124
|
* 口座を検索する
|
|
125
125
|
*/
|
|
126
126
|
search(params: factory.account.ISearchConditions): Promise<factory.account.IAccount[]>;
|
|
127
|
+
unsetUnnecessaryFields(params: {
|
|
128
|
+
filter: any;
|
|
129
|
+
$unset: any;
|
|
130
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
127
131
|
}
|
|
@@ -425,5 +425,11 @@ class MongoRepository {
|
|
|
425
425
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
unsetUnnecessaryFields(params) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
return this.accountModel.updateMany(params.filter, { $unset: params.$unset })
|
|
431
|
+
.exec();
|
|
432
|
+
});
|
|
433
|
+
}
|
|
428
434
|
}
|
|
429
435
|
exports.MongoRepository = MongoRepository;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -473,11 +473,11 @@ class MongoRepository {
|
|
|
473
473
|
if (typeof additionalPropertyValue !== 'string') {
|
|
474
474
|
throw new factory.errors.NotFound('additionalProperty.value');
|
|
475
475
|
}
|
|
476
|
-
const _c = creatingEventParams.attributes, {
|
|
476
|
+
const _c = creatingEventParams.attributes, { eventStatus } = _c, setOnInsertFields = __rest(_c, ["eventStatus"]);
|
|
477
477
|
bulkWriteOps.push({
|
|
478
478
|
updateOne: {
|
|
479
479
|
filter: {
|
|
480
|
-
typeOf,
|
|
480
|
+
typeOf: creatingEventParams.attributes.typeOf,
|
|
481
481
|
// 追加特性をキーに更新
|
|
482
482
|
additionalProperty: {
|
|
483
483
|
$exists: true,
|
|
@@ -485,18 +485,9 @@ class MongoRepository {
|
|
|
485
485
|
}
|
|
486
486
|
},
|
|
487
487
|
update: {
|
|
488
|
-
$setOnInsert: {
|
|
489
|
-
_id: uniqid(),
|
|
490
|
-
typeOf,
|
|
491
|
-
project,
|
|
492
|
-
superEvent,
|
|
493
|
-
workPerformed,
|
|
494
|
-
location,
|
|
495
|
-
name
|
|
496
|
-
// ...creatingEventParams.attributes
|
|
497
|
-
},
|
|
488
|
+
$setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() }),
|
|
498
489
|
// 変更可能な属性のみ上書き
|
|
499
|
-
$set:
|
|
490
|
+
$set: { eventStatus }
|
|
500
491
|
},
|
|
501
492
|
upsert: true
|
|
502
493
|
}
|
|
@@ -169,5 +169,11 @@ class MongoRepository {
|
|
|
169
169
|
.exec();
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
+
unsetUnnecessaryFields(params) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
return this.serviceOutputModel.updateMany(params.filter, { $unset: params.$unset })
|
|
175
|
+
.exec();
|
|
176
|
+
});
|
|
177
|
+
}
|
|
172
178
|
}
|
|
173
179
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED