1
- import { Controller , Get , Param , Query , Post , Put , Delete , HttpCode , HttpStatus , ParseIntPipe , UsePipes , Body } from '@nestjs/common' ;
1
+ import { Controller , Get , Param , Query , Post , Put , Delete , HttpCode , HttpStatus , ParseIntPipe , UsePipes , Body , UseGuards } from '@nestjs/common' ;
2
2
import { JoiValidationPipe } from '../../../../pipe/joi-validation.pipe'
3
3
import { UsersService } from './../../services/users/users.service' ;
4
4
import { createUserSchema } from './../../../../schemas/user.schema' ;
5
5
6
+
7
+ import { JwtAuthGuard } from '../../../../modules/auth/guards/jwt-auth.guard'
8
+ import { RolesGuard } from '../../../../modules/auth/guards/roles.guard'
9
+ import { Public } from '../../../../modules/auth/decorators/public.decorator'
10
+ import { Roles } from '../../../../modules/auth/decorators/roles.decorator'
11
+ import { Role } from '../../../../entities/user.entity'
12
+
13
+ @UseGuards ( JwtAuthGuard , RolesGuard )
6
14
@Controller ( 'users' )
7
15
export class UsersController {
8
16
constructor ( private usersService : UsersService ) { }
17
+
18
+ @Public ( )
9
19
@Post ( )
10
20
@HttpCode ( HttpStatus . CREATED )
11
21
@UsePipes ( new JoiValidationPipe ( createUserSchema ) )
@@ -17,30 +27,33 @@ export class UsersController {
17
27
}
18
28
19
29
20
- /* @Get (":id")
30
+ @Get ( ":id" )
21
31
@HttpCode ( HttpStatus . FOUND )
32
+ @Roles ( Role . ADMIN )
22
33
async get ( @Param ( "id" , ParseIntPipe ) id : number ) : Promise < object > {
23
- return { data: await this.languageService .get(id) }
24
- }*/
25
- /**/
26
- @ Get ( )
27
- @ HttpCode ( HttpStatus . FOUND )
28
- async list ( @Query ( ) params : any ) : Promise < object > {
29
- return { data : await this . usersService . list ( params ) }
30
- } /*
34
+ return { data : await this . usersService . get ( id ) }
35
+ }
36
+ @ Get ( )
37
+ @ HttpCode ( HttpStatus . FOUND )
38
+ @ Roles ( Role . ADMIN )
39
+ async list ( @Query ( ) params : any ) : Promise < object > {
40
+ return { data : await this . usersService . list ( params ) }
41
+ }
31
42
32
- @Put (":id")
33
- @HttpCode (HttpStatus.ACCEPTED)
34
- async update(@Param("id", ParseIntPipe) id: number, @Body(new JoiValidationPipe(createUserSchema)) payload: any): Promise<object> {
35
- return { msg: "updated", data: await this.usersService.update(id, payload) }
36
- }
43
+ @Put ( ":id" )
44
+ @HttpCode ( HttpStatus . ACCEPTED )
45
+ @Roles ( Role . ADMIN )
46
+ async update ( @Param ( "id" , ParseIntPipe ) id : number , @Body ( new JoiValidationPipe ( createUserSchema ) ) payload : any ) : Promise < object > {
47
+ return { msg : "updated" , data : await this . usersService . update ( id , payload ) }
48
+ }
49
+
50
+ @Delete ( ":id" )
51
+ @HttpCode ( HttpStatus . OK )
52
+ @Roles ( Role . ADMIN )
53
+ async delete ( @Param ( "id" , ParseIntPipe ) id : number ) : Promise < object > {
54
+ let deleted = await this . usersService . delete ( id )
55
+ return { msg : "deleted" }
56
+ }
37
57
38
- @Delete (":id")
39
- @HttpCode (HttpStatus.OK)
40
- async delete(@Param("id", ParseIntPipe) id: number): Promise<object> {
41
- let deleted = await this.usersService.delete(id)
42
- return { msg: "deleted" }
43
- }
44
- */
45
58
}
46
59
0 commit comments