X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Froutes%2Fproblems.js;h=6cebb8f0ebee43805e466f8d34e5d0b289a5a36d;hp=732ea7109064d9fee4a367bd76c408217f03b4c1;hb=0234201fb338fc239d6f613c677fa932c7c3697c;hpb=585d095517ca2aedab8ad125cc7c39b90e13d5cc diff --git a/server/routes/problems.js b/server/routes/problems.js index 732ea710..6cebb8f0 100644 --- a/server/routes/problems.js +++ b/server/routes/problems.js @@ -4,18 +4,16 @@ const ProblemModel = require("../models/Problem"); const sanitizeHtml = require('sanitize-html'); router.post("/problems", access.logged, access.ajax, (req,res) => { - if (ProblemModel.checkProblem(req.body.prob)) - { - const problem = - { + if (ProblemModel.checkProblem(req.body.prob)) { + const problem = { vid: req.body.prob.vid, fen: req.body.prob.fen, uid: req.userId, instruction: sanitizeHtml(req.body.prob.instruction), solution: sanitizeHtml(req.body.prob.solution), }; - ProblemModel.create(problem, (err,ret) => { - res.json(err || {id:ret.pid}); + ProblemModel.create(problem, (err, ret) => { + res.json(err || ret); }); } else @@ -24,24 +22,20 @@ router.post("/problems", access.logged, access.ajax, (req,res) => { router.get("/problems", access.ajax, (req,res) => { const probId = req.query["pid"]; - if (probId && probId.match(/^[0-9]+$/)) - { + if (probId && probId.match(/^[0-9]+$/)) { ProblemModel.getOne(req.query["pid"], (err,problem) => { res.json(err || {problem: problem}); }); - } - else - { + } else { ProblemModel.getAll((err,problems) => { - res.json(err || {problems:problems}); + res.json(err || { problems: problems }); }); } }); router.put("/problems", access.logged, access.ajax, (req,res) => { let obj = req.body.prob; - if (ProblemModel.checkProblem(obj)) - { + if (ProblemModel.checkProblem(obj)) { obj.instruction = sanitizeHtml(obj.instruction); obj.solution = sanitizeHtml(obj.solution); ProblemModel.safeUpdate(obj, req.userId);