UNPKG

nralcm

Version:

This is a framework based on NodeJs to manage rest api request lifecycle

28 lines (27 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("reflect-metadata/Reflect"); const functions_1 = require("../common/functions"); /** * Decorator for Authentication and Authorization * @param roles Roles array (string) */ function Authorize(roles) { return function (target, propertyKey, descriptor) { if (propertyKey && descriptor) { Reflect.defineMetadata("authorize", { roles: roles }, target, propertyKey); } else { const targetString = target.toString(); const baseControllerIndex = targetString.indexOf("BaseController"); if (baseControllerIndex > 0 && targetString.indexOf("BaseController") < targetString.indexOf("{")) { functions_1.IsInjectable(target); Reflect.defineMetadata("authorize", { roles: roles }, target); } else { throw new Error(`${target.name} must extend with BaseController`); } } }; } exports.Authorize = Authorize;