diff --git a/src/dashboard/dashboard.controller.ts b/src/dashboard/dashboard.controller.ts index 8cec5c50418c02eac5f35279a28b7582647e149e..d1453e336226e72cee09dd9949c16c4aec6310ee 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 adfb93e0e0a210e077c1704e260e90c164e15e7e..fb567716ed112e00bed8c296fe78e38b986dfc74 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 ad95d2fc648e9ebf0247fb7f326f682b9a1c8cf3..5cde4775d2db6f280f37568fb14225ced988e499 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 29e867e2227ed68513532f4fe109daf7c30fe550..62175ac254e7225f30c4fe6f9ae889f450e1cf8b 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 }; + } }