import { Request, Response } from "express" import { Container } from "typedi" import { App } from '../index' function preparePath(path: string | RegExp): string { const newPath = App.expressApp.get("baseRoute") + path; return newPath; } function methodDecorator(target: any, descriptor: PropertyDescriptor, path: string | RegExp, method: string, middlewares: Function | Function[] = null, arrValidator: Array = [], ignore: boolean = false) { const self = Container.get(target.constructor) const pathPrepared = ignore ? path : preparePath(path) if(middlewares) { App.expressApp[method](pathPrepared, arrValidator, middlewares, descriptor.value.bind(self)) } else { App.expressApp[method](pathPrepared, descriptor.value.bind(self)) } return descriptor; } export const Http = { Get: (path: string, middlewares: Function | Array = null, arrValidator: Array = [], ignore = false) => { return (target: any, propertyKey: any, descriptor: PropertyDescriptor) => { return methodDecorator(target, descriptor, path, 'get', middlewares, arrValidator, ignore); } }, Post: (path: string, middlewares: Function | Array = null, arrValidator: Array = [], ignore = false) => { return (target: any, propertyKey: any, descriptor: PropertyDescriptor) => { return methodDecorator(target, descriptor, path, 'post', middlewares, arrValidator, ignore); } }, Put: (path: string, middlewares: Function | Array = null, arrValidator: Array = [], ignore = false) => { return (target: any, propertyKey: any, descriptor: PropertyDescriptor) => { return methodDecorator(target, descriptor, path, 'put', middlewares, arrValidator, ignore); } }, Delete: (path: string, middlewares: Function | Array = null, arrValidator: Array = [], ignore = false) => { return (target: any, propertyKey: any, descriptor: PropertyDescriptor) => { return methodDecorator(target, descriptor, path, 'delete', middlewares, arrValidator, ignore); } } }