You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
test-assignment-payments/src/pipes/body.validation.pipe.ts

15 lines
415 B

import { PipeTransform, Injectable, BadRequestException } from '@nestjs/common';
import { ObjectSchema } from 'joi';
@Injectable()
export class BodyValidationPipe implements PipeTransform {
constructor(private schema: ObjectSchema) {}
transform(value: any) {
const { error } = this.schema.validate(value);
if (error) {
throw new BadRequestException(error.message);
}
return value;
}
}