Refactor code
This commit is contained in:
@@ -19,16 +19,16 @@ export class GlobalConfigRouter extends PromiseRouter {
|
|||||||
|
|
||||||
updateGlobalConfig(req) {
|
updateGlobalConfig(req) {
|
||||||
const params = req.body.params;
|
const params = req.body.params;
|
||||||
const update = {};
|
const update = Object.keys(params).reduce((acc, key) => {
|
||||||
Object.keys(params).forEach((key) => {
|
|
||||||
if(params[key] && params[key].__op && params[key].__op === "Delete") {
|
if(params[key] && params[key].__op && params[key].__op === "Delete") {
|
||||||
if (!update.$unset) update.$unset = {};
|
if (!acc.$unset) acc.$unset = {};
|
||||||
update.$unset["params." + key] = "";
|
acc.$unset[`params.${key}`] = "";
|
||||||
} else {
|
} else {
|
||||||
if (!update.$set) update.$set = {};
|
if (!acc.$set) acc.$set = {};
|
||||||
update.$set["params." + key] = params[key];
|
acc.$set[`params.${key}`] = params[key];
|
||||||
}
|
}
|
||||||
});
|
return acc;
|
||||||
|
}, {});
|
||||||
return req.config.database.adaptiveCollection('_GlobalConfig')
|
return req.config.database.adaptiveCollection('_GlobalConfig')
|
||||||
.then(coll => coll.upsertOne({ _id: 1 }, update))
|
.then(coll => coll.upsertOne({ _id: 1 }, update))
|
||||||
.then(() => ({ response: { result: true } }));
|
.then(() => ({ response: { result: true } }));
|
||||||
|
|||||||
Reference in New Issue
Block a user