This commit is contained in:
@@ -77,7 +77,7 @@ export class GamesController {
|
|||||||
await this.gameService.endTurn(game);
|
await this.gameService.endTurn(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':id/leave')
|
@Post('leave')
|
||||||
@ApiOperation({ summary: "Leave a game that hasn't already started" })
|
@ApiOperation({ summary: "Leave a game that hasn't already started" })
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
async leave(
|
async leave(
|
||||||
@@ -91,7 +91,21 @@ export class GamesController {
|
|||||||
return await this.gameService.leaveGame(game, session.user);
|
return await this.gameService.leaveGame(game, session.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':id/kick/:playerId')
|
@Post('surrender')
|
||||||
|
@ApiOperation({ summary: "Leave a game that hasn't already started" })
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
async surrender(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Session() session: Record<string, any>,
|
||||||
|
@Param('id', GamePipe) game: Document<Game> & Game,
|
||||||
|
) {
|
||||||
|
if (!game.started) {
|
||||||
|
throw new HttpException('Game has not started', HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
return await this.gameService.leaveGame(game, session.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('kick/:playerId')
|
||||||
@ApiOperation({ summary: 'Kick a player' })
|
@ApiOperation({ summary: 'Kick a player' })
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
async kick(
|
async kick(
|
||||||
@@ -100,9 +114,6 @@ export class GamesController {
|
|||||||
@Param('id', GamePipe) game: Document<Game> & Game,
|
@Param('id', GamePipe) game: Document<Game> & Game,
|
||||||
@Param('playerId') playerId: string,
|
@Param('playerId') playerId: string,
|
||||||
) {
|
) {
|
||||||
if (game.started) {
|
|
||||||
throw new HttpException('Game already started', HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
if (session.user.userId != game.owner.userId) {
|
if (session.user.userId != game.owner.userId) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'You do do not own this game',
|
'You do do not own this game',
|
||||||
|
|||||||
@@ -289,7 +289,9 @@ export class GameService {
|
|||||||
await game.save({ session });
|
await game.save({ session });
|
||||||
if (game.teams.length <= 1) {
|
if (game.teams.length <= 1) {
|
||||||
await this.endGame(game, session);
|
await this.endGame(game, session);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithTransaction
|
@WithTransaction
|
||||||
@@ -340,12 +342,18 @@ export class GameService {
|
|||||||
team: new ReadTeamDto(team),
|
team: new ReadTeamDto(team),
|
||||||
playerId: kickedPlayerId,
|
playerId: kickedPlayerId,
|
||||||
});
|
});
|
||||||
|
let gameExists = true;
|
||||||
if (team.players.length == 0) {
|
if (team.players.length == 0) {
|
||||||
const teamIndex = game.teams.indexOf(team);
|
if (!game.started) {
|
||||||
game.teams.splice(teamIndex, 1);
|
const teamIndex = game.teams.indexOf(team);
|
||||||
|
game.teams.splice(teamIndex, 1);
|
||||||
|
} else {
|
||||||
|
gameExists = await this.killTeam(game, team, session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gameExists) {
|
||||||
|
await game.save({ session });
|
||||||
}
|
}
|
||||||
|
|
||||||
await game.save({ session });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithTransaction
|
@WithTransaction
|
||||||
|
|||||||
Reference in New Issue
Block a user