diff --git a/src/alokasi-topik/alokasi-topik.controller.ts b/src/alokasi-topik/alokasi-topik.controller.ts index ed647d0f14d1c8ffcdacebd76d455fc2e3c3e1dd..8c095da4d27d04e961dce48cc605c5df62bd0f8d 100644 --- a/src/alokasi-topik/alokasi-topik.controller.ts +++ b/src/alokasi-topik/alokasi-topik.controller.ts @@ -59,7 +59,7 @@ export class AlokasiTopikController { @Roles(RoleEnum.S2_TIM_TESIS, RoleEnum.ADMIN) @Get("/:id") async getById(@Param() params: TopikParamDto) { - const res = await this.alokasiTopikService.findById(params.id); + const res = await this.alokasiTopikService.findActiveTopikById(params.id); if (!res) throw new NotFoundException(); return res as OmittedTopik; } @@ -71,10 +71,12 @@ export class AlokasiTopikController { @Query() query: TopikQueryDto, ) { - return await this.alokasiTopikService.findAllCreatedByPembimbing({ - page: query.page || 1, - ...query, - }); + return await this.alokasiTopikService.findAllActiveTopikCreatedByPembimbing( + { + page: query.page || 1, + ...query, + }, + ); } @Roles(RoleEnum.S2_TIM_TESIS, RoleEnum.ADMIN) diff --git a/src/alokasi-topik/alokasi-topik.service.ts b/src/alokasi-topik/alokasi-topik.service.ts index 3ead15a888e2bde1325675493e7e3620ed188c1c..6a272d71cd1632ada903a4fcddae1a010af2e1b6 100644 --- a/src/alokasi-topik/alokasi-topik.service.ts +++ b/src/alokasi-topik/alokasi-topik.service.ts @@ -30,7 +30,7 @@ export class AlokasiTopikService { return { ids: ids.map(({ id }) => id) }; } - async findById(id: string) { + async findActiveTopikById(id: string) { return await this.topikRepo.findOne({ select: { id: true, @@ -45,6 +45,7 @@ export class AlokasiTopikService { }, where: { id, + aktif: true, }, relations: { pengaju: true, @@ -52,7 +53,7 @@ export class AlokasiTopikService { }); } - async findAllCreatedByPembimbing(options: { + async findAllActiveTopikCreatedByPembimbing(options: { page: number; limit?: number; search?: string; @@ -71,6 +72,7 @@ export class AlokasiTopikService { }, }, where: { + aktif: true, pengaju: { id: options.idPembimbing || undefined, roles: ArrayContains([RoleEnum.S2_PEMBIMBING]), @@ -130,10 +132,10 @@ export class AlokasiTopikService { } async update(id: string, updateDto: UpdateTopikDto) { - return await this.topikRepo.update(id, updateDto); + return await this.topikRepo.update({ id, aktif: true }, updateDto); } async remove(id: string) { - return await this.topikRepo.delete({ id }); // TODO: cascade? + return await this.topikRepo.update({ id }, { aktif: false }); } } diff --git a/src/entities/topik.entity.ts b/src/entities/topik.entity.ts index c3b79e49c17523408d6c619206924fe23a3116e0..e239df1bfc04a3d38be310e45857b1a28ec0c842 100644 --- a/src/entities/topik.entity.ts +++ b/src/entities/topik.entity.ts @@ -6,7 +6,7 @@ import { PrimaryGeneratedColumn, } from "typeorm"; import { Pengguna } from "./pengguna.entity"; -import { ApiProperty } from "@nestjs/swagger"; +import { ApiHideProperty, ApiProperty } from "@nestjs/swagger"; @Entity() export class Topik { @@ -30,4 +30,8 @@ export class Topik { @ApiProperty({ example: "550e8400-e29b-41d4-a716-446655440000" }) @Column({ nullable: true }) idPengaju: string; + + @ApiHideProperty() + @Column({ type: "boolean", default: true }) + aktif: boolean; } diff --git a/src/registrasi-tesis/registrasi-tesis.service.ts b/src/registrasi-tesis/registrasi-tesis.service.ts index c2f221a3092661d1fc9e9c491863b181e9d62c6f..496af6f847fc6bf8451d83810cfbae67233c281e 100644 --- a/src/registrasi-tesis/registrasi-tesis.service.ts +++ b/src/registrasi-tesis/registrasi-tesis.service.ts @@ -79,8 +79,14 @@ export class RegistrasiTesisService { throw new NotFoundException("Penerima not found."); } - if (topicRegistrationDto.idTopik && !topik) { - throw new NotFoundException("Topic not found."); + if (topicRegistrationDto.idTopik) { + if (!topik) { + throw new NotFoundException("Topic not found."); + } + + if (!topik.aktif) { + throw new BadRequestException("Topic is not active."); + } } if (lastPendaftaran && lastPendaftaran.status !== RegStatus.REJECTED) {