Template
feat : add testing
This commit is contained in:
@@ -19,6 +19,7 @@ import { Observable, fromEvent, map } from 'rxjs';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { GameService } from '../services/games.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { SessionData } from 'express-session';
|
||||
|
||||
@ApiTags('game')
|
||||
@Controller('games/:id')
|
||||
@@ -47,7 +48,7 @@ export class GamesController {
|
||||
@UseGuards(AuthGuard)
|
||||
async start(
|
||||
@Param('id') id: string,
|
||||
@Session() session: Record<string, any>,
|
||||
@Session() session: SessionData,
|
||||
@Param('id', GamePipe) game: Game,
|
||||
) {
|
||||
if (game.started) {
|
||||
@@ -59,7 +60,7 @@ export class GamesController {
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
if (game.owner.userId != session.user.userId) {
|
||||
if (game.owner.id != session.user.id) {
|
||||
throw new HttpException(
|
||||
'You can only start games you own',
|
||||
HttpStatus.FORBIDDEN,
|
||||
@@ -72,33 +73,33 @@ export class GamesController {
|
||||
@Post('surrender')
|
||||
@ApiOperation({ summary: 'Leave a game that has already started' })
|
||||
@UseGuards(AuthGuard)
|
||||
async surrender(
|
||||
surrender(
|
||||
@Param('id') id: string,
|
||||
@Session() session: Record<string, any>,
|
||||
@Session() session: SessionData,
|
||||
@Param('id', GamePipe) game: Game,
|
||||
) {
|
||||
if (!game.started) {
|
||||
throw new HttpException('Game has not started', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.lobbyService.leaveGame(game, session.user);
|
||||
return this.lobbyService.leaveGame(game, session.user);
|
||||
}
|
||||
|
||||
@Post('kick/:playerId')
|
||||
@ApiOperation({ summary: 'Kick a player' })
|
||||
@UseGuards(AuthGuard)
|
||||
async kick(
|
||||
kick(
|
||||
@Param('id') id: string,
|
||||
@Session() session: Record<string, any>,
|
||||
@Session() session: SessionData,
|
||||
@Param('id', GamePipe) game: Game,
|
||||
@Param('playerId') playerId: string,
|
||||
) {
|
||||
if (session.user.userId != game.owner.userId) {
|
||||
if (session.user.id != game.owner.id) {
|
||||
throw new HttpException(
|
||||
'You do do not own this game',
|
||||
HttpStatus.FORBIDDEN,
|
||||
);
|
||||
}
|
||||
return await this.lobbyService.kickPlayer(game, session.user, playerId);
|
||||
return this.lobbyService.kickPlayer(game, session.user, playerId);
|
||||
}
|
||||
|
||||
@Sse('/subscribe')
|
||||
|
||||
Reference in New Issue
Block a user