From 514388554dc0752f0f9f04e399a3573b1f44a15c Mon Sep 17 00:00:00 2001 From: koomchang Date: Sat, 9 Nov 2024 19:37:10 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=BD=94=EC=8A=A4=20id=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20owner=20id=EB=A5=BC=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EC=84=9C=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=EB=A7=8C=20=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?#83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/course/course.service.ts | 7 +++++++ backend/src/course/guards/CoursePermissionGuard.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/course/course.service.ts b/backend/src/course/course.service.ts index 60ce625e..8cec9aa2 100644 --- a/backend/src/course/course.service.ts +++ b/backend/src/course/course.service.ts @@ -72,6 +72,13 @@ export class CourseService { return await CourseDetailResponse.from(map); } + async getCourseOwnerId(courseId: number) { + const course = await this.courseRepository.findById(courseId); + if (!course) throw new CourseNotFoundException(courseId); + + return course.user.id; + } + async createCourse(userId: number, createMapForm: CreateCourseRequest) { const user = { id: userId } as User; const map = createMapForm.toEntity(user); diff --git a/backend/src/course/guards/CoursePermissionGuard.ts b/backend/src/course/guards/CoursePermissionGuard.ts index da68b20c..44fb5970 100644 --- a/backend/src/course/guards/CoursePermissionGuard.ts +++ b/backend/src/course/guards/CoursePermissionGuard.ts @@ -11,10 +11,10 @@ export class CoursePermissionGuard implements CanActivate { const courseId = Number(request.params.id); const userId = Number(request.user.userId); - const course = await this.courseService.getCourseById(courseId); - if (course.user.id !== userId) { + const course = await this.courseService.getCourseOwnerId(courseId); + if (course !== userId) { throw new CoursePermissionException(courseId); } - return course.user.id === userId; + return true; } }