Skip to content

Commit

Permalink
refactor: #84 PR 피드백 반영
Browse files Browse the repository at this point in the history
에러코드 수정
불필요한 인자 제거
id 타입 캐스팅 없이 사용할 수 있도록 수정
  • Loading branch information
Miensoap authored and koomchang committed Nov 13, 2024
1 parent ec2adeb commit 025f5b6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/src/auth/AuthUser.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AuthUser = createParamDecorator(
);

export interface AuthUser {
userId: string;
userId: number;
role: string;
}

Expand Down
5 changes: 1 addition & 4 deletions backend/src/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ const BEARER = 'Bearer';
const BEARER_REGEX = new RegExp(`^${BEARER}\\s+([A-Za-z0-9\\-._~+\\/=]*)$`);

export function extractBearerToken(header: string): string | null {
if (!header) {
return null;
}
const match = header.match(BEARER_REGEX);
const match = header?.match(BEARER_REGEX);
return match ? match[1] : null;
}

Expand Down
14 changes: 6 additions & 8 deletions backend/src/course/course.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class CourseController {
@Get('/my')
@UseGuards(JwtAuthGuard)
async getMyCourseList(@AuthUser() user: AuthUser) {
const userId = Number(user.userId);
return await this.courseService.getOwnCourses(userId);
return await this.courseService.getOwnCourses(user.userId);
}

@Get('/:id')
Expand All @@ -52,14 +51,15 @@ export class CourseController {
@AuthUser() user: AuthUser,
@Body() createCourseRequest: CreateCourseRequest,
) {
const userId = Number(user.userId);
return await this.courseService.createCourse(userId, createCourseRequest);
return await this.courseService.createCourse(
user.userId,
createCourseRequest,
);
}

@Put('/:id/places')
@UseGuards(JwtAuthGuard, CoursePermissionGuard)
async setPlacesOfCourse(
@AuthUser() user: AuthUser,
@Param('id') id: number,
@Body() setPlacesOfCourseRequest: SetPlacesOfCourseRequest,
) {
Expand All @@ -72,7 +72,6 @@ export class CourseController {
@Patch('/:id/info')
@UseGuards(JwtAuthGuard, CoursePermissionGuard)
async updateCourseInfo(
@AuthUser() user: AuthUser,
@Param('id') id: number,
@Body() updateCourseInfoRequest: UpdateCourseInfoRequest,
) {
Expand All @@ -83,7 +82,6 @@ export class CourseController {
@Patch('/:id/visibility')
@UseGuards(JwtAuthGuard, CoursePermissionGuard)
async updateCourseVisibility(
@AuthUser() user: AuthUser,
@Param('id') id: number,
@Body('isPublic') isPublic: boolean,
) {
Expand All @@ -93,7 +91,7 @@ export class CourseController {

@Delete('/:id')
@UseGuards(JwtAuthGuard, CoursePermissionGuard)
async deleteCourse(@AuthUser() user: AuthUser, @Param('id') id: number) {
async deleteCourse(@Param('id') id: number) {
return await this.courseService.deleteCourse(id);
}
}
2 changes: 1 addition & 1 deletion backend/src/course/exception/CoursePermissionException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HttpStatus } from '@nestjs/common';
export class CoursePermissionException extends BaseException {
constructor(id: number) {
super({
code: 903,
code: 905,
message: `id:${id} 코스에 대한 권한이 없습니다.`,
status: HttpStatus.FORBIDDEN,
});
Expand Down

0 comments on commit 025f5b6

Please sign in to comment.