-router.post("/problems", access.logged, access.ajax, (req,res) => {
- const error = ProblemModel.checkProblem(req.body.prob);
- if (!!error)
- return res.json({errmsg:error});
- 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) => {
- return res.json(err || {pid:ret.pid});
- });
+router.get("/problems", access.ajax, (req,res) => {
+ const probId = req.query["id"];
+ const cursor = req.query["cursor"];
+ if (!!probId && !!probId.match(/^[0-9]+$/)) {
+ ProblemModel.getOne(probId, (err, problem) => {
+ res.json(err || {problem: problem});
+ });
+ } else if (!!cursor && !!cursor.match(/^[0-9]+$/)) {
+ const onlyMine = (req.query["mode"] == "mine");
+ const uid = parseInt(req.query["uid"]);
+ ProblemModel.getNext(uid, onlyMine, cursor, (err, problems) => {
+ res.json(err || { problems: problems });
+ });
+ }