projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add Cannibal variant
[vchess.git]
/
server
/
routes
/
problems.js
diff --git
a/server/routes/problems.js
b/server/routes/problems.js
index
64c173a
..
8a82462
100644
(file)
--- a/
server/routes/problems.js
+++ b/
server/routes/problems.js
@@
-4,44
+4,39
@@
const ProblemModel = require("../models/Problem");
const sanitizeHtml = require('sanitize-html');
router.post("/problems", access.logged, access.ajax, (req,res) => {
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),
};
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
res.json({});
});
});
}
else
res.json({});
});
-router.get("/problems", (req,res) => {
+router.get("/problems",
access.ajax,
(req,res) => {
const probId = req.query["pid"];
const probId = req.query["pid"];
- if (probId && probId.match(/^[0-9]+$/))
- {
- ProblemModel.getOne(req.query["pid"], (err,problem) => {
+ const cursor = req.query["cursor"];
+
if (!!probId && !!probId.match(/^[0-9]+$/))
{
+ ProblemModel.getOne(req.query["pid"], (err,
problem) => {
res.json(err || {problem: problem});
});
res.json(err || {problem: problem});
});
- }
- else
- {
- ProblemModel.getAll((err,problems) => {
- res.json(err || {problems:problems});
+ } else if (!!cursor && !!cursor.match(/^[0-9]+$/)) {
+ ProblemModel.getNext(cursor, (err, problems) => {
+ res.json(err || { problems: problems });
});
}
});
router.put("/problems", access.logged, access.ajax, (req,res) => {
let obj = req.body.prob;
});
}
});
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);
obj.instruction = sanitizeHtml(obj.instruction);
obj.solution = sanitizeHtml(obj.solution);
ProblemModel.safeUpdate(obj, req.userId);