hinos-requestmatcher
v1.0.7
Published
Module help parse type for request query, params, body before get data in controller for hinos
Downloads
3
Readme
hi-requestmatcher
A plugin cast type for request as query, params, body before get data in controller hinos
Install
npm i hinos-requestmatcher -S
Examples
Typescript
File controller
import { GET, POST, PUT, DELETE, HEAD } from 'hinos-route';
import { BODYPARSER } from 'hinos-bodyparser';
import { MATCHER } from 'hinos-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;
}
}