Convert all remaining tabs by 2spaces
[vchess.git] / server / routes / games.js
index e9d9ab4..24bfc82 100644 (file)
@@ -9,10 +9,10 @@ var params = require("../config/parameters");
 // From main hall, start game between players 0 and 1
 router.post("/games", access.logged, access.ajax, (req,res) => {
   const gameInfo = req.body.gameInfo;
-       if (!Array.isArray(gameInfo.players) ||
+  if (!Array.isArray(gameInfo.players) ||
     !gameInfo.players.some(p => p.id == req.userId))
   {
-               return res.json({errmsg: "Cannot start someone else's game"});
+    return res.json({errmsg: "Cannot start someone else's game"});
   }
   const cid = req.body.cid;
   // Check all entries of gameInfo + cid:
@@ -25,29 +25,29 @@ router.post("/games", access.logged, access.ajax, (req,res) => {
   if (!!error)
     return res.json({errmsg:error});
   ChallengeModel.remove(cid);
-       GameModel.create(
+  GameModel.create(
     gameInfo.vid, gameInfo.fen, gameInfo.timeControl, gameInfo.players,
-               (err,ret) => {
-                       access.checkRequest(res, err, ret, "Cannot create game", () => {
+    (err,ret) => {
+      access.checkRequest(res, err, ret, "Cannot create game", () => {
         const oppIdx = (gameInfo.players[0].id == req.userId ? 1 : 0);
         const oppId = gameInfo.players[oppIdx].id;
         UserModel.tryNotify(oppId,
           "New game: " + params.siteURL + "/game/" + ret.gid);
-                               res.json({gameId: ret.gid});
-                       });
-               }
-       );
+        res.json({gameId: ret.gid});
+      });
+    }
+  );
 });
 
 router.get("/games", access.ajax, (req,res) => {
-       const gameId = req.query["gid"];
-       if (!!gameId)
+  const gameId = req.query["gid"];
+  if (!!gameId)
   {
     GameModel.getOne(gameId, (err,game) => {
-                 access.checkRequest(res, err, game, "Game not found", () => {
+      access.checkRequest(res, err, game, "Game not found", () => {
         res.json({game: game});
-                 });
-         });
+      });
+    });
   }
   else
   {
@@ -55,10 +55,10 @@ router.get("/games", access.ajax, (req,res) => {
     const userId = req.query["uid"];
     const excluded = !!req.query["excluded"];
     GameModel.getByUser(userId, excluded, (err,games) => {
-                       if (!!err)
+      if (!!err)
         return res.json({errmsg: err.errmsg || err.toString()});
-                       res.json({games: games});
-         });
+      res.json({games: games});
+    });
   }
 });
 
@@ -70,11 +70,11 @@ router.put("/games", access.logged, access.ajax, (req,res) => {
   if (!gid.toString().match(/^[0-9]+$/))
     error = "Wrong game ID";
   const obj = req.body.newObj;
-       error = GameModel.checkGameUpdate(obj);
+  error = GameModel.checkGameUpdate(obj);
   if (!!error)
     return res.json({errmsg: error});
-       GameModel.update(gid, obj, (err) => {
-               if (!!err)
+  GameModel.update(gid, obj, (err) => {
+    if (!!err)
       return res.json(err);
     // Notify opponent if he enabled notifications:
     GameModel.getPlayers(gid, (err2,players) => {
@@ -85,7 +85,7 @@ router.put("/games", access.logged, access.ajax, (req,res) => {
         "New move in game: " + params.siteURL + "/game/" + gid);
     });
     res.json({});
-       });
+  });
 });
 
 module.exports = router;