Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaseRouter {
- app: express.Application = express;
- // some other comment stuff
- }
- function PostMethod(route: string = '/') {
- return (target: BaseRouter, key: string, descriptor: PropertyDescriptor): void {
- // This is where things don't work out
- // descriptor.value correctly returns the RequestHandler which I can attach to express
- // target.app is undefined
- target.app.post(route, descriptor.value);
- }
- }
- @ResourceRouter() // <= this is optional, can I access all decorators inside the class from this decorator? That would also lead me to a solution
- export class BlogRouter extends BaseRouter {
- @GetMethod()
- index(req, res) {
- // req.send(...); return posts
- }
- @GetMethod('/:modelId')
- show(req, res, next) {
- // find req.params.modelId
- }
- @PostMethod()
- createPost() {}
- @DeleteMethod()
- deletePost() {}
- @UpdateMethod()
- updatePost() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement