From a8ec56b564595d188d7a1e5693cfdab3fa1b6017 Mon Sep 17 00:00:00 2001
From: Chiquita Ahsanunnisa <16521248@mahasiswa.itb.ac.id>
Date: Wed, 17 Apr 2024 16:43:50 +0700
Subject: [PATCH] hotfix: restore deleted module

---
 src/app.module.ts                             |  2 ++
 .../dosen-bimbingan.controller.ts             | 34 +++++++++++++++++++
 src/dosen-bimbingan/dosen-bimbingan.dto.ts    | 17 ++++++++++
 src/dosen-bimbingan/dosen-bimbingan.module.ts | 21 ++++++++++++
 .../dosen-bimbingan.service.ts                | 25 ++++++++++++++
 5 files changed, 99 insertions(+)
 create mode 100644 src/dosen-bimbingan/dosen-bimbingan.controller.ts
 create mode 100644 src/dosen-bimbingan/dosen-bimbingan.dto.ts
 create mode 100644 src/dosen-bimbingan/dosen-bimbingan.module.ts
 create mode 100644 src/dosen-bimbingan/dosen-bimbingan.service.ts

diff --git a/src/app.module.ts b/src/app.module.ts
index e512e01..d396e6c 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -35,6 +35,7 @@ import { SubmisiTugas } from "./entities/submisiTugas";
 import { KelasModule } from "./kelas/kelas.module";
 import { BerkasSubmisiTugas } from "./entities/berkasSubmisiTugas";
 import { BerkasTugas } from "./entities/berkasTugas";
+import { DosenBimbinganModule } from './dosen-bimbingan/dosen-bimbingan.module';
 
 @Module({
   imports: [
@@ -82,6 +83,7 @@ import { BerkasTugas } from "./entities/berkasTugas";
     BimbinganModule,
     KonfigurasiModule,
     KelasModule,
+    DosenBimbinganModule,
   ],
   controllers: [AppController],
   providers: [AppService],
diff --git a/src/dosen-bimbingan/dosen-bimbingan.controller.ts b/src/dosen-bimbingan/dosen-bimbingan.controller.ts
new file mode 100644
index 0000000..81a3167
--- /dev/null
+++ b/src/dosen-bimbingan/dosen-bimbingan.controller.ts
@@ -0,0 +1,34 @@
+import { Controller, Get, UseGuards } from "@nestjs/common";
+import {
+  ApiBearerAuth,
+  ApiCookieAuth,
+  ApiOkResponse,
+  ApiOperation,
+  ApiTags,
+} from "@nestjs/swagger";
+import { RoleEnum } from "src/entities/pengguna.entity";
+import { CustomAuthGuard } from "src/middlewares/custom-auth.guard";
+import { Roles } from "src/middlewares/roles.decorator";
+import { RolesGuard } from "src/middlewares/roles.guard";
+import { GetDosbimResDto } from "./dosen-bimbingan.dto";
+import { DosenBimbinganService } from "./dosen-bimbingan.service";
+
+@ApiTags("Dosen Bimbingan")
+@ApiCookieAuth()
+@ApiBearerAuth()
+@Controller("dosen-bimbingan")
+@UseGuards(CustomAuthGuard, RolesGuard)
+@Roles(RoleEnum.ADMIN, RoleEnum.S2_TIM_TESIS, RoleEnum.S2_MAHASISWA)
+export class DosenBimbinganController {
+  constructor(private readonly dosbimService: DosenBimbinganService) {}
+
+  @ApiOkResponse({ type: [GetDosbimResDto] })
+  @ApiOperation({
+    summary:
+      "Get all available dosen bimbingan. Roles: ADMIN, S2_TIM_TESIS, S2_MAHASISWA",
+  })
+  @Get()
+  async get() {
+    return await this.dosbimService.getAll();
+  }
+}
diff --git a/src/dosen-bimbingan/dosen-bimbingan.dto.ts b/src/dosen-bimbingan/dosen-bimbingan.dto.ts
new file mode 100644
index 0000000..23c823e
--- /dev/null
+++ b/src/dosen-bimbingan/dosen-bimbingan.dto.ts
@@ -0,0 +1,17 @@
+import { IsOptional } from "@nestjs/class-validator";
+import { ApiPropertyOptional, PickType } from "@nestjs/swagger";
+import { IsUUID } from "class-validator";
+import { Pengguna } from "src/entities/pengguna.entity";
+
+export class DosbimOptQueryDto {
+  @ApiPropertyOptional({ example: "550e8400-e29b-41d4-a716-446655440000" })
+  @IsOptional()
+  @IsUUID()
+  regId?: string;
+}
+
+export class GetDosbimResDto extends PickType(Pengguna, [
+  "id",
+  "email",
+  "nama",
+] as const) {}
diff --git a/src/dosen-bimbingan/dosen-bimbingan.module.ts b/src/dosen-bimbingan/dosen-bimbingan.module.ts
new file mode 100644
index 0000000..1929f62
--- /dev/null
+++ b/src/dosen-bimbingan/dosen-bimbingan.module.ts
@@ -0,0 +1,21 @@
+import { Module } from "@nestjs/common";
+import { DosenBimbinganController } from "./dosen-bimbingan.controller";
+import { DosenBimbinganService } from "./dosen-bimbingan.service";
+import { AuthModule } from "src/auth/auth.module";
+import { TypeOrmModule } from "@nestjs/typeorm";
+import { PendaftaranTesis } from "src/entities/pendaftaranTesis.entity";
+import { DosenBimbingan } from "src/entities/dosenBimbingan.entity";
+import { Pengguna } from "src/entities/pengguna.entity";
+import { KonfigurasiModule } from "src/konfigurasi/konfigurasi.module";
+import { CustomStrategy } from "src/middlewares/custom.strategy";
+
+@Module({
+  imports: [
+    TypeOrmModule.forFeature([PendaftaranTesis, DosenBimbingan, Pengguna]),
+    AuthModule,
+    KonfigurasiModule,
+  ],
+  controllers: [DosenBimbinganController],
+  providers: [DosenBimbinganService, CustomStrategy],
+})
+export class DosenBimbinganModule {}
diff --git a/src/dosen-bimbingan/dosen-bimbingan.service.ts b/src/dosen-bimbingan/dosen-bimbingan.service.ts
new file mode 100644
index 0000000..88f0f9d
--- /dev/null
+++ b/src/dosen-bimbingan/dosen-bimbingan.service.ts
@@ -0,0 +1,25 @@
+import { Injectable } from "@nestjs/common";
+import { InjectRepository } from "@nestjs/typeorm";
+import { Pengguna, RoleEnum } from "src/entities/pengguna.entity";
+import { ArrayContains, Repository } from "typeorm";
+
+@Injectable()
+export class DosenBimbinganService {
+  constructor(
+    @InjectRepository(Pengguna)
+    private penggunaRepo: Repository<Pengguna>,
+  ) {}
+
+  async getAll() {
+    return await this.penggunaRepo.find({
+      select: {
+        id: true,
+        nama: true,
+        email: true,
+      },
+      where: {
+        roles: ArrayContains([RoleEnum.S2_PEMBIMBING]),
+      },
+    });
+  }
+}
-- 
GitLab