File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 11import { Request , Response } from 'express' ;
2+ import { validationResult } from 'express-validator' ;
23
34class FactorialController {
45 compute ( request : Request , response : Response ) {
5- console . log ( request . query ) ;
6+ const errors = validationResult ( request ) ;
7+
8+ if ( ! errors . isEmpty ( ) ) {
9+ return response . status ( 400 ) . json ( { errors : errors . array ( ) } ) ;
10+ }
11+
612 return response . send ( "ok, it's working!" ) ;
713 }
814}
Original file line number Diff line number Diff line change 11import { Router } from 'express' ;
2+ import { query } from 'express-validator' ;
3+
24import FactorialController from './controllers/Factorial' ;
35
46const route = Router ( ) ;
57
68const factorialController = new FactorialController ( ) ;
79
8- route . get ( '/factorial' , factorialController . compute ) ;
10+ route . get ( '/factorial' , [
11+ query ( 'number' ) . isNumeric ( ) . withMessage ( 'Você precisa fornecer um número' )
12+ ] , factorialController . compute ) ;
913
1014export default route ;
You can’t perform that action at this time.
0 commit comments