diff --git a/src/Controller.ts b/src/Controller.ts index 135776c..bed86e3 100644 --- a/src/Controller.ts +++ b/src/Controller.ts @@ -80,6 +80,22 @@ export default abstract class Controller { this.router?.post(path, this.wrap(handler)); } + protected put(path: PathParams, handler: RequestHandler, routeName?: string, ...middlewares: RequestHandler[]) { + this.registerRoutes(path, handler, routeName); + for (const middleware of middlewares) { + this.router?.put(path, this.wrap(middleware)); + } + this.router?.put(path, this.wrap(handler)); + } + + protected delete(path: PathParams, handler: RequestHandler, routeName?: string, ...middlewares: RequestHandler[]) { + this.registerRoutes(path, handler, routeName); + for (const middleware of middlewares) { + this.router?.delete(path, this.wrap(middleware)); + } + this.router?.delete(path, this.wrap(handler)); + } + private wrap(handler: RequestHandler): RequestHandler { return (req, res, next) => { function handleErr(e: any) {