Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseController<T>

The base controller with CRUD and authentication

Type parameters

Hierarchy

Index

Constructors

constructor

  • Create a new base controller and attaches CRUD method with 'routeName' express route

    Parameters

    • baseRepository: BaseRepository<T>

      The generic base repository with CRUD operations

    • app: any

      The express application used to register a new route for this controller

    Returns BaseController

Properties

Private app

app: any

The express application used to register a new route for this controller

Private baseRepository

baseRepository: BaseRepository<T>

The generic base repository with CRUD operations

Protected isAuthEnabled

isAuthEnabled: boolean = false

Indicates if the authentication has been enabled in this controller

Protected router

router: Router = Router()

The express router

Accessors

routeName

  • get routeName(): string

Methods

register

  • register(): this

useAuth

  • useAuth(): this
  • Enable JWT token verification. Every method called after this call will use authentication

    A user scope can be specified using a scope middleware.

    Returns this

useCreate

  • useCreate(middleware?: Array<RequestHandler>): this
  • Attach to the current route the create operation

    A user scope can be specified using a scope middleware.

    Parameters

    • Optional middleware: Array<RequestHandler>

    Returns this

useCrud

  • Attach to the current route the CRUD operations.

    A user scope can be specified using a scope middleware.

    Delete operation required Admin scope by default in all collection

    Parameters

    Returns this

Abstract useCustoms

useDelete

  • useDelete(middleware?: Array<RequestHandler>): this
  • Attach to the current route the delete operation

    A user scope can be specified using a scope middleware.

    Parameters

    • Optional middleware: Array<RequestHandler>

    Returns this

useMiddleware

  • useMiddleware(...middleware: Array<RequestHandler>): this
  • Allow to use middleware for all methods

    Parameters

    • Rest ...middleware: Array<RequestHandler>

      The middleware to use for all methods

    Returns this

useRead

  • useRead(middleware?: Array<RequestHandler>): this
  • Attach to the current route the read all and ready by id operation

    A user scope can be specified using a scope middleware.

    Parameters

    • Optional middleware: Array<RequestHandler>

    Returns this

useUpdate

  • useUpdate(middleware?: Array<RequestHandler>): this
  • Attach to the current route the update operation

    A user scope can be specified using a scope middleware.

    Parameters

    • Optional middleware: Array<RequestHandler>

    Returns this

Generated using TypeDoc