Skip to content

Commit a678fff

Browse files
committed
fix dto structure
1 parent 551d6fc commit a678fff

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

service/src/_common/dto/parts/idname.part.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IsMongoId, IsNotEmpty, IsString } from 'class-validator'
22
import { ApiProperty } from '@nestjs/swagger'
33

44
export class IdnamePartDto {
5-
@IsMongoId()
5+
@IsMongoId({ message: 'Id invalide' })
66
@ApiProperty()
77
public id: string
88

service/src/_common/pipes/dto-validation.pipe.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export class DtoValidationPipe extends ValidationPipe {
3131
const message = `Erreur de validation : ${Object.keys(validations).join(', ')}`.trim()
3232
Logger.debug(`${message} (${JSON.stringify(validations)})`, 'DtoValidationPipe')
3333
if (process.env.NODE_ENV !== 'production' && request.query['debug']) {
34-
debug['_errors'] = errors
34+
debug['_errors'] = errors.map((error) => {
35+
delete error['target']
36+
return error
37+
})
3538
}
3639
return new BadRequestException({
3740
statusCode: HttpStatus.BAD_REQUEST,
@@ -49,9 +52,10 @@ export class DtoValidationPipe extends ValidationPipe {
4952
validations[`${prefix + error.property}`] = Object.values(error.constraints)[0]
5053
}
5154
if (error.children.length > 0) {
55+
console.log(error.children)
5256
for (const errorChild of error.children) {
5357
if (errorChild.constraints) {
54-
validations[`${prefix + errorChild.property}`] = Object.values(errorChild.constraints)[0]
58+
validations[`${prefix + error.property}.${errorChild.property}`] = Object.values(errorChild.constraints)[0]
5559
}
5660
if (errorChild.children.length > 0) {
5761
validations = { ...validations, ...this.validationRecursive(errorChild, `${prefix + error.property}.${errorChild.property}.`) }

0 commit comments

Comments
 (0)