X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Froutes%2Fproblems.js;h=02088357c30a0bfc637141cffd6749f0e792f5ef;hb=bd76b45611cbb58dcf774745a4d690277a82aacd;hp=c45a1baccd43f0aa5925d4bfb8c65393d76d382d;hpb=89021f181ac0689bbc785ce0ebd9a910e66352b0;p=vchess.git diff --git a/server/routes/problems.js b/server/routes/problems.js index c45a1bac..02088357 100644 --- a/server/routes/problems.js +++ b/server/routes/problems.js @@ -38,29 +38,25 @@ router.post("/problems", access.logged, access.ajax, (req,res) => { solution: sanitizeHtml(req.body.prob.solution), }; ProblemModel.create(problem, (err,ret) => { - return res.json(err || {pid:ret.pid}); + return res.json(err || {id:ret.pid}); }); }); router.put("/problems", access.logged, access.ajax, (req,res) => { - const pid = req.body.pid; - let error = ""; - if (!pid.toString().match(/^[0-9]+$/)) - error = "Wrong problem ID"; - let obj = req.body.newProb; - error = ProblemModel.checkProblem(obj); - obj.instruction = sanitizeHtml(obj.instruction); - obj.solution = sanitizeHtml(obj.solution); + let obj = req.body.prob; + const error = ProblemModel.checkProblem(obj); if (!!error) return res.json({errmsg: error}); - ProblemModel.update(pid, obj, (err) => { + obj.instruction = sanitizeHtml(obj.instruction); + obj.solution = sanitizeHtml(obj.solution); + ProblemModel.update(obj, (err) => { res.json(err || {}); }); }); router.delete("/problems", access.logged, access.ajax, (req,res) => { const pid = req.query.id; - if (!pid.match(/^[0-9]+$/)) + if (!pid.toString().match(/^[0-9]+$/)) res.json({errmsg: "Bad problem ID"}); ProblemModel.safeRemove(pid, req.userId, err => { res.json(err || {});