This commit is contained in:
@@ -14,13 +14,15 @@ import { AuthGuard } from '../guards/auth.guard';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { StartingDeckDto } from '../dto/update-game.dto';
|
||||
import { Game } from '../schemas/game.schema';
|
||||
import { Document } from 'mongoose';
|
||||
import mongoose, { Document } from 'mongoose';
|
||||
import { GamePipe, GameStartedPipe } from '../pipe/game.pipe';
|
||||
|
||||
import { Observable, fromEvent, map } from 'rxjs';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { GameService } from '../services/games.service';
|
||||
import { getCurrentTeam, getPlayer, isInTeam } from '../utils';
|
||||
import { getCurrentTeam, getPlayer, isInTeam, WithTransaction } from '../utils';
|
||||
import { User } from 'src/users/schemas/user.entity';
|
||||
import { ReadTeamDto } from '../dto/read-games.dto';
|
||||
|
||||
@ApiTags('game')
|
||||
@Controller('games/:id')
|
||||
@@ -75,6 +77,41 @@ export class GamesController {
|
||||
await this.gameService.endTurn(game);
|
||||
}
|
||||
|
||||
@Post(':id/leave')
|
||||
@ApiOperation({ summary: "Leave a game that hasn't already started" })
|
||||
@UseGuards(AuthGuard)
|
||||
async leave(
|
||||
@Param('id') id: string,
|
||||
@Session() session: Record<string, any>,
|
||||
@Param('id', GamePipe) game: Document<Game> & Game,
|
||||
) {
|
||||
if (game.started) {
|
||||
throw new HttpException('Game already started', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.gameService.leaveGame(game, session.user);
|
||||
}
|
||||
|
||||
@Post(':id/kick/:playerId')
|
||||
@ApiOperation({ summary: 'Kick a player' })
|
||||
@UseGuards(AuthGuard)
|
||||
async kick(
|
||||
@Param('id') id: string,
|
||||
@Session() session: Record<string, any>,
|
||||
@Param('id', GamePipe) game: Document<Game> & Game,
|
||||
@Param('playerId') playerId: string,
|
||||
) {
|
||||
if (game.started) {
|
||||
throw new HttpException('Game already started', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (session.user.userId != game.owner.userId) {
|
||||
throw new HttpException(
|
||||
'You do do not own this game',
|
||||
HttpStatus.FORBIDDEN,
|
||||
);
|
||||
}
|
||||
return await this.gameService.kickPlayer(game, session.user, playerId);
|
||||
}
|
||||
|
||||
@Sse('/subscribe')
|
||||
subscribe(
|
||||
@Param('id') id: string,
|
||||
|
||||
Reference in New Issue
Block a user