Feat : add Prepare token
This commit is contained in:
+7
-5
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user