From 755c4a9a76688db4371ba945eec3030d2b98d4de Mon Sep 17 00:00:00 2001
From: Chiquita Ahsanunnisa <16521248@mahasiswa.itb.ac.id>
Date: Wed, 1 May 2024 15:25:59 +0700
Subject: [PATCH] refactor: remove periode and its effect

---
 src/alokasi-topik/alokasi-topik.controller.ts |  30 +---
 src/alokasi-topik/alokasi-topik.module.ts     |   3 +-
 src/alokasi-topik/alokasi-topik.service.ts    |  25 +--
 src/bimbingan/bimbingan.controller.ts         |  20 +--
 src/bimbingan/bimbingan.dto.ts                |   1 -
 src/bimbingan/bimbingan.module.ts             |   2 -
 src/bimbingan/bimbingan.service.ts            |  33 +---
 src/dashboard/dashboard.module.ts             |   2 -
 src/dashboard/dashboard.service.ts            |  35 +----
 src/dosen-bimbingan/dosen-bimbingan.module.ts |   2 -
 src/entities/topik.entity.ts                  |   4 -
 src/main.ts                                   |   5 -
 .../registrasi-tesis.controller.ts            |  71 ---------
 .../registrasi-tesis.module.ts                |   2 -
 .../registrasi-tesis.service.ts               | 145 ++++++++++--------
 15 files changed, 104 insertions(+), 276 deletions(-)

diff --git a/src/alokasi-topik/alokasi-topik.controller.ts b/src/alokasi-topik/alokasi-topik.controller.ts
index 6fa4e26..ed647d0 100644
--- a/src/alokasi-topik/alokasi-topik.controller.ts
+++ b/src/alokasi-topik/alokasi-topik.controller.ts
@@ -1,5 +1,4 @@
 import {
-  BadRequestException,
   Body,
   Controller,
   Delete,
@@ -18,7 +17,6 @@ import {
   ApiTags,
 } from "@nestjs/swagger";
 import { RoleEnum } from "src/entities/pengguna.entity";
-import { KonfigurasiService } from "src/konfigurasi/konfigurasi.service";
 import { CustomAuthGuard } from "src/middlewares/custom-auth.guard";
 import { Roles } from "src/middlewares/roles.decorator";
 import { RolesGuard } from "src/middlewares/roles.guard";
@@ -41,35 +39,20 @@ import { AlokasiTopikService } from "./alokasi-topik.service";
 @Controller("alokasi-topik")
 @UseGuards(CustomAuthGuard, RolesGuard)
 export class AlokasiTopikController {
-  constructor(
-    private alokasiTopikService: AlokasiTopikService,
-    private konfService: KonfigurasiService,
-  ) {}
+  constructor(private alokasiTopikService: AlokasiTopikService) {}
 
   @ApiOkResponse({ type: CreateRespDto })
   @Roles(RoleEnum.S2_TIM_TESIS, RoleEnum.ADMIN)
   @Post()
   async create(@Body() createDto: CreateTopikDto) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) throw new BadRequestException("Periode belum dikonfigurasi.");
-
-    return await this.alokasiTopikService.create({ ...createDto, periode });
+    return await this.alokasiTopikService.create({ ...createDto });
   }
 
   @ApiOkResponse({ type: createBulkRespDto })
   @Roles(RoleEnum.S2_TIM_TESIS, RoleEnum.ADMIN)
   @Post("/bulk")
   async createBulk(@Body() createDto: CreateBulkTopikDto) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) throw new BadRequestException("Periode belum dikonfigurasi.");
-
-    return await this.alokasiTopikService.createBulk(createDto, periode);
+    return await this.alokasiTopikService.createBulk(createDto);
   }
 
   @ApiOkResponse({ type: OmittedTopik })
@@ -88,16 +71,9 @@ export class AlokasiTopikController {
     @Query()
     query: TopikQueryDto,
   ) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) throw new BadRequestException("Periode belum dikonfigurasi.");
-
     return await this.alokasiTopikService.findAllCreatedByPembimbing({
       page: query.page || 1,
       ...query,
-      periode,
     });
   }
 
diff --git a/src/alokasi-topik/alokasi-topik.module.ts b/src/alokasi-topik/alokasi-topik.module.ts
index e9769a4..f7daaff 100644
--- a/src/alokasi-topik/alokasi-topik.module.ts
+++ b/src/alokasi-topik/alokasi-topik.module.ts
@@ -5,10 +5,9 @@ import { TypeOrmModule } from "@nestjs/typeorm";
 import { Topik } from "src/entities/topik.entity";
 import { CustomStrategy } from "src/middlewares/custom.strategy";
 import { AuthModule } from "src/auth/auth.module";
-import { KonfigurasiModule } from "src/konfigurasi/konfigurasi.module";
 
 @Module({
-  imports: [TypeOrmModule.forFeature([Topik]), AuthModule, KonfigurasiModule],
+  imports: [TypeOrmModule.forFeature([Topik]), AuthModule],
   providers: [AlokasiTopikService, CustomStrategy],
   controllers: [AlokasiTopikController],
 })
