Feat : add Prepare token

This commit is contained in:
2024-07-13 16:49:31 +02:00
parent 2e0485cc87
commit 8ca627a047
5 changed files with 203 additions and 8 deletions
+7 -5
View File
@@ -24,17 +24,19 @@ export function getPlayer(session: Record<string, any>, game: Game) {
if (!user) {
throw new HttpException('Please log in', HttpStatus.UNAUTHORIZED);
}
return findPlayer(user._id, game);
}
export function findPlayer(playerId: string, game: Game) {
for (const team of game.teams) {
for (const player of team.players) {
if (player.user._id.equals(user._id)) {
if (player.user._id.equals(playerId)) {
return player as Document<Player> & Player;
}
}
}
throw new HttpException(
'You are not part of this game',
HttpStatus.FORBIDDEN,
);
throw new HttpException('Player not found in game', HttpStatus.FORBIDDEN);
}
export function isInTeam(team: Team, player: Player) {