fix: update error.constraints conditions

This commit is contained in:
yassinedorbozgithub 2025-01-15 11:04:18 +01:00
parent 2a25f19448
commit bac79cd74a

View File

@ -33,7 +33,7 @@ export class ObjectIdPipe implements PipeTransform<string, Promise<string>> {
async transform(value: string, { type, data }: ArgumentMetadata) {
if (typeof value === 'string' && data === 'id' && type === 'param') {
const errors = await this.getErrors(value);
if (errors.constraints)
if (errors?.constraints)
throw new BadRequestException(Object.values(errors.constraints)[0]);
} else if (
typeof value === 'object' &&
@ -45,7 +45,7 @@ export class ObjectIdPipe implements PipeTransform<string, Promise<string>> {
if (param.startsWith('id')) {
const errors = await this.getErrors(String(paramValue));
if (errors.constraints)
if (errors?.constraints)
throw new BadRequestException(
Object.values(errors.constraints)[0],
);