|
|
@@ -484,23 +484,28 @@ module.exports = (crowi) => {
|
|
|
* type: object
|
|
|
* description: editor settings
|
|
|
*/
|
|
|
- router.put('/editor-settings', accessTokenParser, loginRequiredStrictly, csrf, validator.editorSettings, apiV3FormValidator, async(req, res) => {
|
|
|
- try {
|
|
|
- const query = { userId: req.user.id };
|
|
|
- const textlintSettings = req.body?.textlintSettings;
|
|
|
- const update = {};
|
|
|
+ // router.put('/editor-settings', accessTokenParser, loginRequiredStrictly, csrf, validator.editorSettings, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.put('/editor-settings', accessTokenParser, loginRequiredStrictly, 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(update, { 'textlintSettings.isTextlintEnabled': textlintSettings.isTextlintEnabled });
|
|
|
- }
|
|
|
- if (textlintSettings?.textlintRules != null) {
|
|
|
- Object.assign(update, { 'textlintSettings.textlintRules': textlintSettings.textlintRules });
|
|
|
- }
|
|
|
+ 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 };
|
|
|
- const response = await EditorSettings.findOneAndUpdate(query, { $set: update }, options);
|
|
|
+ // 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 response = await EditorSettings.findOneAndUpdate(query, { $set: document }, options);
|
|
|
return res.apiv3(response);
|
|
|
}
|
|
|
catch (err) {
|