summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/othello/games.ts6
-rw-r--r--src/api/endpoints/othello/games/show.ts16
2 files changed, 19 insertions, 3 deletions
diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts
index dd3ee523a8..2a6bbb4043 100644
--- a/src/api/endpoints/othello/games.ts
+++ b/src/api/endpoints/othello/games.ts
@@ -23,7 +23,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('cannot set since_id and until_id');
}
- const q = my ? {
+ const q: any = my ? {
is_started: true,
$or: [{
user1_id: user._id
@@ -34,7 +34,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
is_started: true
};
-
const sort = {
_id: -1
};
@@ -52,7 +51,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Fetch games
const games = await Game.find(q, {
- sort
+ sort,
+ limit
});
// Reponse
diff --git a/src/api/endpoints/othello/games/show.ts b/src/api/endpoints/othello/games/show.ts
new file mode 100644
index 0000000000..9dc8f24900
--- /dev/null
+++ b/src/api/endpoints/othello/games/show.ts
@@ -0,0 +1,16 @@
+import $ from 'cafy';
+import Game, { pack } from '../../../models/othello-game';
+
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'game_id' parameter
+ const [gameId, gameIdErr] = $(params.game_id).id().$;
+ if (gameIdErr) return rej('invalid game_id param');
+
+ const game = await Game.findOne({ _id: gameId });
+
+ if (game == null) {
+ return rej('game not found');
+ }
+
+ res(await pack(game, user));
+});