AI Implementation feature(820): Project Scaffold and Platform Foundations (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';
|
||||
import { ZodSchema } from 'zod';
|
||||
import { ApiError } from '../errors/api-error';
|
||||
|
||||
@Injectable()
|
||||
export class ZodValidationPipe implements PipeTransform {
|
||||
constructor(private readonly schema: ZodSchema) {}
|
||||
|
||||
transform(value: any, _metadata: ArgumentMetadata): any {
|
||||
const parsed = this.schema.safeParse(value);
|
||||
if (!parsed.success) {
|
||||
const details = parsed.error.issues.map((i) => ({ path: i.path.join('.'), message: i.message }));
|
||||
throw ApiError.validation('Request validation failed', details);
|
||||
}
|
||||
return parsed.data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user