diff --git a/src/alokasi-topik/alokasi-topik.service.ts b/src/alokasi-topik/alokasi-topik.service.ts
index b9056ab..3ead15a 100644
--- a/src/alokasi-topik/alokasi-topik.service.ts
+++ b/src/alokasi-topik/alokasi-topik.service.ts
@@ -16,35 +16,26 @@ import {
 export class AlokasiTopikService {
   constructor(@InjectRepository(Topik) private topikRepo: Repository<Topik>) {}
 
-  async create(
-    createDto: CreateTopikDto & { periode: string },
-  ): Promise<CreateRespDto> {
+  async create(createDto: CreateTopikDto): Promise<CreateRespDto> {
     const ids = (await this.topikRepo.insert(createDto)).identifiers;
 
     return { id: ids[0].id };
   }
 
-  async createBulk(
-    createDto: CreateBulkTopikDto,
-    periode: string,
-  ): Promise<createBulkRespDto> {
+  async createBulk(createDto: CreateBulkTopikDto): Promise<createBulkRespDto> {
     const ids = (
-      await this.topikRepo.insert(
-        createDto.data.map((dto) => ({ ...dto, periode })),
-      )
+      await this.topikRepo.insert(createDto.data.map((dto) => ({ ...dto })))
     ).identifiers;
 
     return { ids: ids.map(({ id }) => id) };
   }
 
   async findById(id: string) {
-    // not periode-protected
     return await this.topikRepo.findOne({
       select: {
         id: true,
         judul: true,
         deskripsi: true,
-        periode: true,
         pengaju: {
           id: true,
           nama: true,
@@ -66,14 +57,12 @@ export class AlokasiTopikService {
     limit?: number;
     search?: string;
     idPembimbing?: string;
-    periode: string;
   }): Promise<GetAllRespDto> {
     const dataQuery = this.topikRepo.find({
       select: {
         id: true,
         judul: true,
         deskripsi: true,
-        periode: true,
         pengaju: {
           id: true,
           nama: true,
@@ -82,7 +71,6 @@ export class AlokasiTopikService {
         },
       },
       where: {
-        periode: options.periode,
         pengaju: {
           id: options.idPembimbing || undefined,
           roles: ArrayContains([RoleEnum.S2_PEMBIMBING]),
@@ -107,8 +95,7 @@ export class AlokasiTopikService {
         .createQueryBuilder("topik")
         .select("topik.id")
         .innerJoinAndSelect("topik.pengaju", "pengaju")
-        .where("topik.periode = :periode", { periode: options.periode })
-        .andWhere("pengaju.roles @> :role", {
+        .where("pengaju.roles @> :role", {
           role: [RoleEnum.S2_PEMBIMBING],
         });
 
@@ -143,12 +130,10 @@ export class AlokasiTopikService {
   }
 
   async update(id: string, updateDto: UpdateTopikDto) {
-    // not periode-protected
     return await this.topikRepo.update(id, updateDto);
   }
 
   async remove(id: string) {
-    // not periode-protected
-    return await this.topikRepo.delete({ id }); // TODO: manage relation cascading option
+    return await this.topikRepo.delete({ id }); // TODO: cascade?
   }
 }
diff --git a/src/bimbingan/bimbingan.controller.ts b/src/bimbingan/bimbingan.controller.ts
index 99eab5d..4f03874 100644
--- a/src/bimbingan/bimbingan.controller.ts
+++ b/src/bimbingan/bimbingan.controller.ts
@@ -45,9 +45,7 @@ export class BimbinganController {
   constructor(private readonly bimbinganService: BimbinganService) {}
 
   @ApiOkResponse({ type: GetByMahasiswaIdResDto })
-  @ApiNotFoundResponse({
-    description: "Tidak ada pendaftaran pada periode sekarang",
-  })
+  @ApiNotFoundResponse({ description: "Tidak ada pendaftaran" })
   @Roles(RoleEnum.S2_PEMBIMBING, RoleEnum.ADMIN, RoleEnum.S2_TIM_TESIS)
   @Get("/mahasiswa/:mahasiswaId")
   async getByMahasiswaId(
@@ -61,9 +59,7 @@ export class BimbinganController {
   }
 
   @ApiOkResponse({ type: GetByMahasiswaIdResDto })
-  @ApiNotFoundResponse({
-    description: "Tidak ada pendaftaran pada periode sekarang",
-  })
+  @ApiNotFoundResponse({ description: "Tidak ada pendaftaran" })
   @Roles(RoleEnum.S2_MAHASISWA)
   @Get("/")
   async getOwnBimbingan(
@@ -80,9 +76,7 @@ export class BimbinganController {
     description:
       "Waktu bimbingan lebih dari hari ini atau bimbingan berikutnya sebelum waktu bimbingan yang dimasukkan",
   })
-  @ApiNotFoundResponse({
-    description: "Tidak ada pendaftaran pada periode sekarang",
-  })
+  @ApiNotFoundResponse({ description: "Tidak ada pendaftaran" })
   @Roles(RoleEnum.S2_MAHASISWA)
   @ApiBody({ type: CreateBimbinganReqDto })
   @Post("/")
@@ -94,9 +88,7 @@ export class BimbinganController {
   }
 
   @ApiOkResponse({ type: UpdateStatusResDto })
-  @ApiNotFoundResponse({
-    description: "Bimbingan tidak ditemukan",
-  })
+  @ApiNotFoundResponse({ description: "Bimbingan tidak ditemukan" })
   @ApiForbiddenResponse({
     description: "Anda tidak memiliki akses untuk mengubah status bimbingan",
   })
@@ -111,9 +103,7 @@ export class BimbinganController {
   }
 
   @ApiOkResponse({ type: GetByBimbinganIdResDto })
-  @ApiNotFoundResponse({
-    description: "Bimbingan tidak ditemukan",
-  })
+  @ApiNotFoundResponse({ description: "Bimbingan tidak ditemukan" })
   @Roles(RoleEnum.S2_PEMBIMBING, RoleEnum.ADMIN)
   @Get("/:bimbinganId")
   async getByBimbinganId(
diff --git a/src/bimbingan/bimbingan.dto.ts b/src/bimbingan/bimbingan.dto.ts
index f3afcda..649f9c9 100644
--- a/src/bimbingan/bimbingan.dto.ts
+++ b/src/bimbingan/bimbingan.dto.ts
@@ -33,7 +33,6 @@ class PickedTopikBimbingan extends PickType(Topik, [
   "judul",
   "deskripsi",
   "idPengaju",
-  "periode",
 ] as const) {}
 
 export class GetByMahasiswaIdResDto {
diff --git a/src/bimbingan/bimbingan.module.ts b/src/bimbingan/bimbingan.module.ts
index 30174c6..e38f360 100644
--- a/src/bimbingan/bimbingan.module.ts
+++ b/src/bimbingan/bimbingan.module.ts
@@ -4,7 +4,6 @@ import { BimbinganService } from "./bimbingan.service";
 import { TypeOrmModule } from "@nestjs/typeorm";
 import { Bimbingan } from "src/entities/bimbingan.entity";
 import { PendaftaranTesis } from "src/entities/pendaftaranTesis.entity";
-import { Konfigurasi } from "src/entities/konfigurasi.entity";
 import { DosenBimbingan } from "src/entities/dosenBimbingan.entity";
 import { BerkasBimbingan } from "src/entities/berkasBimbingan.entity";
 
@@ -13,7 +12,6 @@ import { BerkasBimbingan } from "src/entities/berkasBimbingan.entity";
     TypeOrmModule.forFeature([
       Bimbingan,
       PendaftaranTesis,
-      Konfigurasi,
       DosenBimbingan,
       BerkasBimbingan,
     ]),
diff --git a/src/bimbingan/bimbingan.service.ts b/src/bimbingan/bimbingan.service.ts
index 52c1ba2..44a2824 100644
--- a/src/bimbingan/bimbingan.service.ts
+++ b/src/bimbingan/bimbingan.service.ts
@@ -9,7 +9,6 @@ import * as dayjs from "dayjs";
 import { AuthDto } from "src/auth/auth.dto";
 import { Bimbingan, BimbinganStatus } from "src/entities/bimbingan.entity";
 import { DosenBimbingan } from "src/entities/dosenBimbingan.entity";
-import { Konfigurasi } from "src/entities/konfigurasi.entity";
 import {
   PendaftaranTesis,
   RegStatus,
@@ -33,8 +32,6 @@ export class BimbinganService {
     private bimbinganRepository: Repository<Bimbingan>,
     @InjectRepository(PendaftaranTesis)
     private pendaftaranTesisRepository: Repository<PendaftaranTesis>,
-    @InjectRepository(Konfigurasi)
-    private konfigurasiRepository: Repository<Konfigurasi>,
     @InjectRepository(DosenBimbingan)
     private dosenBimbinganRepository: Repository<DosenBimbingan>,
     @InjectRepository(BerkasBimbingan)
@@ -45,17 +42,10 @@ export class BimbinganService {
     mahasiswaId: string,
     user: AuthDto,
   ): Promise<GetByMahasiswaIdResDto> {
-    const currentPeriode = await this.konfigurasiRepository.findOne({
-      where: { key: process.env.KONF_PERIODE_KEY },
-    });
-
     const pendaftaran = await this.pendaftaranTesisRepository.findOne({
       where: {
         mahasiswa: { id: mahasiswaId },
         status: RegStatus.APPROVED,
-        topik: {
-          periode: currentPeriode.value,
-        },
       },
       relations: {
         mahasiswa: true,
@@ -65,9 +55,7 @@ export class BimbinganService {
     });
 
     if (!pendaftaran) {
-      throw new NotFoundException(
-        "Tidak ada pendaftaran yang disetujui pada periode ini",
-      );
+      throw new NotFoundException("Tidak ada pendaftaran yang disetujui");
     }
 
     // Validate bimbingan data by its dosbim
@@ -119,17 +107,10 @@ export class BimbinganService {
     createDto: CreateBimbinganReqDto,
   ): Promise<CreateBimbinganResDto> {
     // Check if user registered in bimbingan
-    const currentPeriode = await this.konfigurasiRepository.findOne({
-      where: { key: process.env.KONF_PERIODE_KEY },
-    });
-
     const pendaftaran = await this.pendaftaranTesisRepository.findOne({
       where: {
         mahasiswa: { id: mahasiswaId },
         status: RegStatus.APPROVED,
-        topik: {
-          periode: currentPeriode.value,
-        },
       },
       relations: {
         mahasiswa: true,
@@ -139,9 +120,7 @@ export class BimbinganService {
     });
 
     if (!pendaftaran) {
-      throw new NotFoundException(
-        "Tidak ada pendaftaran yang disetujui pada periode ini",
-      );
+      throw new NotFoundException("Tidak ada pendaftaran yang disetujui");
     }
 
     if (dayjs(createDto.waktuBimbingan).isAfter(dayjs(new Date()).endOf("d")))
@@ -195,19 +174,13 @@ export class BimbinganService {
     user: AuthDto,
     bimbinganId: string,
   ): Promise<GetByBimbinganIdResDto> {
-    const currentPeriode = await this.konfigurasiRepository.findOne({
-      where: { key: process.env.KONF_PERIODE_KEY },
-    });
-
     const bimbinganQuery = this.bimbinganRepository
       .createQueryBuilder("bimbingan")
       .leftJoinAndSelect("bimbingan.pendaftaran", "pendaftaran")
       .leftJoinAndSelect("pendaftaran.dosenBimbingan", "dosenBimbingan")
       .leftJoinAndSelect("dosenBimbingan.dosen", "dosen")
       .leftJoinAndSelect("bimbingan.berkas", "berkas")
-      .leftJoin("pendaftaran.topik", "topik", "topik.periode = :periode", {
-        periode: currentPeriode.value,
-      })
+      .leftJoin("pendaftaran.topik", "topik")
       .leftJoinAndSelect("pendaftaran.mahasiswa", "mahasiswa")
       .where("bimbingan.id = :id", { id: bimbinganId });
     const bimbingan = await bimbinganQuery.getOne();
diff --git a/src/dashboard/dashboard.module.ts b/src/dashboard/dashboard.module.ts
index 8f8f447..0d4da49 100644
--- a/src/dashboard/dashboard.module.ts
+++ b/src/dashboard/dashboard.module.ts
@@ -5,7 +5,6 @@ import { DashboardService } from "./dashboard.service";
 import { PendaftaranTesis } from "../entities/pendaftaranTesis.entity";
 import { Pengguna } from "../entities/pengguna.entity";
 import { Topik } from "../entities/topik.entity";
-import { Konfigurasi } from "src/entities/konfigurasi.entity";
 import { Bimbingan } from "src/entities/bimbingan.entity";
 import { PendaftaranSidsem } from "src/entities/pendaftaranSidsem";
 import { DosenBimbingan } from "src/entities/dosenBimbingan.entity";
@@ -17,7 +16,6 @@ import { BimbinganModule } from "src/bimbingan/bimbingan.module";
       PendaftaranTesis,
       Pengguna,
       Topik,
-      Konfigurasi,
       Bimbingan,
       PendaftaranSidsem,
       DosenBimbingan,
diff --git a/src/dashboard/dashboard.service.ts b/src/dashboard/dashboard.service.ts
index c2bfcb1..d6b71ae 100644
--- a/src/dashboard/dashboard.service.ts
+++ b/src/dashboard/dashboard.service.ts
@@ -6,7 +6,6 @@ import {
   RegStatus,
 } from "../entities/pendaftaranTesis.entity";
 import { Pengguna } from "../entities/pengguna.entity";
-import { Konfigurasi } from "src/entities/konfigurasi.entity";
 import { Bimbingan } from "src/entities/bimbingan.entity";
 import {
   DashboardDto,
@@ -28,8 +27,6 @@ export class DashboardService {
     private pendaftaranTesisRepository: Repository<PendaftaranTesis>,
     @InjectRepository(Pengguna)
     private penggunaRepository: Repository<Pengguna>,
-    @InjectRepository(Konfigurasi)
-    private konfigurasiRepository: Repository<Konfigurasi>,
     @InjectRepository(Bimbingan)
     private bimbinganRepository: Repository<Bimbingan>,
     @InjectRepository(PendaftaranSidsem)
@@ -49,14 +46,6 @@ export class DashboardService {
     dosenId: string,
     search?: string,
   ): Promise<DashboardDto[]> {
-    const currentPeriode = await this.konfigurasiRepository.findOne({
-      where: { key: process.env.KONF_PERIODE_KEY },
-    });
-
-    if (!currentPeriode) {
-      throw new BadRequestException("Periode belum dikonfigurasi");
-    }
-
     let pendaftaranTesisQuery = this.pendaftaranTesisRepository
       .createQueryBuilder("pendaftaranTesis")
       .leftJoinAndSelect("pendaftaranTesis.mahasiswa", "mahasiswa")
@@ -71,8 +60,7 @@ export class DashboardService {
       )
       .andWhere("pendaftaranTesis.status = :status", {
         status: RegStatus.APPROVED,
-      })
-      .andWhere("topik.periode = :periode", { periode: currentPeriode.value });
+      });
 
     if (search) {
       pendaftaranTesisQuery = pendaftaranTesisQuery.andWhere(
@@ -112,15 +100,9 @@ export class DashboardService {
   async getStatisticsByJalurPilihan(
     dosenId: string,
   ): Promise<JalurStatisticDto[]> {
-    const [currentPeriode, dosen] = await Promise.all([
-      this.konfigurasiRepository.findOne({
-        where: { key: process.env.KONF_PERIODE_KEY },
-      }),
-      this.penggunaRepository.findOne({
-        where: { id: dosenId },
-      }),
-    ]);
-
+    const dosen = await this.penggunaRepository.findOne({
+      where: { id: dosenId },
+    });
     if (!dosen) {
       throw new BadRequestException("Dosen tidak ditemukan");
     }
@@ -129,9 +111,7 @@ export class DashboardService {
       .createQueryBuilder("pendaftaranTesis")
       .select("pendaftaranTesis.jalurPilihan", "jalurPilihan")
       .addSelect("COUNT(*)", "count")
-      .leftJoin("pendaftaranTesis.topik", "topik", "topik.periode = :periode", {
-        periode: currentPeriode.value,
-      })
+      .leftJoin("pendaftaranTesis.topik", "topik")
       .innerJoin(
         "pendaftaranTesis.dosenBimbingan",
         "dosenBimbingan",
@@ -152,10 +132,6 @@ export class DashboardService {
   async getDashboardMahasiswa(
     mahasiswaId: string,
   ): Promise<DashboardMahasiswaResDto> {
-    const currentPeriode = await this.konfigurasiRepository.findOne({
-      where: { key: process.env.KONF_PERIODE_KEY },
-    });
-
     const mahasiswaQuery = this.penggunaRepository
       .createQueryBuilder("pengguna")
       .select([
@@ -182,7 +158,6 @@ export class DashboardService {
       .leftJoinAndSelect("pendaftaranTesis.topik", "topik")
       .leftJoin("pendaftaranTesis.penerima", "penerima")
       .where("mahasiswa.id = :id", { id: mahasiswaId })
-      .andWhere("topik.periode = :periode", { periode: currentPeriode.value })
       .orderBy("pendaftaranTesis.waktuPengiriman", "DESC");
 
     const [mahasiswa, pendaftaranTesis] = await Promise.all([
diff --git a/src/dosen-bimbingan/dosen-bimbingan.module.ts b/src/dosen-bimbingan/dosen-bimbingan.module.ts
index 1929f62..5fef686 100644
--- a/src/dosen-bimbingan/dosen-bimbingan.module.ts
+++ b/src/dosen-bimbingan/dosen-bimbingan.module.ts
@@ -6,14 +6,12 @@ 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],
diff --git a/src/entities/topik.entity.ts b/src/entities/topik.entity.ts
index 7523412..c3b79e4 100644
--- a/src/entities/topik.entity.ts
+++ b/src/entities/topik.entity.ts
@@ -30,8 +30,4 @@ export class Topik {
   @ApiProperty({ example: "550e8400-e29b-41d4-a716-446655440000" })
   @Column({ nullable: true })
   idPengaju: string;
-
-  @ApiProperty()
-  @Column({ type: "text" })
-  periode: string;
 }
diff --git a/src/main.ts b/src/main.ts
index fdce89e..2f6bfcc 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -25,12 +25,7 @@ async function bootstrap() {
     .addTag("Bimbingan")
     .addTag("Dashboard")
     .addTag("Dosen Bimbingan")
-    .addTag("Kelas")
-    .addTag("Konfigurasi")
-    .addTag("Nilai")
     .addTag("Registrasi Tesis")
-    .addTag("Submisi Tugas")
-    .addTag("Tugas")
     .addCookieAuth(process.env.COOKIE_NAME)
     .addBearerAuth()
     .build();
diff --git a/src/registrasi-tesis/registrasi-tesis.controller.ts b/src/registrasi-tesis/registrasi-tesis.controller.ts
index 9802752..e740095 100644
--- a/src/registrasi-tesis/registrasi-tesis.controller.ts
+++ b/src/registrasi-tesis/registrasi-tesis.controller.ts
@@ -1,5 +1,4 @@
 import {
-  BadRequestException,
   Body,
   Controller,
   ForbiddenException,
@@ -24,7 +23,6 @@ import {
 import { Request } from "express";
 import { AuthDto } from "src/auth/auth.dto";
 import { RoleEnum } from "src/entities/pengguna.entity";
-import { KonfigurasiService } from "src/konfigurasi/konfigurasi.service";
 import { CustomAuthGuard } from "src/middlewares/custom-auth.guard";
 import { Roles } from "src/middlewares/roles.decorator";
 import { RolesGuard } from "src/middlewares/roles.guard";
@@ -51,7 +49,6 @@ import { RegistrasiTesisService } from "./registrasi-tesis.service";
 export class RegistrasiTesisController {
   constructor(
     private readonly registrasiTesisService: RegistrasiTesisService,
-    private readonly konfService: KonfigurasiService,
   ) {}
 
   @ApiOperation({
@@ -72,18 +69,9 @@ export class RegistrasiTesisController {
   ): Promise<IdDto> {
     const { id } = req.user as AuthDto;
 
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     return this.registrasiTesisService.createTopicRegistration(
       id,
       topicRegistrationDto,
-      periode,
     );
   }
 
@@ -108,17 +96,8 @@ export class RegistrasiTesisController {
       }
     }
 
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     return this.registrasiTesisService.findByUserId(
       params.mahasiswaId,
-      periode,
       false,
       undefined,
     );
@@ -147,17 +126,8 @@ export class RegistrasiTesisController {
       idPenerima = id;
     }
 
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     const res = await this.registrasiTesisService.findByUserId(
       params.mahasiswaId,
-      periode,
       true,
       idPenerima,
     );
@@ -180,12 +150,7 @@ export class RegistrasiTesisController {
       throw new ForbiddenException();
     }
 
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
     return this.registrasiTesisService.getRegsStatistics({
-      periode,
       idPenerima: query.view == RoleEnum.S2_PEMBIMBING ? idPenerima : undefined,
     });
   }
@@ -211,20 +176,11 @@ export class RegistrasiTesisController {
       throw new ForbiddenException();
     }
 
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     return await this.registrasiTesisService.findAllRegs({
       ...query,
       page: query.page || 1,
       idPenerima:
         query.view === RoleEnum.S2_PEMBIMBING ? idPenerima : undefined,
-      periode,
     });
   }
 
@@ -241,14 +197,6 @@ export class RegistrasiTesisController {
     @Body() body: UpdateInterviewBodyDto,
     @Req() req: Request,
   ) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     const { id, roles } = req.user as AuthDto;
     let idPenerima = undefined;
 
@@ -262,7 +210,6 @@ export class RegistrasiTesisController {
 
     return await this.registrasiTesisService.updateInterviewDate(
       params.mhsId,
-      periode,
       body,
       idPenerima,
     );
@@ -281,14 +228,6 @@ export class RegistrasiTesisController {
     @Body() body: UpdateStatusBodyDto,
     @Req() req: Request,
   ) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     const { id, roles } = req.user as AuthDto;
     let idPenerima = undefined;
 
@@ -302,7 +241,6 @@ export class RegistrasiTesisController {
 
     return await this.registrasiTesisService.updateStatus(
       params.mhsId,
-      periode,
       body,
       idPenerima,
     );
@@ -320,17 +258,8 @@ export class RegistrasiTesisController {
     @Param() params: UpdateByMhsParamsDto,
     @Body() body: UpdatePembimbingBodyDto,
   ) {
-    const periode = await this.konfService.getKonfigurasiByKey(
-      process.env.KONF_PERIODE_KEY,
-    );
-
-    if (!periode) {
-      throw new BadRequestException("Periode belum dikonfigurasi.");
-    }
-
     return await this.registrasiTesisService.updatePembimbingList(
       params.mhsId,
-      periode,
       body,
     );
   }
diff --git a/src/registrasi-tesis/registrasi-tesis.module.ts b/src/registrasi-tesis/registrasi-tesis.module.ts
index 65926b0..8e177eb 100644
--- a/src/registrasi-tesis/registrasi-tesis.module.ts
+++ b/src/registrasi-tesis/registrasi-tesis.module.ts
@@ -8,7 +8,6 @@ import { RegistrasiTesisService } from "./registrasi-tesis.service";
 import { Topik } from "src/entities/topik.entity";
 import { CustomStrategy } from "src/middlewares/custom.strategy";
 import { AuthModule } from "src/auth/auth.module";
-import { KonfigurasiModule } from "src/konfigurasi/konfigurasi.module";
 
 @Module({
   imports: [
@@ -19,7 +18,6 @@ import { KonfigurasiModule } from "src/konfigurasi/konfigurasi.module";
       Topik,
     ]),
     AuthModule,
-    KonfigurasiModule,
   ],
   controllers: [RegistrasiTesisController],
   providers: [RegistrasiTesisService, CustomStrategy],
diff --git a/src/registrasi-tesis/registrasi-tesis.service.ts b/src/registrasi-tesis/registrasi-tesis.service.ts
index 08e1b84..f3c861c 100644
--- a/src/registrasi-tesis/registrasi-tesis.service.ts
+++ b/src/registrasi-tesis/registrasi-tesis.service.ts
@@ -43,21 +43,18 @@ export class RegistrasiTesisService {
   async createTopicRegistration(
     userId: string,
     topicRegistrationDto: RegDto,
-    periode: string,
   ): Promise<IdDto> {
     const queries: (
       | Promise<void | PendaftaranTesis>
       | Promise<Pengguna>
       | Promise<Topik>
     )[] = [
-      this.getNewestRegByMhsOrFail(userId, periode).catch(
-        (ex: BadRequestException) => {
-          if (ex.message === "No mahasiswa user with given id exists") {
-            throw ex;
-          }
-          // else: mahasiswa does not have pending registration -> allowed
-        },
-      ),
+      this.getNewestRegByMhsOrFail(userId).catch((ex: BadRequestException) => {
+        if (ex.message === "No mahasiswa user with given id exists") {
+          throw ex;
+        }
+        // else: mahasiswa does not have pending registration -> allowed
+      }),
       this.penggunaRepository.findOne({
         where: { id: topicRegistrationDto.idPenerima },
       }),
@@ -104,7 +101,6 @@ export class RegistrasiTesisService {
         judul: topicRegistrationDto.judulTopik,
         deskripsi: topicRegistrationDto.deskripsiTopik,
         idPengaju: userId,
-        periode,
       });
     }
 
@@ -125,7 +121,6 @@ export class RegistrasiTesisService {
 
   async findByUserId(
     mahasiswaId: string,
-    periode: string,
     isNewestOnly: boolean,
     idPenerima?: string,
   ) {
@@ -137,6 +132,7 @@ export class RegistrasiTesisService {
       .addSelect("pt.jalurPilihan")
       .addSelect("pt.waktuPengiriman")
       .addSelect("topik.judul")
+      .addSelect("topik.deskripsi")
       .addSelect("penerima.id")
       .addSelect("penerima.nama")
       .addSelect("penerima.kontak")
@@ -144,14 +140,11 @@ export class RegistrasiTesisService {
       .addSelect("dosen.id")
       .addSelect("dosen.nama")
       .addSelect("dosen.kontak")
-      .addSelect("topik.judul")
-      .addSelect("topik.deskripsi")
       .leftJoin("pt.topik", "topik")
       .leftJoin("pt.penerima", "penerima")
       .leftJoin("pt.dosenBimbingan", "dosenBimbingan")
       .leftJoin("dosenBimbingan.dosen", "dosen")
       .where("pt.mahasiswaId = :mahasiswaId", { mahasiswaId })
-      .andWhere("topik.periode = :periode", { periode })
       .orderBy("pt.waktuPengiriman", "DESC");
 
     const res = await baseQuery.getMany();
@@ -194,7 +187,6 @@ export class RegistrasiTesisService {
   }
 
   async getRegsStatistics(options: {
-    periode: string;
     idPenerima?: string;
   }): Promise<RegStatisticsRespDto> {
     let totalMahasiswa = this.penggunaRepository.count({
@@ -216,33 +208,56 @@ export class RegistrasiTesisService {
         "latest",
         "latest.latest_mahasiswaId = pt.mahasiswaId AND pt.waktuPengiriman = latest.latestPengiriman",
       )
-      .innerJoinAndSelect("pt.topik", "topik")
-      .where("topik.periode = :periode", { periode: options.periode });
+      .innerJoinAndSelect("pt.topik", "topik");
 
     if (options.idPenerima) {
-      baseQuery.andWhere("pt.penerimaId = :idPenerima", {
+      baseQuery.where("pt.penerimaId = :idPenerima", {
         idPenerima: options.idPenerima,
       });
 
       totalMahasiswa = baseQuery.getCount();
     }
 
-    const totalDiterima = baseQuery
-      .clone()
-      .andWhere("pt.status = :status", { status: RegStatus.APPROVED })
-      .getCount();
+    let totalDiterima: Promise<number>;
+    let totalProses: Promise<number>;
+    let totalDitolak: Promise<number>;
 
-    const totalProses = baseQuery
-      .clone()
-      .andWhere("pt.status IN (:...status)", {
-        status: [RegStatus.NOT_ASSIGNED, RegStatus.INTERVIEW],
-      })
-      .getCount();
-
-    const totalDitolak = baseQuery
-      .clone()
-      .andWhere("pt.status = :status", { status: RegStatus.REJECTED })
-      .getCount();
+    if (options.idPenerima) {
+      // where used
+      totalDiterima = baseQuery
+        .clone()
+        .andWhere("pt.status = :status", { status: RegStatus.APPROVED })
+        .getCount();
+
+      totalProses = baseQuery
+        .clone()
+        .andWhere("pt.status IN (:...status)", {
+          status: [RegStatus.NOT_ASSIGNED, RegStatus.INTERVIEW],
+        })
+        .getCount();
+
+      totalDitolak = baseQuery
+        .clone()
+        .andWhere("pt.status = :status", { status: RegStatus.REJECTED })
+        .getCount();
+    } else {
+      totalDiterima = baseQuery
+        .clone()
+        .where("pt.status = :status", { status: RegStatus.APPROVED })
+        .getCount();
+
+      totalProses = baseQuery
+        .clone()
+        .where("pt.status IN (:...status)", {
+          status: [RegStatus.NOT_ASSIGNED, RegStatus.INTERVIEW],
+        })
+        .getCount();
+
+      totalDitolak = baseQuery
+        .clone()
+        .where("pt.status = :status", { status: RegStatus.REJECTED })
+        .getCount();
+    }
 
     const [total, diterima, proses, ditolak] = await Promise.all([
       totalMahasiswa,
@@ -275,7 +290,6 @@ export class RegistrasiTesisService {
     search?: string;
     order_by?: "nim";
     sort?: "ASC" | "DESC";
-    periode: string;
   }) {
     const baseQuery = this.pendaftaranTesisRepository
       .createQueryBuilder("pt")
@@ -299,32 +313,44 @@ export class RegistrasiTesisService {
     baseQuery
       .innerJoinAndSelect("pt.topik", "topik")
       .innerJoinAndSelect("pt.penerima", "penerima")
-      .innerJoinAndSelect("pt.mahasiswa", "mahasiswa")
-      .where("topik.periode = :periode", { periode: options.periode });
+      .innerJoinAndSelect("pt.mahasiswa", "mahasiswa");
 
+    let whereUsed = false;
     if (options.idPenerima) {
-      baseQuery.andWhere("pt.penerimaId = :idPenerima", {
+      baseQuery.where("pt.penerimaId = :idPenerima", {
         idPenerima: options.idPenerima,
       });
+
+      whereUsed = true;
     }
 
-    if (options.search)
-      baseQuery.andWhere(
-        new Brackets((qb) =>
-          qb
-            .where("mahasiswa.nama ILIKE :search", {
-              search: `%${options.search}%`,
-            })
-            .orWhere("mahasiswa.nim ILIKE :search", {
-              search: `%${options.search}%`,
-            }),
-        ),
+    if (options.search) {
+      const bracket = new Brackets((qb) =>
+        qb
+          .where("mahasiswa.nama ILIKE :search", {
+            search: `%${options.search}%`,
+          })
+          .orWhere("mahasiswa.nim ILIKE :search", {
+            search: `%${options.search}%`,
+          }),
       );
 
-    if (options.status)
-      baseQuery.andWhere("pt.status = :status", {
-        status: options.status,
-      });
+      if (whereUsed) {
+        baseQuery.andWhere(bracket);
+      } else {
+        baseQuery.where(bracket);
+        whereUsed = true;
+      }
+    }
+
+    if (options.status) {
+      if (whereUsed) {
+        baseQuery.andWhere("pt.status = :status", { status: options.status });
+      } else {
+        baseQuery.where("pt.status = :status", { status: options.status });
+        whereUsed = true;
+      }
+    }
 
     if (options.order_by) {
       const orderByMapping = {
@@ -363,7 +389,7 @@ export class RegistrasiTesisService {
     return resData;
   }
 
-  private async getNewestRegByMhsOrFail(mahasiswaId: string, periode: string) {
+  private async getNewestRegByMhsOrFail(mahasiswaId: string) {
     const mahasiswa = await this.penggunaRepository.findOne({
       select: {
         id: true,
@@ -387,7 +413,6 @@ export class RegistrasiTesisService {
         topik: {
           judul: true,
           deskripsi: true,
-          periode: true,
         },
         penerima: {
           id: true,
@@ -400,9 +425,6 @@ export class RegistrasiTesisService {
       },
       where: {
         mahasiswa: mahasiswa,
-        topik: {
-          periode,
-        },
       },
       order: {
         waktuPengiriman: "DESC",
@@ -419,7 +441,6 @@ export class RegistrasiTesisService {
 
   async updateInterviewDate(
     mahasiswaId: string,
-    periode: string,
     dto: UpdateInterviewBodyDto,
     idPenerima?: string,
   ) {
@@ -432,7 +453,7 @@ export class RegistrasiTesisService {
       );
     }
 
-    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId, periode);
+    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId);
 
     if (newestReg && idPenerima && newestReg.penerima.id !== idPenerima) {
       throw new ForbiddenException();
@@ -462,11 +483,10 @@ export class RegistrasiTesisService {
 
   async updateStatus(
     mahasiswaId: string,
-    periode: string,
     dto: UpdateStatusBodyDto,
     idPenerima?: string,
   ) {
-    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId, periode);
+    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId);
 
     if (newestReg && idPenerima && newestReg.penerima.id !== idPenerima) {
       throw new ForbiddenException();
@@ -509,10 +529,9 @@ export class RegistrasiTesisService {
 
   async updatePembimbingList(
     mahasiswaId: string,
-    periode: string,
     { pembimbing_ids: dosen_ids }: UpdatePembimbingBodyDto,
   ) {
-    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId, periode);
+    const newestReg = await this.getNewestRegByMhsOrFail(mahasiswaId);
 
     if (newestReg.status !== RegStatus.APPROVED)
       throw new BadRequestException(
-- 
GitLab