diff --git a/src/dashboard/dashboard.controller.ts b/src/dashboard/dashboard.controller.ts index 193b9f35a2a211159c2a5908941e772a82262562..e8ba12c0bcc39b6dcc96a9b221475b502cc3a5d2 100644 --- a/src/dashboard/dashboard.controller.ts +++ b/src/dashboard/dashboard.controller.ts @@ -1,7 +1,23 @@ -import { Controller } from "@nestjs/common"; -import { DashboardService } from "./dashboard.service"; +import { Controller, Get, Param, UseGuards } from '@nestjs/common'; +import { DashboardService } from './dashboard.service'; +import { CustomAuthGuard } from "src/middlewares/custom-auth.guard"; +import { RolesGuard } from "src/middlewares/roles.guard"; +import { RoleEnum } from "src/entities/pengguna.entity"; +import { Roles } from "src/middlewares/roles.decorator"; -@Controller("dashboard") + +@Controller('dashboard') export class DashboardController { constructor(private readonly dashboardService: DashboardService) {} -} + + @UseGuards(CustomAuthGuard, RolesGuard) + @Roles(RoleEnum.S2_PEMBIMBING, RoleEnum.ADMIN, RoleEnum.S2_TIM_TESIS) + @Get(':dosenId') + async findByPenerimaId(@Param('dosenId') penerimaId: string) { + return this.dashboardService.findByPenerimaId(penerimaId); + } + @Get(':dosenId/statistics') + async getStatisticsByJalurPilihan(@Param('dosenId') penerimaId: string) { + return this.dashboardService.getStatisticsByJalurPilihan(penerimaId); + } +} \ No newline at end of file diff --git a/src/dashboard/dashboard.dto.ts b/src/dashboard/dashboard.dto.ts new file mode 100644 index 0000000000000000000000000000000000000000..b9aeab42519c5b5735ee2554bf3c57fe1ed4cdb2 --- /dev/null +++ b/src/dashboard/dashboard.dto.ts @@ -0,0 +1,14 @@ +import { JalurEnum, RegStatus } from '../entities/pendaftaranTesis.entity'; + +export class DashboardDto { + id: string; + jalurPilihan: JalurEnum; + waktuPengiriman: Date; + jadwalInterview: Date; + waktuKeputusan: Date; + status: RegStatus; + periode: string; + topikId: string; + mahasiswaId: string; + penerimaId: string; +} \ No newline at end of file diff --git a/src/dashboard/dashboard.module.ts b/src/dashboard/dashboard.module.ts index 600273185f59e8d4391db852eefdfeb5eb13ff2b..44a7c6151bfb7e72eb3f0b8bb6845f6e37c9d38b 100644 --- a/src/dashboard/dashboard.module.ts +++ b/src/dashboard/dashboard.module.ts @@ -1,9 +1,14 @@ -import { Module } from "@nestjs/common"; -import { DashboardController } from "./dashboard.controller"; -import { DashboardService } from "./dashboard.service"; +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +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'; @Module({ + imports: [TypeOrmModule.forFeature([PendaftaranTesis, Pengguna, Topik])], controllers: [DashboardController], providers: [DashboardService], }) -export class DashboardModule {} +export class DashboardModule {} \ No newline at end of file diff --git a/src/dashboard/dashboard.service.ts b/src/dashboard/dashboard.service.ts index 3414bca8cd82381dc027c405a9d4c687804169ba..7ef693ab03fd88d2616aff8876d55f111bc7bf81 100644 --- a/src/dashboard/dashboard.service.ts +++ b/src/dashboard/dashboard.service.ts @@ -1,4 +1,47 @@ -import { Injectable } from "@nestjs/common"; +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; +import { PendaftaranTesis } from '../entities/pendaftaranTesis.entity'; +import { JalurEnum } from '../entities/pendaftaranTesis.entity'; +import { Pengguna } from '../entities/pengguna.entity'; +import { Topik } from '../entities/topik.entity'; @Injectable() -export class DashboardService {} +export class DashboardService { + constructor( + @InjectRepository(PendaftaranTesis) + private pendaftaranTesisRepository: Repository<PendaftaranTesis>, + @InjectRepository(Pengguna) + private penggunaRepository: Repository<Pengguna>, + @InjectRepository(Topik) + private topikRepository: Repository<Topik>, + ) {} + + async findAll(): Promise<PendaftaranTesis[]> { + return this.pendaftaranTesisRepository.find({ relations: ["mahasiswa", "topik"] }); + } + + async findByPenerimaId(penerimaId: string): Promise<PendaftaranTesis[]> { + const penerima = await this.penggunaRepository.findOne({ where: { id: penerimaId } }); + if (!penerima) { + return []; + } + const pendaftaranTesis = await this.pendaftaranTesisRepository.find({ where: { penerima }, relations: ["mahasiswa", "topik"] }); + return pendaftaranTesis; + } + + async getStatisticsByJalurPilihan(penerimaId: string): Promise<{ jalurPilihan: JalurEnum; count: number }[]> { + const penerima = await this.penggunaRepository.findOne({ where: { id: penerimaId } }); + if (!penerima) { + return []; + } + const statistics = await this.pendaftaranTesisRepository + .createQueryBuilder('pendaftaranTesis') + .select('pendaftaranTesis.jalurPilihan', 'jalurPilihan') + .addSelect('COUNT(*)', 'count') + .where('pendaftaranTesis.penerima = :penerima', { penerima: penerima.id }) + .groupBy('pendaftaranTesis.jalurPilihan') + .getRawMany(); + return statistics; + } +} \ No newline at end of file