title: How to make a dynamic roles guard, to work in both controllers and handlers
body: <p>I'm defining a roles guard like this:</p>
  <pre class="lang-js prettyprint-override"><code>import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
  import { Reflector } from '@nestjs/core';
  import { Observable } from 'rxjs';
  import { User } from './user.entity';
  
  @Injectable()
  export class RolesGuard implements CanActivate {
    constructor(
      private reflector: Reflector,
    ) { }
  
    async matchRoles(roles: string[], userRole: User[&quot;roles&quot;]) {
      let match = false;
  
      if (roles.indexOf(userRole) &gt; -1) {
        match = true;
      }
  
      return match
    }
  
    canActivate(
      context: ExecutionContext,
    ): boolean | Promise&lt;boolean&gt; | Observable&lt;boolean&gt; {
      const roles = this.reflector.get&lt;string[]&gt;('roles', context.getClass());
      if (!roles) {
        return true;
      }
      const request = context.switchToHttp().getRequest();
      const user: User = request.user;
  
      return this.matchRoles(roles, user.roles)
    }
  }
  </code></pre>
  <p>in this roles example it works only in a controller level like this:</p>
  <pre class="lang-js prettyprint-override"><code>@Controller('games')
  @hasRoles('user')
  @UseGuards(AuthGuard(), JwtGuard, RolesGuard)
  export class GamesController {
  ...
  </code></pre>
  <p>But i want it to work dynamically with both, at controller level, and handler level.
  so i can appy a <code>@hasRoles('user')</code> for every route in the controller, and <code>@hasRoles('admin')</code> for some routes  in that controller.</p>
  <p>So to do this i need to change the reflector method from <code>getClass</code> to <code>getHandler</code> dynamically.</p>