Router Methods

import { Get, Post, Put, Delete } from '@appt/api/router';

Appt's router methods are essentially express router methods with sugar. So first, we export every method express also does on a Capitalized pattern. Second, makes sense for us to maintain an semantic and coherent pattern, since many things here are using decorator and annotation syntax. Lets improve the PrivateRouter component a little:

private.router.js
import { TRouter } from '@appt/api';
import { Get, Post } from '@appt/api/router';
@Component({
extend: TRouter('/private', {
auth: {
secret: '231edfrw21g34',
ignore: ['favicon.ico', /\/back-/\/]
}
}),
inject: 'MiddlewaresComponent'
})
export class PrivateRouter{
constructor(myMiddleware){
this.middleware = myMiddleware;
}
@Get('/')
getAll(req, res, next){
res.status(200).send('Take everything!')
}
@Get('/:id')
getById(req, res, next){
res.status(200).send(`We're gonna search by: ${req.params.id}`)
}
@Post('/:id', this.middleware.doSomethingFirst)
getById(req, res, next){
res.status(200).send(req.body)
}
}