From 1f58ee5c90c703e5f709f0bdf26e711e01112122 Mon Sep 17 00:00:00 2001 From: Chiquita Ahsanunnisa <16521248@mahasiswa.itb.ac.id> Date: Wed, 1 May 2024 20:56:28 +0700 Subject: [PATCH] refactor: remove useless dashboard mhs endpoint --- src/dashboard/dashboard.controller.ts | 13 --- src/dashboard/dashboard.dto.ts | 64 +----------- src/dashboard/dashboard.module.ts | 13 +-- src/dashboard/dashboard.service.ts | 136 +------------------------- 4 files changed, 3 insertions(+), 223 deletions(-) diff --git a/src/dashboard/dashboard.controller.ts b/src/dashboard/dashboard.controller.ts index 31a3a4c..bb16aeb 100644 --- a/src/dashboard/dashboard.controller.ts +++ b/src/dashboard/dashboard.controller.ts @@ -8,7 +8,6 @@ import { AuthDto } from "src/auth/auth.dto"; import { Request } from "express"; import { DashboardDto, - DashboardMahasiswaResDto, GetDashboardDosbimQueryDto, JalurStatisticDto, } from "./dashboard.dto"; @@ -48,16 +47,4 @@ export class DashboardController { (request.user as AuthDto).id, ); } - - @UseGuards(CustomAuthGuard, RolesGuard) - @Roles(RoleEnum.S2_MAHASISWA) - @ApiOkResponse({ type: DashboardMahasiswaResDto }) - @Get("/mahasiswa") - async getDashboardMahasiswa( - @Req() request: Request, - ): Promise<DashboardMahasiswaResDto> { - return this.dashboardService.getDashboardMahasiswa( - (request.user as AuthDto).id, - ); - } } diff --git a/src/dashboard/dashboard.dto.ts b/src/dashboard/dashboard.dto.ts index 8d27993..b11d1e6 100644 --- a/src/dashboard/dashboard.dto.ts +++ b/src/dashboard/dashboard.dto.ts @@ -4,14 +4,9 @@ import { OmitType, PickType, } from "@nestjs/swagger"; -import { - JalurEnum, - PendaftaranTesis, -} from "../entities/pendaftaranTesis.entity"; +import { JalurEnum } from "../entities/pendaftaranTesis.entity"; import { Topik } from "src/entities/topik.entity"; import { Pengguna } from "src/entities/pengguna.entity"; -import { Bimbingan } from "src/entities/bimbingan.entity"; -import { PendaftaranSidsem } from "src/entities/pendaftaranSidsem"; import { IsOptional } from "class-validator"; import { BimbinganStatus } from "src/entities/bimbingan.entity"; @@ -23,35 +18,10 @@ class PickedMhsDashboard extends PickType(Pengguna, [ "email", ] as const) {} -class OmittedTopikMhsDashboard extends OmitType(Topik, ["pengaju"] as const) {} - class NoEmailUserDashboard extends OmitType(PickedMhsDashboard, [ "email", ] as const) {} -export class NoNIMUserDashboard extends OmitType(PickedMhsDashboard, [ - "nim", -] as const) {} - -class OmittedPendaftaranTesisMhsDashboard extends OmitType(PendaftaranTesis, [ - "mahasiswa", - "topik", - "penerima", -] as const) { - @ApiProperty() - topik: OmittedTopikMhsDashboard; - - @ApiProperty() - penerima: NoEmailUserDashboard; -} - -class SidsemWithPenguji extends OmitType(PendaftaranSidsem, [ - "penguji", -] as const) { - @ApiProperty({ type: [NoNIMUserDashboard] }) - penguji: NoNIMUserDashboard[]; -} - export class DashboardDto { @ApiProperty({ example: "550e8400-e29b-41d4-a716-446655440000" }) id: string; @@ -77,38 +47,6 @@ export class JalurStatisticDto { count: number; } -export class DashboardMahasiswaResDto { - @ApiProperty() - mahasiswa: PickedMhsDashboard; - - @ApiProperty({ type: OmittedPendaftaranTesisMhsDashboard, nullable: true }) - pendaftaranTesis: OmittedPendaftaranTesisMhsDashboard; - - @ApiProperty({ type: [NoNIMUserDashboard] }) - dosenBimbingan: NoNIMUserDashboard[]; - - @ApiProperty({ type: [Bimbingan] }) - bimbingan: Bimbingan[]; - - @ApiProperty({ - type: PendaftaranSidsem, - nullable: true, - }) - seminarSatu: PendaftaranSidsem; - - @ApiProperty({ - type: SidsemWithPenguji, - nullable: true, - }) - seminarDua: SidsemWithPenguji; - - @ApiProperty({ - type: SidsemWithPenguji, - nullable: true, - }) - sidang: SidsemWithPenguji; -} - export class GetDashboardDosbimQueryDto { @ApiPropertyOptional({}) @IsOptional() diff --git a/src/dashboard/dashboard.module.ts b/src/dashboard/dashboard.module.ts index 0d4da49..4f310dc 100644 --- a/src/dashboard/dashboard.module.ts +++ b/src/dashboard/dashboard.module.ts @@ -4,22 +4,11 @@ import { DashboardController } from "./dashboard.controller"; import { DashboardService } from "./dashboard.service"; import { PendaftaranTesis } from "../entities/pendaftaranTesis.entity"; import { Pengguna } from "../entities/pengguna.entity"; -import { Topik } from "../entities/topik.entity"; -import { Bimbingan } from "src/entities/bimbingan.entity"; -import { PendaftaranSidsem } from "src/entities/pendaftaranSidsem"; -import { DosenBimbingan } from "src/entities/dosenBimbingan.entity"; import { BimbinganModule } from "src/bimbingan/bimbingan.module"; @Module({ imports: [ - TypeOrmModule.forFeature([ - PendaftaranTesis, - Pengguna, - Topik, - Bimbingan, - PendaftaranSidsem, - DosenBimbingan, - ]), + TypeOrmModule.forFeature([PendaftaranTesis, Pengguna]), BimbinganModule, ], controllers: [DashboardController], diff --git a/src/dashboard/dashboard.service.ts b/src/dashboard/dashboard.service.ts index d6b71ae..7486c33 100644 --- a/src/dashboard/dashboard.service.ts +++ b/src/dashboard/dashboard.service.ts @@ -6,18 +6,7 @@ import { RegStatus, } from "../entities/pendaftaranTesis.entity"; import { Pengguna } from "../entities/pengguna.entity"; -import { Bimbingan } from "src/entities/bimbingan.entity"; -import { - DashboardDto, - DashboardMahasiswaResDto, - JalurStatisticDto, - NoNIMUserDashboard, -} from "./dashboard.dto"; -import { - PendaftaranSidsem, - TipeSidsemEnum, -} from "src/entities/pendaftaranSidsem"; -import { DosenBimbingan } from "src/entities/dosenBimbingan.entity"; +import { DashboardDto, JalurStatisticDto } from "./dashboard.dto"; import { BimbinganService } from "src/bimbingan/bimbingan.service"; @Injectable() @@ -27,12 +16,6 @@ export class DashboardService { private pendaftaranTesisRepository: Repository<PendaftaranTesis>, @InjectRepository(Pengguna) private penggunaRepository: Repository<Pengguna>, - @InjectRepository(Bimbingan) - private bimbinganRepository: Repository<Bimbingan>, - @InjectRepository(PendaftaranSidsem) - private pendaftaranSidsemRepository: Repository<PendaftaranSidsem>, - @InjectRepository(DosenBimbingan) - private dosenBimbinganRepository: Repository<DosenBimbingan>, private bimbinganService: BimbinganService, ) {} @@ -128,121 +111,4 @@ export class DashboardService { return statistics as JalurStatisticDto[]; } - - async getDashboardMahasiswa( - mahasiswaId: string, - ): Promise<DashboardMahasiswaResDto> { - const mahasiswaQuery = this.penggunaRepository - .createQueryBuilder("pengguna") - .select([ - "pengguna.id", - "pengguna.nama", - "pengguna.email", - "pengguna.nim", - ]) - .where("pengguna.id = :id", { id: mahasiswaId }); - const pendaftaranTesisQuery = this.pendaftaranTesisRepository - .createQueryBuilder("pendaftaranTesis") - .select([ - "pendaftaranTesis.id", - "pendaftaranTesis.jalurPilihan", - "pendaftaranTesis.waktuPengiriman", - "pendaftaranTesis.jadwalInterview", - "pendaftaranTesis.waktuKeputusan", - "pendaftaranTesis.status", - "penerima.id", - "penerima.nama", - "penerima.email", - ]) - .leftJoin("pendaftaranTesis.mahasiswa", "mahasiswa") - .leftJoinAndSelect("pendaftaranTesis.topik", "topik") - .leftJoin("pendaftaranTesis.penerima", "penerima") - .where("mahasiswa.id = :id", { id: mahasiswaId }) - .orderBy("pendaftaranTesis.waktuPengiriman", "DESC"); - - const [mahasiswa, pendaftaranTesis] = await Promise.all([ - mahasiswaQuery.getOne(), - pendaftaranTesisQuery.getOne(), - ]); - - let dosenBimbingan: DosenBimbingan[] = []; - let bimbingan: Bimbingan[] = []; - let seminarSatu: PendaftaranSidsem | null = null; - let seminarDua: PendaftaranSidsem | null = null; - let sidang: PendaftaranSidsem | null = null; - - if (pendaftaranTesis) { - const dosenBimbinganQuery = this.dosenBimbinganRepository - .createQueryBuilder("dosenBimbingan") - .select(["dosen.id", "dosen.nama", "dosen.email"]) - .leftJoin("dosenBimbingan.dosen", "dosen") - .where("dosenBimbingan.idPendaftaran = :id", { - id: pendaftaranTesis.id, - }); - const bimbinganQuery = this.bimbinganRepository - .createQueryBuilder("bimbingan") - .leftJoinAndSelect("bimbingan.berkas", "berkas") - .where("bimbingan.pendaftaranId = :id", { - id: pendaftaranTesis.id, - }); - const [seminarSatuQuery, seminarDuaQuery, sidangQuery] = Object.values( - TipeSidsemEnum, - ).map((tipe) => { - let temp = this.pendaftaranSidsemRepository - .createQueryBuilder("pendaftaranSidsem") - .leftJoinAndSelect("pendaftaranSidsem.ruangan", "ruangan") - .where("pendaftaranSidsem.pendaftaranTesisId = :id", { - id: pendaftaranTesis.id, - }) - .andWhere("pendaftaranSidsem.tipe = :tipe", { - tipe, - }) - .andWhere("NOT pendaftaranSidsem.ditolak"); - - if (tipe !== TipeSidsemEnum.SEMINAR_1) { - temp = temp - .leftJoinAndSelect("pendaftaranSidsem.penguji", "penguji") - .leftJoinAndSelect("penguji.dosen", "dosen"); - } - - return temp; - }); - - [dosenBimbingan, bimbingan, seminarSatu, seminarDua, sidang] = - await Promise.all([ - dosenBimbinganQuery.getMany(), - bimbinganQuery.getMany(), - seminarSatuQuery.getOne(), - seminarDuaQuery.getOne(), - sidangQuery.getOne(), - ]); - } - - return { - mahasiswa, - pendaftaranTesis, - dosenBimbingan: - dosenBimbingan.length > 0 - ? (dosenBimbingan as any as NoNIMUserDashboard[]) - : [pendaftaranTesis.penerima], - bimbingan, - seminarSatu, - seminarDua: { - ...seminarDua, - penguji: seminarDua?.penguji.map((p) => ({ - id: p.dosen.id, - nama: p.dosen.nama, - email: p.dosen.email, - })), - }, - sidang: { - ...sidang, - penguji: sidang?.penguji.map((p) => ({ - id: p.dosen.id, - nama: p.dosen.nama, - email: p.dosen.email, - })), - }, - }; - } } -- GitLab