nestia
nestia copied to clipboard
Using applyDecorator with nestia
I am trying to use the nestjs applyDecorator method, to group nestjs and nestia decorators together.
it seems like the TypedException is not recognized. is that functionality not supported? is there an alternative ?
import {
applyDecorators,
ForbiddenException,
HttpStatus,
SetMetadata,
} from '@nestjs/common';
import { Role } from './role.enum';
import { TypedException } from '@nestia/core';
export const ROLE_KEY = 'role';
export const Roles = (role: Role) =>
applyDecorators(
SetMetadata(ROLE_KEY, role),
TypedException<ForbiddenException>(HttpStatus.FORBIDDEN),
);
/**
* Request something
*
* @security X-Auth-Token
*/
@TypedRoute.Post('/request')
@Roles(Role.ROLE_SUPER_ADMIN)
public async request() {
return true;
}
it would also be nice to have an equivalent to the nestjs @ApiSecurity
decorator that does not require a comment.
That way you could add it inside the applyDecorator to not have to specify security in the comment.
Not possible due to @nestia/core
is based on transformation (AOT compilation).
would there be a way to make an aot version of applydecorators? allowing to mix nestjs ans nestia decorators?
Have considered the way, but could not get any idea yet. If you have, then suggest me please.