Fixes
[vchess.git] / server / routes / problems.js
index c45a1ba..0208835 100644 (file)
@@ -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 || {});