improve id checks for getting finished games
This commit is contained in:
@@ -11,7 +11,7 @@ export const getGames = async (req: Request, res: Response) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.query.id) {
|
if (req.query.id && Number.isFinite(req.query.id)) {
|
||||||
// get finished game by id
|
// get finished game by id
|
||||||
const game = await GameModel.findById(parseInt(req.query.id as string));
|
const game = await GameModel.findById(parseInt(req.query.id as string));
|
||||||
if (!game) {
|
if (!game) {
|
||||||
@@ -19,7 +19,7 @@ export const getGames = async (req: Request, res: Response) => {
|
|||||||
} else {
|
} else {
|
||||||
res.status(200).json(game);
|
res.status(200).json(game);
|
||||||
}
|
}
|
||||||
} else if (req.query.userid) {
|
} else if (req.query.userid && Number.isFinite(req.query.userid)) {
|
||||||
// get finished games by user id
|
// get finished games by user id
|
||||||
const games = await GameModel.findByUserId(parseInt(req.query.userid as string));
|
const games = await GameModel.findByUserId(parseInt(req.query.userid as string));
|
||||||
if (!games) {
|
if (!games) {
|
||||||
|
|||||||
Reference in New Issue
Block a user