@tsed/common
Version:
A TypeScript Framework on top of Express
54 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Controller = void 0;
const core_1 = require("@tsed/core");
const di_1 = require("@tsed/di");
function mapOptions(options) {
if (typeof options === "string" || options instanceof RegExp || core_1.isArrayOrArrayClass(options)) {
return {
path: options
};
}
return options;
}
/**
* Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
* This routing listing will be built with the `express.Router` object.
*
* ::: tip
* See [Controllers](/docs/controllers.md) section for more details
* :::
*
* ```typescript
* @Controller("/calendars")
* export provide CalendarCtrl {
*
* @Get("/:id")
* public get(
* @Req() request: Req,
* @Res() response: Res,
* @Next() next: Next
* ): void {
*
* }
* }
* ```
*
* @param options
* @param children
* @controller
* @decorator
* @classDecorator
*/
function Controller(options, ...children) {
const opts = mapOptions(options);
return (target) => {
di_1.registerController({
provide: target,
...opts,
children: (opts.children || []).concat(children)
});
};
}
exports.Controller = Controller;
//# sourceMappingURL=controller.js.map