In my controller, I have multiple requests (POST, GET etc.) where the path includes an id parameter that needs to be a number string. I want to validate this parameter once and have it apply to all instances.
Here is the current code snippet:
@Get(':account_id')
@ApiOperation({
description: 'Get account information',
operationId: 'getAccount',
title: 'Get account information',
})
@ApiOkResponse({ type: AccountDto })
@ApiUnauthorizedResponse({ type: ApiErrorDto })
@ApiForbiddenResponse({ type: ApiErrorDto })
@ApiNotFoundResponse({ type: ApiErrorDto })
@ApiBadRequestResponse({ type: ApiErrorDto })
@ApiImplicitParam({ name: 'account_id', description: 'The account Id' })
async findOne(@Param('account_id', new ParseIntPipe()) accountId: string): Promise<AccountDto> {
return await this.accountService.findOne(accountId);
}
I find myself needing to call the validation pipe every time.
Is there a way for me to apply validation to all occurrences of `account_id` variables in my controller?