Add PUT and DELETE REST methods to controllers
This commit is contained in:
parent
e63b5d21fe
commit
8755a152a6
@ -80,6 +80,22 @@ export default abstract class Controller {
|
|||||||
this.router?.post(path, this.wrap(handler));
|
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 {
|
private wrap(handler: RequestHandler): RequestHandler {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
function handleErr(e: any) {
|
function handleErr(e: any) {
|
||||||
|
Loading…
Reference in New Issue
Block a user