Skip to content

Commit

Permalink
feat: end game route
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinand11 committed Aug 24, 2023
1 parent 90ab27d commit 2bc3291
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions services/api/src/application/controllers/plays/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export class GameController {
throw new NotAuthorizedError()
}

static async end (req: Request) {
const ended = await GamesUseCases.end({ id: req.params.id, userId: req.authUser!.id })
if (ended) return ended
throw new NotAuthorizedError()
}

static async getQuestions (req: Request) {
const game = await GamesUseCases.find(req.params.id)
if (!game) throw new NotFoundError()
Expand Down
12 changes: 12 additions & 0 deletions services/api/src/application/routes/plays/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ export const gamesRoutes = groupRoutes('/games', [
}
})
]
}, {
path: '/:id/end',
method: 'post',
controllers: [
isAuthenticated,
makeController(async (req) => {
return {
status: StatusCodes.Ok,
result: await GameController.end(req)
}
})
]
}, {
path: '/:id/join',
method: 'post',
Expand Down

0 comments on commit 2bc3291

Please sign in to comment.