Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. class BaseRouter {
  2.  
  3. app: express.Application = express;
  4.  
  5. // some other comment stuff
  6. }
  7.  
  8. function PostMethod(route: string = '/') {
  9.  
  10. return (target: BaseRouter, key: string, descriptor: PropertyDescriptor): void {
  11.  
  12. // This is where things don't work out
  13. // descriptor.value correctly returns the RequestHandler which I can attach to express
  14. // target.app is undefined
  15. target.app.post(route, descriptor.value);
  16. }
  17. }
  18.  
  19. @ResourceRouter() // <= this is optional, can I access all decorators inside the class from this decorator? That would also lead me to a solution
  20. export class BlogRouter extends BaseRouter {
  21.  
  22.  
  23. @GetMethod()
  24. index(req, res) {
  25.  
  26. // req.send(...); return posts
  27. }
  28.  
  29.  
  30. @GetMethod('/:modelId')
  31. show(req, res, next) {
  32.  
  33. // find req.params.modelId
  34. }
  35.  
  36. @PostMethod()
  37. createPost() {}
  38.  
  39. @DeleteMethod()
  40. deletePost() {}
  41.  
  42. @UpdateMethod()
  43. updatePost() {}
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement