@@ -15,7 +15,7 @@ export class UserController implements AbstractAssemblage {
1515 @Get ( '/' )
1616 public findAll ( _req : Request , res : Response ) {
1717 const users = this . repository . findAll ( ) ;
18- res . status ( 200 ) . send ( JSON . stringify ( users || [ ] ) ) ;
18+ res . status ( 200 ) . json ( Array . isArray ( users ) ? users : [ ] ) ;
1919 }
2020
2121 @Head ( '/headers' )
@@ -29,50 +29,52 @@ export class UserController implements AbstractAssemblage {
2929
3030 @Get ( '/id/:id' )
3131 public findById ( req : Request , res : Response ) {
32- const user = this . repository . findById ( req . params . id ) ;
32+ const id = String ( req . params . id ) . trim ( ) ;
33+ const user = this . repository . findById ( id ) ;
3334 if ( ! user ) {
3435 res . sendStatus ( 404 ) ;
36+ return ;
3537 }
36- res . status ( 200 ) . send ( JSON . stringify ( user ) ) ;
38+ res . status ( 200 ) . json ( user ) ;
3739 }
3840
3941 @Get ( '/gender/:gender' )
4042 public findByGender ( req : Request , res : Response ) {
41- const user = this . repository . findByGender ( req . params . gender ) ;
43+ const gender = String ( req . params . gender ) . trim ( ) ;
44+ const user = this . repository . findByGender ( gender ) ;
4245 if ( ! user ) {
4346 res . sendStatus ( 404 ) ;
47+ return ;
4448 }
45- res . status ( 200 ) . send (
46- JSON . stringify ( {
47- ...user ,
48- } )
49- ) ;
49+ res . status ( 200 ) . json ( user ) ;
5050 }
5151
5252 @Post ( '/' )
5353 public create ( req : Request , res : Response ) {
5454 const user = this . repository . create ( req . body ) ;
55- res . status ( 201 ) . send ( JSON . stringify ( user ) ) ;
55+ res . status ( 201 ) . json ( user ) ;
5656 }
5757
5858 @Put ( '/replace/:id' )
5959 public replace ( req : Request , res : Response ) {
60- const user = this . repository . modify ( req . params . id , req . body ) ;
60+ const id = String ( req . params . id ) . trim ( ) ;
61+ const user = this . repository . modify ( id , req . body ) ;
6162 if ( ! user ) {
6263 res . sendStatus ( 404 ) ;
6364 return ;
6465 }
65- res . status ( 200 ) . send ( JSON . stringify ( user ) ) ;
66+ res . status ( 200 ) . json ( user ) ;
6667 }
6768
6869 @Patch ( '/modify/:id' )
6970 public modify ( req : Request , res : Response ) {
70- const user = this . repository . modify ( req . params . id , req . body ) ;
71+ const id = String ( req . params . id ) . trim ( ) ;
72+ const user = this . repository . modify ( id , req . body ) ;
7173 if ( ! user ) {
7274 res . sendStatus ( 404 ) ;
7375 return ;
7476 }
75- res . status ( 200 ) . send ( JSON . stringify ( user ) ) ;
77+ res . status ( 200 ) . json ( user ) ;
7678 }
7779 /*
7880 @All ('/')
0 commit comments