Ver código fonte

Merge pull request #4195 from weseek/feat/6987-editor-current-settings-endpoint

Feat/6987 editor current settings endpoint
stevenfukase 4 anos atrás
pai
commit
702d070c20

+ 1 - 1
packages/app/src/server/models/user.js

@@ -36,7 +36,7 @@ module.exports = function(crowi) {
   }
   }
 
 
   const editorCurrentSettingsSchema = new mongoose.Schema({
   const editorCurrentSettingsSchema = new mongoose.Schema({
-    isTextLintEnable: { type: Boolean, default: true },
+    isTextlintEnabled: { type: Boolean, default: true },
   });
   });
 
 
   const userSchema = new mongoose.Schema({
   const userSchema = new mongoose.Schema({

+ 37 - 1
packages/app/src/server/routes/apiv3/personal-setting.js

@@ -15,7 +15,7 @@ const router = express.Router();
 /**
 /**
  * @swagger
  * @swagger
  *  tags:
  *  tags:
- *    name: PsersonalSetting
+ *    name: PersonalSetting
  */
  */
 
 
 /**
 /**
@@ -98,6 +98,9 @@ module.exports = (crowi) => {
       body('providerType').isString().not().isEmpty(),
       body('providerType').isString().not().isEmpty(),
       body('accountId').isString().not().isEmpty(),
       body('accountId').isString().not().isEmpty(),
     ],
     ],
+    editorSettings: [
+      body('isTextlintEnabled').isBoolean(),
+    ],
   };
   };
 
 
   /**
   /**
@@ -459,5 +462,38 @@ module.exports = (crowi) => {
 
 
   });
   });
 
 
+  /**
+   * @swagger
+   *
+   *    /personal-setting:
+   *      put:
+   *        tags: [PersonalSetting]
+   *        operationId: putEditorSettings
+   *        summary: /personal-setting
+   *        description: Change editor preferences
+   *        responses:
+   *          200:
+   *            description: params of personal info
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    currentUser:
+   *                      type: object
+   *                      description: personal params
+   */
+  router.put('/editor-settings', accessTokenParser, loginRequiredStrictly, csrf, validator.editorSettings, apiV3FormValidator, async(req, res) => {
+    try {
+      const user = await User.findOne({ _id: req.user.id });
+      user.editorCurrentSettings = req.body;
+      const { editorCurrentSettings } = await user.save();
+      return res.apiv3({ editorCurrentSettings });
+    }
+    catch (err) {
+      logger.error(err);
+      return res.apiv3Err('updating-editor-settings-failed');
+    }
+  });
+
   return router;
   return router;
 };
 };