import { ApiController , Controller , HttpGet , BindNumber , BindBoolean , BindInteger , HttpPost , Parse , Async , QueryParam } from '../../../../index' ; import { toNumberTen , toJPG , toNumber , toUser , throwException , convertToProvidedData , numValidation , boolValidation , returnProps , toUserAdd } from '../parse-handlers/handlers' ; import { User } from './user' ; @ Controller ( '/home' ) export class HomeController extends ApiController { @ HttpGet ( '/withoutParse/:id/:photo' ) withoutParse ( id , photo ) { return { id : id , photo : photo , message : '.jpg is not added to photo, and id holds string type' } ; } @ HttpGet ( '/withParse/:id/:photo' ) withParse ( @ Parse ( toNumber ) id , @ Parse ( toJPG ) photo ) { return { id : id , photo : photo , message : '.jpg added to photo, and id must be converted to number' } ; } @ HttpGet ( '/parseException/:id' ) parseException ( @ Parse ( throwException ) id ) { return { message : '.jpg added to photo, and id must be converted to number' } ; } @ Async ( ) @ HttpGet ( '/asyncParseException/:id' ) async asyncParseException ( @ Parse ( throwException ) id ) { return '.jpg added to photo, and id must be converted to number' ; } @ HttpGet ( '/getTen/:id' ) getTen ( @ Parse ( toNumberTen ) id ) { return { id : id , message : 'No matter what you pass to /:id, it would always transform to 10' } ; } @ HttpPost ( '/postTen/:id' ) postTen ( @ Parse ( toUser ) user , @ Parse ( toNumberTen ) id ) { return { user : user , id : id , message : 'No matter what you post in body, user will be null and id is ten' } ; } @ HttpPost ( '/postUser/:id' ) postUser ( @ Parse ( toUserAdd ) user , @ Parse ( toNumberTen ) id ) { return { user : user , id : id , message : 'Provide { "name": "dino" } as body and name is prepended with "hello"' } ; } @ HttpPost ( '/pickPost/:user' ) pickPost ( @ Parse ( toUserAdd ) user ) { return { user : user , message : 'user is picked from http-body and not from segment' } ; } @ HttpPost ( '/pickPostUser/:user' ) pickPostUser ( @ Parse ( toUserAdd ) body , @ Parse ( toNumber ) user ) { return { body : body , user : user , message : 'user is picked from the segment and body from http-body' } ; } @ HttpPost ( '/postWithoutParse' ) post ( user ) { return { user : user , message : 'You will receive exactly what you have passed in the body' } ; } @ HttpPost ( '/postWithoutParam' ) postWithoutParam ( ) { return { message : 'Should not break and continue working' } ; } @ HttpGet ( '/parseWithData/:id' ) parseWithData ( @ Parse ( convertToProvidedData , String ) id ) { return { id : id , message : 'Should return "String" always' } ; } @ HttpGet ( '/props/:id' ) props ( @ Parse ( returnProps , 'dummyData' ) id ) { return { props : id , message : 'Should return props properties' } ; } @ HttpGet ( '/parseValidations/:id/:name' ) parseValidations ( @ Parse ( numValidation ) id , @ Parse ( boolValidation ) name ) { return { id : id , name : name , message : 'Should return validation errors for model' , isValid : this . model . isValid , modelErrors : this . model . errors , values : this . model . values } ; } @ HttpGet ( '/queryParam' ) withQueryParam ( @ QueryParam ( ) search ) { return { search : search } ; } @ HttpGet ( '/queryParamParse' ) withQueryParamParse ( @ QueryParam ( toNumber ) id ) { return { id : id } ; } @ HttpGet ( '/queryParam/:id' ) withQueryParamAndParse ( @ Parse ( toNumber ) id , @ QueryParam ( ) search ) { return { id : id , search : search } ; } @ HttpGet ( '/queryParamAndParse/:id' ) queryParamAndParse ( @ QueryParam ( ) id ) { return { id : id , req : 'Perform GET /queryParam/45?id=32' , msg : 'should map from query string. Should return 32' } ; } @ HttpGet ( '/paramParser/:id' ) paramParser ( id ) { return { id : id , req : 'Perform GET /queryParam/45?id=32' , msg : 'should map from variable segment. Should return 45' } ; } @ HttpGet ( '/bindNumber/:id' ) bindNumber ( @ BindNumber ( ) id ) { return { id } ; } @ HttpGet ( '/bindBoolean/:id' ) bindBoolean ( @ BindBoolean ( ) id ) { return { id } ; } @ HttpGet ( '/bindInteger/:id' ) bindInteger ( @ BindInteger ( ) id ) { return { id } ; } }