1- import { injectable , inject } from 'inversify' ;
1+ import { injectable , inject , named } from 'inversify' ;
22import { Controller , Get , Post , Put , Delete , RequestParam , RequestBody , Response , Request } from 'inversify-express-utils' ;
33import { my } from 'my-express' ;
4- import { Log } from '../../core/log' ;
54import { UserService } from '../services/UsersService' ;
65import { Types } from '../../constants/Types' ;
6+ import { Service } from '../../constants/Targets' ;
77import { authenticate , populateUser } from '../middlewares' ;
88
9- const log = new Log ( 'api:ctrl.UserController' ) ;
10-
119/**
1210 * UserController is in charge of the user resource and should
1311 * provide all crud actions.
@@ -16,45 +14,39 @@ const log = new Log('api:ctrl.UserController');
1614@Controller ( '/user' , authenticate )
1715export class UserController {
1816
19- constructor ( @inject ( Types . UserService ) private userService : UserService ) { }
17+ constructor ( @inject ( Types . Service ) @ named ( Service . UserService ) private userService : UserService ) { }
2018
2119 @Get ( '/' )
2220 public async findAll ( @Response ( ) res : my . Response ) : Promise < any > {
23- log . debug ( 'findAll' ) ;
2421 const users = await this . userService . findAll ( ) ;
2522 return res . found ( users . toJSON ( ) ) ;
2623 }
2724
2825 @Post ( '/' )
2926 public async create ( @Response ( ) res : my . Response , @RequestBody ( ) body : any ) : Promise < any > {
30- log . debug ( 'create ' , body ) ;
3127 const user = await this . userService . create ( body ) ;
3228 return res . created ( user . toJSON ( ) ) ;
3329 }
3430
3531 @Get ( '/me' , populateUser )
3632 public async findMe ( @Request ( ) req : my . Request , @Response ( ) res : my . Response ) : Promise < any > {
37- log . debug ( 'findMe' ) ;
3833 return res . found ( req . user ) ;
3934 }
4035
4136 @Get ( '/:id' )
4237 public async findOne ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string ) : Promise < any > {
43- log . debug ( 'findOne ' , id ) ;
4438 const user = await this . userService . findOne ( parseInt ( id , 10 ) ) ;
4539 return res . found ( user . toJSON ( ) ) ;
4640 }
4741
4842 @Put ( '/:id' )
4943 public async update ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string , @RequestBody ( ) body : any ) : Promise < any > {
50- log . debug ( 'update ' , body ) ;
5144 const user = await this . userService . update ( parseInt ( id , 10 ) , body ) ;
5245 return res . updated ( user . toJSON ( ) ) ;
5346 }
5447
5548 @Delete ( '/:id' )
5649 public async destroy ( @Response ( ) res : my . Response , @RequestParam ( 'id' ) id : string ) : Promise < any > {
57- log . debug ( 'destroy ' , id ) ;
5850 await this . userService . destroy ( parseInt ( id , 10 ) ) ;
5951 return res . destroyed ( ) ;
6052 }
0 commit comments