|
|
@@ -485,13 +485,26 @@ module.exports = (crowi) => {
|
|
|
* description: editor settings
|
|
|
*/
|
|
|
router.put('/editor-settings', accessTokenParser, loginRequiredStrictly, csrf, validator.editorSettings, apiV3FormValidator, async(req, res) => {
|
|
|
+ const query = { userId: req.user.id };
|
|
|
+ const textlintSettings = req.body.textlintSettings;
|
|
|
+ const document = {};
|
|
|
+
|
|
|
+ if (textlintSettings == null) {
|
|
|
+ return res.apiv3Err('no-settings-found');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (textlintSettings.isTextlintEnabled != null) {
|
|
|
+ Object.assign(document, { 'textlintSettings.isTextlintEnabled': textlintSettings.isTextlintEnabled });
|
|
|
+ }
|
|
|
+ if (textlintSettings.textlintRules != null) {
|
|
|
+ Object.assign(document, { 'textlintSettings.textlintRules': textlintSettings.textlintRules });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Insert if document does not exist, and return new values
|
|
|
+ // See: https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
|
+ const options = { upsert: true, new: true };
|
|
|
try {
|
|
|
- const query = { userId: req.user.id };
|
|
|
- const update = req.body;
|
|
|
- // Insert if document does not exist, and return new values
|
|
|
- // See: https://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate
|
|
|
- const options = { upsert: true, new: true };
|
|
|
- const response = await EditorSettings.findOneAndUpdate(query, update, options);
|
|
|
+ const response = await EditorSettings.findOneAndUpdate(query, { $set: document }, options);
|
|
|
return res.apiv3(response);
|
|
|
}
|
|
|
catch (err) {
|