From 35a546ef26eb895cb5eba8882baf87ad5948a072 Mon Sep 17 00:00:00 2001 From: Rinaldy Adin <16521390@mahasiswa.itb.ac.id> Date: Mon, 3 Jun 2024 01:15:37 +0700 Subject: [PATCH] feat: dashbaord mahasiswa --- src/dashboard/dashboard.controller.ts | 9 +++++ src/dashboard/dashboard.dto.ts | 11 +++++ src/dashboard/dashboard.module.ts | 2 + src/dashboard/dashboard.service.ts | 58 +++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/src/dashboard/dashboard.controller.ts b/src/dashboard/dashboard.controller.ts index 8cec5c5..d1453e3 100644 --- a/src/dashboard/dashboard.controller.ts +++ b/src/dashboard/dashboard.controller.ts @@ -14,6 +14,7 @@ import { RolesGuard } from "src/middlewares/roles.guard"; import { DashboardDto, GetDashboardDosbimQueryDto, + GetDashboardMahasiswaRespDto, GetDashboardTimTesisReqQueryDto, GetDashboardTimTesisRespDto, JalurStatisticDto, @@ -59,4 +60,12 @@ export class DashboardController { ): Promise<GetDashboardTimTesisRespDto> { return this.dashboardService.getDashboardTimTesis(query); } + + @UseGuards(CustomAuthGuard, RolesGuard) + @Roles(RoleEnum.S2_MAHASISWA) + @ApiOkResponse({ type: GetDashboardMahasiswaRespDto }) + @Get("/mahasiswa") + async getDashboardMahasiswa(): Promise<GetDashboardMahasiswaRespDto> { + return this.dashboardService.getDashboardMahasiswa(); + } } diff --git a/src/dashboard/dashboard.dto.ts b/src/dashboard/dashboard.dto.ts index adfb93e..fb56771 100644 --- a/src/dashboard/dashboard.dto.ts +++ b/src/dashboard/dashboard.dto.ts @@ -101,3 +101,14 @@ export class GetDashboardTimTesisRespDto { @ApiProperty({ type: GetDashboardTimTesisDataDto }) data: GetDashboardTimTesisDataDto[]; } + +export class GetDashboardMahasiswaRespDto { + @ApiProperty() + isSemproPeriod: boolean; + + @ApiProperty() + isSemtesPeriod: boolean; + + @ApiProperty() + isSidangPeriod: boolean; +} diff --git a/src/dashboard/dashboard.module.ts b/src/dashboard/dashboard.module.ts index ad95d2f..5cde477 100644 --- a/src/dashboard/dashboard.module.ts +++ b/src/dashboard/dashboard.module.ts @@ -2,6 +2,7 @@ import { Module } from "@nestjs/common"; import { TypeOrmModule } from "@nestjs/typeorm"; import { BimbinganModule } from "src/bimbingan/bimbingan.module"; import { DosenBimbingan } from "src/entities/dosenBimbingan.entity"; +import { Konfigurasi } from "src/entities/konfigurasi.entity"; import { PendaftaranSidsem } from "src/entities/pendaftaranSidsem"; import { PendaftaranTesis } from "../entities/pendaftaranTesis.entity"; import { Pengguna } from "../entities/pengguna.entity"; @@ -15,6 +16,7 @@ import { DashboardService } from "./dashboard.service"; Pengguna, PendaftaranSidsem, DosenBimbingan, + Konfigurasi, ]), BimbinganModule, ], diff --git a/src/dashboard/dashboard.service.ts b/src/dashboard/dashboard.service.ts index 29e867e..62175ac 100644 --- a/src/dashboard/dashboard.service.ts +++ b/src/dashboard/dashboard.service.ts @@ -1,7 +1,12 @@ import { BadRequestException, Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; +import * as dayjs from "dayjs"; import { BimbinganService } from "src/bimbingan/bimbingan.service"; import { DosenBimbingan } from "src/entities/dosenBimbingan.entity"; +import { + Konfigurasi, + KonfigurasiKeyEnum, +} from "src/entities/konfigurasi.entity"; import { PendaftaranSidsem, SidsemStatus, @@ -16,6 +21,7 @@ import { Pengguna, RoleEnum } from "../entities/pengguna.entity"; import { DashboardDto, DashboardTimTesisStatusEnum, + GetDashboardMahasiswaRespDto, GetDashboardTimTesisReqQueryDto, GetDashboardTimTesisRespDto, JalurStatisticDto, @@ -32,6 +38,8 @@ export class DashboardService { private dosenBimbinganRepository: Repository<DosenBimbingan>, @InjectRepository(PendaftaranSidsem) private pendaftaranSidsemRepository: Repository<PendaftaranSidsem>, + @InjectRepository(Konfigurasi) + private konfigurasiRepository: Repository<Konfigurasi>, private bimbinganService: BimbinganService, ) {} @@ -300,4 +308,54 @@ export class DashboardService { })), }; } + + async getDashboardMahasiswa(): Promise<GetDashboardMahasiswaRespDto> { + const [ + awalSempro, + akhirSempro, + awalSemtes, + akhirSemtes, + awalSidang, + akhirSidang, + ] = await Promise.all([ + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AWAL_SEMPRO }, + }), + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AKHIR_SEMPRO }, + }), + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AWAL_SEM_TESIS }, + }), + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AKHIR_SEM_TESIS }, + }), + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AWAL_SIDANG }, + }), + this.konfigurasiRepository.findOne({ + where: { key: KonfigurasiKeyEnum.AKHIR_SIDANG }, + }), + ]); + + const isSemproPeriod = + awalSempro && + akhirSempro && + dayjs(awalSempro.value, "YYYY-mm-dd").startOf("day").isBefore(dayjs()) && + dayjs(akhirSempro.value, "YYYY-mm-dd").endOf("day").isAfter(dayjs()); + + const isSemtesPeriod = + awalSemtes && + akhirSemtes && + dayjs(awalSemtes.value, "YYYY-mm-dd").startOf("day").isBefore(dayjs()) && + dayjs(akhirSemtes.value, "YYYY-mm-dd").endOf("day").isAfter(dayjs()); + + const isSidangPeriod = + awalSidang && + akhirSidang && + dayjs(awalSidang.value, "YYYY-mm-dd").startOf("day").isBefore(dayjs()) && + dayjs(akhirSidang.value, "YYYY-mm-dd").endOf("day").isAfter(dayjs()); + + return { isSemproPeriod, isSemtesPeriod, isSidangPeriod }; + } } -- GitLab