Initial commit

This commit is contained in:
2024-12-27 22:54:05 +01:00
commit 024834d309
46 changed files with 14574 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import {
PipeTransform,
Injectable,
HttpException,
HttpStatus,
} from '@nestjs/common';
import { Game } from '../schemas/game.schema';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
@Injectable()
export class GamePipe implements PipeTransform {
constructor(@InjectRepository(Game) private gameRepository: Repository<Game>) {}
async transform(value: any) {
const game = await this.gameRepository.findBy({id: value});
if (!game) {
throw new HttpException('Game not found', HttpStatus.NOT_FOUND);
}
return game;
}
}
@Injectable()
export class GameStartedPipe implements PipeTransform {
constructor(@InjectRepository(Game) private gameRepository: Repository<Game>) {}
async transform(value: any) {
const game = await this.gameRepository.findBy({id: value});
if (!game) {
throw new HttpException('Game not found', HttpStatus.NOT_FOUND);
}
if (!game.started) {
throw new HttpException(
'The game must be started',
HttpStatus.BAD_REQUEST,
);
}
return game;
}
}