Chore : add cardPipe
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user