I have requests in my controller, the @Param
is the string version of the MongoId.
If I call this request with an invalid format of the string, not Matching the MongoId format, the request goes through until the MongoDB call throws an internal server Error.
How do I validate that for example "aaa"
or "ANWPINREBAFSOFASD" is not validated and stops as early as possible in my requests
Current Controller Endpoint:
@Get(':id')
@ApiOperation({ summary: 'Get nice information' })
findOne(
@Param('id') id: string) {
return this.niceService.findOne(id);
}
The service that is called:
async findOne(id: string): Promise<NiceDocument> {
const niceResult: NiceDocument = await this.NiceSchema.findById(id)
if (!niceResult) {
throw new NotFoundException()
}
return table
}