From 1ef66c962a1cea81dee4f5db32cd011feac7de44 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 17 Jun 2018 08:10:54 +0900 Subject: reversi :white_flower: :100: --- src/server/api/endpoints/othello/games.ts | 62 ------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/server/api/endpoints/othello/games.ts (limited to 'src/server/api/endpoints/othello/games.ts') diff --git a/src/server/api/endpoints/othello/games.ts b/src/server/api/endpoints/othello/games.ts deleted file mode 100644 index 2320a34b04..0000000000 --- a/src/server/api/endpoints/othello/games.ts +++ /dev/null @@ -1,62 +0,0 @@ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import OthelloGame, { pack } from '../../../../models/othello-game'; - -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'my' parameter - const [my = false, myErr] = $.bool.optional().get(params.my); - if (myErr) return rej('invalid my param'); - - // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); - if (limitErr) return rej('invalid limit param'); - - // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); - if (sinceIdErr) return rej('invalid sinceId param'); - - // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); - if (untilIdErr) return rej('invalid untilId param'); - - // Check if both of sinceId and untilId is specified - if (sinceId && untilId) { - return rej('cannot set sinceId and untilId'); - } - - const q: any = my ? { - isStarted: true, - $or: [{ - user1Id: user._id - }, { - user2Id: user._id - }] - } : { - isStarted: true - }; - - const sort = { - _id: -1 - }; - - if (sinceId) { - sort._id = 1; - q._id = { - $gt: sinceId - }; - } else if (untilId) { - q._id = { - $lt: untilId - }; - } - - // Fetch games - const games = await OthelloGame.find(q, { - sort, - limit - }); - - // Reponse - res(Promise.all(games.map(async (g) => await pack(g, user, { - detail: false - })))); -}); -- cgit v1.2.3-freya