Added merging in Config with scoped set
This commit is contained in:
@@ -18,20 +18,20 @@ export class GlobalConfigRouter extends PromiseRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateGlobalConfig(req) {
|
updateGlobalConfig(req) {
|
||||||
|
const params = req.body.params;
|
||||||
|
const update = {};
|
||||||
|
Object.keys(params).forEach((key) => {
|
||||||
|
if(params[key] && params[key].__op && params[key].__op === "Delete") {
|
||||||
|
if (!update.$unset) update.$unset = {};
|
||||||
|
update.$unset["params." + key] = "";
|
||||||
|
} else {
|
||||||
|
if (!update.$set) update.$set = {};
|
||||||
|
update.$set["params." + key] = params[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
return req.config.database.adaptiveCollection('_GlobalConfig')
|
return req.config.database.adaptiveCollection('_GlobalConfig')
|
||||||
.then(coll => coll.find({ '_id': 1 }, { limit: 1 }))
|
.then(coll => coll.upsertOne({ _id: 1 }, update))
|
||||||
.then(results => {
|
.then(() => ({ response: { result: true } }));
|
||||||
const previousConfig = results && results[0] && results[0].params || {};
|
|
||||||
const newConfig = Object.assign({}, previousConfig, req.body.params);
|
|
||||||
for (var key in newConfig) {
|
|
||||||
if (newConfig[key] && newConfig[key].__op && newConfig[key].__op === "Delete") {
|
|
||||||
delete newConfig[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return req.config.database.adaptiveCollection('_GlobalConfig')
|
|
||||||
.then(coll => coll.upsertOne({ _id: 1 }, { $set: { params: newConfig } }))
|
|
||||||
.then(() => ({ response: { result: true } }));
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mountRoutes() {
|
mountRoutes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user