@yuriyempty/nestjs-extended-controller
TypeScript icon, indicating that this package has built-in type declarations

1.1.31 • Public • Published

nestjs-extended-controller

NPM Version NPM Downloads Node.js Version

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

Package Sidebar

Install

npm i @yuriyempty/nestjs-extended-controller

Weekly Downloads

18

Version

1.1.31

License

MIT

Unpacked Size

24 kB

Total Files

14

Last publish

Collaborators

  • yuriyempty