import { Controller } from 'egg' ; import { route } from '../../../../../lib' ; import { BadRequestError } from '../../../../../lib/error' ; export class TypeFormatController extends Controller { @ route ( '/typeformat/string' ) string ( data ) { if ( typeof data !== 'string' ) { throw new BadRequestError ( `${ typeof data } ${ data }` ) ; } } @ route ( '/typeformat/number' ) number ( data ) { if ( typeof data !== 'number' ) { throw new BadRequestError ( `${ typeof data } ${ data }` ) ; } } @ route ( '/typeformat/boolean' ) boolean ( data ) { if ( typeof data !== 'boolean' ) { throw new BadRequestError ( `${ typeof data } ${ data }` ) ; } } @ route ( 'POST /typeformat/boolean' ) booleanPost ( data ) { if ( typeof data !== 'boolean' ) { throw new BadRequestError ( `${ typeof data } ${ data }` ) ; } } /** need the type info 'number' of array */ @ route ( '/typeformat/array' , { name : 'array' , validateMetaInfo : [ { name : 'id' , rule : { type : 'array' , itemType : 'number' , } , } , ] , schemas : { params : [ { name : 'id3' , in : 'query' , schema : { type : 'array' , items : { type : 'number' , } , } , } , ] , } , } ) async array ( id , id2 , id3 ) { return { id , id2 , id3 } ; } @ route ( 'POST /typeformat/array' ) async postArray ( ids ) { return ids ; } }