nestia icon indicating copy to clipboard operation
nestia copied to clipboard

Using applyDecorator with nestia

Open loucass003 opened this issue 9 months ago • 3 comments

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.

loucass003 avatar Sep 26 '23 15:09 loucass003

Not possible due to @nestia/core is based on transformation (AOT compilation).

samchon avatar Sep 26 '23 16:09 samchon

would there be a way to make an aot version of applydecorators? allowing to mix nestjs ans nestia decorators?

loucass003 avatar Sep 26 '23 17:09 loucass003

Have considered the way, but could not get any idea yet. If you have, then suggest me please.

samchon avatar Sep 27 '23 19:09 samchon