X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=routes%2Fproblems.js;fp=routes%2Fproblems.js;h=adb75dae5460e4c22cdb365852dab5f7f58d1598;hb=936dc463c969f648ae0bc81074ff3272c7c99697;hp=43258a0cb0b20eec57d174ea7220b7f725c49475;hpb=ae99d72ce4e0912f459b89059731563f5f20d34d;p=vchess.git diff --git a/routes/problems.js b/routes/problems.js index 43258a0c..adb75dae 100644 --- a/routes/problems.js +++ b/routes/problems.js @@ -6,18 +6,34 @@ const ProblemModel = require("../models/Problem"); const sanitizeHtml = require('sanitize-html'); const MaxNbProblems = 20; +// Get one problem +router.get("/problems/:vname([a-zA-Z0-9]+)/:pnum([0-9]+)", access.ajax, (req,res) => { + const vname = req.params["vname"]; + const pnum = req.params["pnum"]; + ProblemModel.getOne(vname, pnum, (err,problem) => { + if (!!err) + return res.json(err); + return res.json({problem: problem}); + }); +}); + // Fetch N previous or next problems router.get("/problems/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => { const vname = req.params["vname"]; const directionStr = (req.query.direction == "forward" ? ">" : "<"); const lastDt = req.query.last_dt; + const type = req.query.type; if (!lastDt.match(/[0-9]+/)) return res.json({errmsg: "Bad timestamp"}); - ProblemModel.fetchN(vname, directionStr, lastDt, MaxNbProblems, (err,problems) => { - if (!!err) - return res.json(err); - return res.json({problems: problems}); - }); + if (!["others","mine"].includes(type)) + return res.json({errmsg: "Bad type"}); + ProblemModel.fetchN(vname, req.userId, type, directionStr, lastDt, MaxNbProblems, + (err,problems) => { + if (!!err) + return res.json(err); + return res.json({problems: problems}); + } + ); }); function sanitizeUserInput(fen, instructions, solution)