Chore : add cardPipe

This commit is contained in:
2024-07-05 09:54:33 +02:00
parent 558a2d1063
commit 345332922c
+22
View File
@@ -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<Card>) {}
async transform(value: any) {
const card = await this.cardmodel.findById(value);
if (!card) {
throw new HttpException('Card not found', HttpStatus.NOT_FOUND);
}
return card;
}
}