vados-requestmatcher
v1.0.0
Published
Module help parse type for request query, params, body before get data in controller for vados
Downloads
1
Readme
hi-requestmatcher
A plugin cast type for request as query, params, body before get data in controller vados
Install
npm i vados-requestmatcher -S
Examples
Typescript
File controller
import { GET, POST, PUT, DELETE, HEAD } from 'vados-route';
import { BODYPARSER } from 'vados-bodyparser';
import { MATCHER } from 'vados-requestmatcher';
export default class ChartController {
@POST('/chart/:id')
@BODYPARSER() // Parse body first
@MATCHER({ // Cast data type
params: {
id: Mongo.uuid
},
body: {
name: String,
des: String,
id: id => +id; // Customize parser, can use async, await
}
})
static async add({
params, // get after parse and match
body // get after parse and match
}) {
const rs: Chart = await ChartService.insert(body);
return rs;
}
}