-// Get one problem (TODO: vid unused, here for URL de-ambiguification)
-router.get("/problems/:vid([0-9]+)/:id([0-9]+)", access.ajax, (req,res) => {
- const pid = req.params["id"];
- ProblemModel.getOne(pid, (err,problem) => {
- if (!!err)
- return res.json(err);
- return res.json({problem: problem});
- });
-});
-
-// Fetch N previous or next problems
-router.get("/problems/:vid([0-9]+)", access.ajax, (req,res) => {
- const vid = req.params["vid"];
- 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"});
- if (!["others","mine"].includes(type))
- return res.json({errmsg: "Bad type"});
- ProblemModel.fetchN(vid, req.userId, type, directionStr, lastDt, MaxNbProblems,
- (err,problems) => {
- if (!!err)
- return res.json(err);
- return res.json({problems: problems});
- }
- );
+router.post("/problems", access.logged, access.ajax, (req,res) => {
+ 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 || ret);
+ });
+ }
+ else
+ res.json({});