Skip to content

Commit 236c7d1

Browse files
committed
Refactor code
1 parent 6b9fd16 commit 236c7d1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Routers/GlobalConfigRouter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ export class GlobalConfigRouter extends PromiseRouter {
1919

2020
updateGlobalConfig(req) {
2121
const params = req.body.params;
22-
const update = {};
23-
Object.keys(params).forEach((key) => {
22+
const update = Object.keys(params).reduce((acc, key) => {
2423
if(params[key] && params[key].__op && params[key].__op === "Delete") {
25-
if (!update.$unset) update.$unset = {};
26-
update.$unset["params." + key] = "";
24+
if (!acc.$unset) acc.$unset = {};
25+
acc.$unset[`params.${key}`] = "";
2726
} else {
28-
if (!update.$set) update.$set = {};
29-
update.$set["params." + key] = params[key];
27+
if (!acc.$set) acc.$set = {};
28+
acc.$set[`params.${key}`] = params[key];
3029
}
31-
});
30+
return acc;
31+
}, {});
3232
return req.config.database.adaptiveCollection('_GlobalConfig')
3333
.then(coll => coll.upsertOne({ _id: 1 }, update))
3434
.then(() => ({ response: { result: true } }));

0 commit comments

Comments
 (0)