'NESTjs validate DTO after the request comes in
Hihi, I have a special situation where I need to validate the body of the request but instead of failing I need to wrap that error array and send it as a response afterwards. With this I mean
@Post('/archives')
async bulkUpload(@Body() body, errors: []): Promise<ArchivesDto> {
const archives = await this.service.save(body);
return this.archivesMapping.getArchivesDto(archives, errors);
}
async save(dto: ArchivesDto): Promise<any> {
retrun ...resultof
}
and in the final response
{
archives:[] // the ones saved
errors: []// those who were bad
}
I mean, I can manually check each and everyone of them with joi or something like that and write a custom message, but the NestJS validation works well and I need to upgrade it a little bit
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
