mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 10:17:30 +08:00
parent
08103327dc
commit
bd2d82e681
2 changed files with 14 additions and 18 deletions
|
|
@ -3,24 +3,16 @@ const { validateConfig } = require("../../handlers/validation");
|
|||
|
||||
class ConfigController {
|
||||
static async getConfig(req, res, next) {
|
||||
try {
|
||||
const { uid } = req.decodedToken;
|
||||
let config = await ConfigDAO.getConfig(uid);
|
||||
return res.status(200).json(config);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
const { uid } = req.decodedToken;
|
||||
let config = await ConfigDAO.getConfig(uid);
|
||||
return res.status(200).json(config);
|
||||
}
|
||||
static async saveConfig(req, res, next) {
|
||||
try {
|
||||
const { config } = req.body;
|
||||
const { uid } = req.decodedToken;
|
||||
validateConfig(config);
|
||||
await ConfigDAO.saveConfig(uid, config);
|
||||
return res.sendStatus(200);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
const { config } = req.body;
|
||||
const { uid } = req.decodedToken;
|
||||
validateConfig(config);
|
||||
await ConfigDAO.saveConfig(uid, config);
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ const { authenticateRequest } = require("../../middlewares/auth");
|
|||
const { Router } = require("express");
|
||||
const ConfigController = require("../controllers/config");
|
||||
const RateLimit = require("../../middlewares/rate-limit");
|
||||
const {
|
||||
asyncHandlerWrapper,
|
||||
requestValidation,
|
||||
} = require("../../middlewares/api-utils");
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
|
@ -9,14 +13,14 @@ router.get(
|
|||
"/",
|
||||
RateLimit.configGet,
|
||||
authenticateRequest,
|
||||
ConfigController.getConfig
|
||||
asyncHandlerWrapper(ConfigController.getConfig)
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/save",
|
||||
RateLimit.configUpdate,
|
||||
authenticateRequest,
|
||||
ConfigController.saveConfig
|
||||
asyncHandlerWrapper(ConfigController.saveConfig)
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue