UNPKG

@tsed/common

Version:
46 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UseAfter = void 0; const core_1 = require("@tsed/core"); const schema_1 = require("@tsed/schema"); /** * Mounts the specified middleware function or functions at the specified path: the middleware function is executed when * the base of the requested path matches `path. * * ```typescript * @Controller('/') * @UseAfter(Middleware1) * export class Ctrl { * * @Get('/') * @UseAfter(Middleware2) * get() { } * } * ``` * * @returns {function(any, any, any): *} * @param args * @decorator * @operation */ function UseAfter(...args) { return schema_1.JsonEntityFn((entity, parameters) => { switch (entity.decoratorType) { case core_1.DecoratorTypes.METHOD: const endpoint = entity; endpoint.afterMiddlewares = args.concat(endpoint.afterMiddlewares); break; case core_1.DecoratorTypes.CLASS: const middlewares = entity.store.get("middlewares") || {}; entity.store.set("middlewares", { ...middlewares, useAfter: [...args, ...(middlewares.useAfter || [])] }); break; default: throw new core_1.UnsupportedDecoratorType(UseAfter, parameters); } }); } exports.UseAfter = UseAfter; //# sourceMappingURL=useAfter.js.map