@yuriyempty/nestjs-extended-controller
v1.1.31
Published
Extended Controller - a small package that allows you to extend the capabilities of the standard nestjs controller, by actually replacing it.
Downloads
214
Maintainers
Readme
nestjs-extended-controller
Description
ExtendedController is a wrapper for "@nestjs/common/decorators/core/controller.decorator". With its help, you can inherit the behavior of the parent controller.
Example
First, we must create a parent controller
import { Controller } from "@nestjs/common";
@Controller("api")
export class AppController {}
Then create a child and assign a parent
import { Get, Param } from "@nestjs/common";
import { AppController } from "./app.controller";
import { ExtendedController } from "@yuriyempty/nestjs-extended-controller";
@ExtendedController({
parent: AppController,
path: [ "user", ":id" ]
})
export class UserController {
@Get()
public get(@Param() params): object {
return {
response: `response form route api/user/${ params.id }`
}
}
@Get("update")
public update(@Param() params): object {
return {
response: `response form route api/user/${ params.id }/update`
}
}
}
Also to param "parent" we can passed other "ExtendedController"
import { Get, Param } from "@nestjs/common";
import { UserController } from "./user.controller";
import { ExtendedController } from "@yuriyempty/nestjs-extended-controller";
@ExtendedController({
parent: UserController,
path: "profile"
})
export class ProfileController {
@Get()
public get(@Param() params): object {
return {
response: `response from route api/user/${ params.id }/profile`
}
}
@Get("update")
public update(@Param() params): object {
return {
response: `response from api/user/${ params.id }/profile/update`
}
}
}
Options
| Name | Type | Default | Description | | ----------------------- |:------------------------------:|:-----------:| --------------------------------------------------------------- | | parent | Function | Controller | The parent class from which the behavior will be inherited | | path | string, string[] | "" | Inherits https://docs.nestjs.com/controllers#routing | | inheritRoutes | boolean | true | | | inheritHost | boolean | true | | | inheritScope | boolean | true | | | inheritGuards | boolean | true | | | inheritPipes | boolean | true | | | inheritExceptionFilters | boolean | true | | | inheritInterceptors | boolean | true | |
TODO