diff --git a/src/games/pipe/card.pipe.ts b/src/games/pipe/card.pipe.ts new file mode 100644 index 0000000..0c844f3 --- /dev/null +++ b/src/games/pipe/card.pipe.ts @@ -0,0 +1,22 @@ +import { + PipeTransform, + Injectable, + HttpException, + HttpStatus, +} from '@nestjs/common'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; +import { Card } from 'src/cards/schemas/cards.schema'; + +@Injectable() +export class CardPipe implements PipeTransform { + constructor(@InjectModel(Card.name) private cardmodel: Model) {} + + async transform(value: any) { + const card = await this.cardmodel.findById(value); + if (!card) { + throw new HttpException('Card not found', HttpStatus.NOT_FOUND); + } + return card; + } +}