From e00a0e9c283f39b6ac48e9e2e1ac8d12dd6e317a Mon Sep 17 00:00:00 2001
From: Chiquita Ahsanunnisa <16521248@mahasiswa.itb.ac.id>
Date: Wed, 10 Apr 2024 00:32:43 +0700
Subject: [PATCH] fix: create account validation

---
 src/akun/akun.controller.ts | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/akun/akun.controller.ts b/src/akun/akun.controller.ts
index de104a2..8b3745b 100644
--- a/src/akun/akun.controller.ts
+++ b/src/akun/akun.controller.ts
@@ -25,14 +25,14 @@ import { JwtAuthGuard } from "src/middlewares/jwt-auth.guard";
 import { ApiCookieAuth, ApiOkResponse, ApiTags } from "@nestjs/swagger";
 
 @ApiTags("Akun")
-@ApiCookieAuth()
 @Controller("akun")
-@UseGuards(JwtAuthGuard, RolesGuard)
-@Roles(RoleEnum.ADMIN, RoleEnum.S1_TIM_TA, RoleEnum.S2_TIM_TESIS)
 export class AkunController {
   constructor(private akunService: AkunService) {}
 
+  @ApiCookieAuth()
   @ApiOkResponse({ type: FindAllResDto })
+  @UseGuards(JwtAuthGuard, RolesGuard)
+  @Roles(RoleEnum.ADMIN, RoleEnum.S1_TIM_TA, RoleEnum.S2_TIM_TESIS)
   @Get("/")
   findAll(@Query() query: FindAllQueryDto): Promise<FindAllResDto> {
     return this.akunService.findAll(
@@ -42,23 +42,33 @@ export class AkunController {
     );
   }
 
+  @ApiCookieAuth()
   @ApiOkResponse({ type: Pengguna })
+  @UseGuards(JwtAuthGuard, RolesGuard)
+  @Roles(RoleEnum.ADMIN, RoleEnum.S1_TIM_TA, RoleEnum.S2_TIM_TESIS)
   @Get("/:id")
   findById(@Param() param: ByIdParamDto): Promise<Pengguna> {
     return this.akunService.findById(param.id);
   }
 
+  // TODO: protect/secure this endpoint
   @Put("/")
   createOrUpdateAccount(@Body() createAkunDto: CreateAkunDto) {
     return this.akunService.createOrUpdateAccount(createAkunDto);
   }
 
+  @ApiCookieAuth()
+  @UseGuards(JwtAuthGuard, RolesGuard)
+  @Roles(RoleEnum.ADMIN, RoleEnum.S1_TIM_TA, RoleEnum.S2_TIM_TESIS)
   @Delete("/:id")
   deleteAccount(@Param() param: ByIdParamDto) {
     return this.akunService.deleteAccount(param.id);
   }
 
+  @ApiCookieAuth()
   @ApiOkResponse({ type: BatchUpdateRoleRespDto })
+  @UseGuards(JwtAuthGuard, RolesGuard)
+  @Roles(RoleEnum.ADMIN, RoleEnum.S1_TIM_TA, RoleEnum.S2_TIM_TESIS)
   @Patch("/roles-batch")
   batchUpdateRole(
     @Body() batchUpdateRoleDto: BatchUpdateRoleDto,
-- 
GitLab