Skip to content

Commit

Permalink
Fix: 유효하지 않은 InvalidLink 에러 처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sally0226 committed Aug 24, 2024
1 parent ba6ec6d commit 5b65945
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/exceptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export class MapNotFoundException extends ExceptionOf.USER(
'존재하지 않는 지도입니다.' as const,
) {}

export class InviteLinkGoneException extends ExceptionOf.USER(
export class InviteLinkInvalidException extends ExceptionOf.USER(
HttpStatus.GONE,
'만료된 초대링크입니다.' as const,
'유효하지 않은 초대링크입니다.' as const,
) {}

export class UserMapConflictException extends ExceptionOf.USER(
Expand Down
12 changes: 7 additions & 5 deletions src/invite-link/invite-link.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GoneException, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';

import { InjectRepository } from '@mikro-orm/nestjs';
import { map } from 'rxjs/operators';

import { INVITE_LINK_EXPIRATION_DAYS } from 'src/common/constants';
import {
Expand All @@ -12,10 +11,9 @@ import {
User,
} from 'src/entities';
import {
InviteLinkGoneException,
InviteLinkInvalidException,
MapNotFoundException,
} from 'src/exceptions/index';
import { InviteLinkResponseDto } from 'src/map/dtos/invite-link-response.dto';
import { UtilService } from 'src/util/util.service';

@Injectable()
Expand Down Expand Up @@ -54,8 +52,12 @@ export class InviteLinkService {
token: inviteLinkToken,
});

if (!inviteLink) {
throw new InviteLinkInvalidException();
}

if (new Date(inviteLink.expiresAt) < new Date()) {
throw new InviteLinkGoneException();
throw new InviteLinkInvalidException();
}

return inviteLink;
Expand Down
9 changes: 8 additions & 1 deletion src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { UpdateMapDto } from './dtos/update-map.dto';
import { MapService } from './map.service';

@ApiTags('maps')
@ApiBearerAuth()
@Controller('maps')
export class MapController {
constructor(
Expand All @@ -44,6 +43,7 @@ export class MapController {
@Post()
@ApiOkResponse({ type: MapItemForUserDto })
@ApiOperation({ summary: '새 지도를 생성합니다' })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
create(@Body() createMapDto: CreateMapDto, @CurrentUser() user: User) {
return this.mapService.create(createMapDto, user);
Expand All @@ -52,6 +52,7 @@ export class MapController {
@Get()
@ApiOperation({ summary: '사용자가 속해있는 지도를 가져옵니다.' })
@ApiOkResponse({ type: [MapItemForUserDto] })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
findAll(@CurrentUser() user: User): Promise<MapItemForUserDto[]> {
return this.mapService.findAll(user);
Expand All @@ -61,6 +62,7 @@ export class MapController {
@ApiOperation({ summary: '지도 정보 조회 (포함된 유저 정보, 맛집 개수...)' })
@ApiOkResponse({ type: MapResponseDto })
@UseMapRoleGuard()
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
async findOne(
@Param('id') id: string,
Expand Down Expand Up @@ -89,6 +91,7 @@ export class MapController {
@Delete(':id')
@ApiOkResponse({ type: Number })
@ApiExcludeEndpoint()
@ApiBearerAuth()
remove(@Param('id') id: string) {
return this.mapService.remove(id);
}
Expand All @@ -98,6 +101,7 @@ export class MapController {
summary: '지도의 초대링크 생성',
description: '유효기간은 7일로 설정되어 있습니다.',
})
@ApiBearerAuth()
@ApiResponse({ type: InviteLinkResponseDto })
@UseMapRoleGuard([UserMapRole.ADMIN])
@UseAuthGuard([UserRole.USER])
Expand All @@ -113,6 +117,7 @@ export class MapController {
@ApiOperation({
summary: '기본 태그와 지도에 저장된 태그를 조회합니다.',
})
@ApiBearerAuth()
@ApiResponse({ type: TagResponseDto, isArray: true })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
Expand All @@ -124,6 +129,7 @@ export class MapController {
@ApiOperation({
summary: '맛집 저장시 사용할 태그를 생성합니다.',
})
@ApiBearerAuth()
@ApiResponse({ type: TagResponseDto })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
Expand Down Expand Up @@ -171,6 +177,7 @@ export class MapController {
summary: '초대링크로 지도에 승선',
description: '초대장 화면에서 "승선하기" 버튼 클릭 시 호출',
})
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
async joinInviteLink(
@Param('token') inviteLinkToken: string,
Expand Down

0 comments on commit 5b65945

Please sign in to comment.