diff --git a/src/grade/grade.controller.ts b/src/grade/grade.controller.ts index 4c09462..10f5fe4 100644 --- a/src/grade/grade.controller.ts +++ b/src/grade/grade.controller.ts @@ -35,7 +35,7 @@ export class GradeController { @Delete(':id') @UseGuards(OwnershipGuard) - public async deleteGrade() { - await this.gradeService.gradeDelete(); + public async deleteGrade(@Param('id') userId: string) { + await this.gradeService.gradeDelete(userId); } } diff --git a/src/grade/grade.repository.ts b/src/grade/grade.repository.ts index fe7ddee..252f801 100644 --- a/src/grade/grade.repository.ts +++ b/src/grade/grade.repository.ts @@ -32,5 +32,7 @@ export class GradeRepository extends BaseRepository { ); } - public async delete(id: string) {} + public async delete(id: string) { + await this.repository.delete({ userId: id }); + } } diff --git a/src/grade/grade.service.ts b/src/grade/grade.service.ts index bf4da56..fa42e4f 100644 --- a/src/grade/grade.service.ts +++ b/src/grade/grade.service.ts @@ -1,4 +1,8 @@ -import { BadRequestException, Injectable } from '@nestjs/common'; +import { + BadRequestException, + Injectable, + NotFoundException, +} from '@nestjs/common'; import { GradeRepository } from './grade.repository'; import { Grade } from '../Entity/grade'; @@ -23,7 +27,7 @@ export class GradeService { const isExist = await this.gradeRepository.findOne(userId); if (!isExist) { - throw new BadRequestException('등록된 학점정보가 없습니다'); + throw new NotFoundException('등록된 학점정보가 없습니다'); } const newGrade = new Grade(); @@ -34,7 +38,15 @@ export class GradeService { await this.gradeRepository.update(newGrade); } - public async gradeDelete() {} + public async gradeDelete(userId: string) { + const isExist = await this.gradeRepository.findOne(userId); + + if (!isExist) { + throw new NotFoundException('등록된 학점정보가 없습니다'); + } + + await this.gradeRepository.delete(userId); + } public calculatePoint(grade: number) { return 0;