mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
21 lines
488 B
TypeScript
21 lines
488 B
TypeScript
import {
|
|
PipeTransform,
|
|
ArgumentMetadata,
|
|
BadRequestException,
|
|
} from '@nestjs/common';
|
|
import { ZodSchema } from 'zod';
|
|
|
|
export class ZodValidationPipe implements PipeTransform {
|
|
constructor(private schema: ZodSchema) {}
|
|
|
|
transform(value: unknown, metadata: ArgumentMetadata) {
|
|
try {
|
|
const parsedValue = this.schema.parse(value);
|
|
return parsedValue;
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new BadRequestException(error.errors);
|
|
}
|
|
}
|
|
}
|