X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=server%2Froutes%2Fgames.js;h=73a8bf70b2fd3bcf507d0730350d6aa7896da058;hp=24e97471c2a507a67d86e9472f6b19e43ea67539;hb=3d55deea9a2011c38d8d0067bd57fc889958bec2;hpb=dce792f64ab0a311d348a6eb05c440dd1b170bd3 diff --git a/server/routes/games.js b/server/routes/games.js index 24e97471..73a8bf70 100644 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -51,35 +51,17 @@ router.get("/games", access.ajax, (req,res) => { } }); -////////////////////////////////// - -// TODO: new move -router.put("/games", access.logged, access.ajax, (req,res) => { - let gid = ObjectId(req.body.gid); - let result = req.body.result; - // NOTE: only game-level life update is "gameover" - GameModel.gameOver(gid, result, ObjectId(req.userId), (err,game) => { - access.checkRequest(res, err, game, "Cannot find game", () => { - res.json({}); - }); - }); -}); - +// New move + fen update + score, potentially // TODO: if newmove fail, takeback in GUI -// TODO: check move structure -// TODO: move should contain an optional "message" field ("corr chat" !) -router.post("/moves", access.logged, access.ajax, (req,res) => { - let gid = ObjectId(req.body.gid); - let fen = req.body.fen; - let vname = req.body.vname; //defined only if !!offlineOpp - // NOTE: storing the moves encoded lead to double stringify --> error at parsing - let move = JSON.parse(req.body.move); - GameModel.addMove(gid, move, fen, req._user._id, (err,game) => { - access.checkRequest(res, err, game, "Cannot find game", () => { - if (!!req.body.offlineOpp) - UserModel.tryNotify(ObjectId(req.body.offlineOpp), gid, vname, "New move"); - res.json({}); - }); +router.put("/games", access.logged, access.ajax, (req,res) => { + const gid = req.body.gid; + const obj = req.body.newObj; + GameModel.update(gid, obj, (err) => { + if (!!err) + return res.json(err); + if (!!req.body.offlineOpp) //TODO: refresh this... + UserModel.tryNotify(req.body.offlineOpp, "New move in game " + gid); + res.json({}); }); });