diff --git a/src/course-review/course-review.service.ts b/src/course-review/course-review.service.ts index b96d58a9..071222b1 100644 --- a/src/course-review/course-review.service.ts +++ b/src/course-review/course-review.service.ts @@ -205,7 +205,8 @@ export class CourseReviewService { // 해당 과목의 강의평들 조회 (유저가 열람권 구매 안했으면 열람 불가 ) const viewableUser = await this.userService.findUserById(user.id); - if (viewableUser.viewableUntil.getDate() < koreaTime.getDate()) { + + if (viewableUser.viewableUntil <= koreaTime) { throw new ForbiddenException('열람권을 구매해야 합니다.'); } diff --git a/src/user/dto/check-course-review-reading-ticket.dto.ts b/src/user/dto/check-course-review-reading-ticket.dto.ts new file mode 100644 index 00000000..ebf91683 --- /dev/null +++ b/src/user/dto/check-course-review-reading-ticket.dto.ts @@ -0,0 +1,10 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class CheckCourseReviewReadingTicketResponseDto { + constructor(date: Date) { + this.date = date; + } + + @ApiProperty({ description: '강의평 열람권 만료 일자' }) + date: Date; +} diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index dc5764ff..78457f3f 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -37,6 +37,7 @@ import { LanguageRequestDto, LanguageResponseDto, } from './dto/user-language.dto'; +import { CheckCourseReviewReadingTicketResponseDto } from './dto/check-course-review-reading-ticket.dto'; @ApiTags('User') @ApiBearerAuth('accessToken') @@ -189,6 +190,23 @@ export class UserController { ); } + @ApiOperation({ + summary: '강의평 열람권 만료 조회', + description: + '해당 사용자의 강의평 열람권이 만료되었는지 확인 후 만료되었으면 null, 만료되지 않았으면 강의평 열람권 만료일자를 반환합니다.', + }) + @ApiResponse({ + status: 200, + description: '강의평 열람권 만료 조회 성공', + type: CheckCourseReviewReadingTicketResponseDto, + }) + @Get('course-review-reading-ticket') + async checkCourseReviewReadingTicket( + @User() user: AuthorizedUserDto, + ): Promise { + return await this.userService.checkCourseReviewReadingTicket(user.id); + } + @ApiOperation({ summary: '회원탈퇴', description: '사용자의 계정을 삭제합니다.', diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 98d7f61f..ba74722b 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -25,6 +25,7 @@ import { CharacterType } from 'src/enums/character-type.enum'; import { Language } from 'src/enums/language'; import { UserLanguageEntity } from 'src/entities/user-language.entity'; import { LanguageResponseDto } from './dto/user-language.dto'; +import { CheckCourseReviewReadingTicketResponseDto } from './dto/check-course-review-reading-ticket.dto'; @Injectable() export class UserService { @@ -397,4 +398,26 @@ export class UserService { return result; } + + async checkCourseReviewReadingTicket( + userId: number, + ): Promise { + const user = await this.userRepository.findOne({ + where: { + id: userId, + }, + }); + + if (!user) throw new NotFoundException('Cannot find user!'); + + const offset = 1000 * 60 * 60 * 9; // 9시간 밀리세컨드 값 + const koreaTime = new Date(Date.now() + offset); // 현재 시간 + + if (user.viewableUntil <= koreaTime) { + // 강의평 열람기간이 같을때도 만료되었다고 처리 + return null; + } + + return new CheckCourseReviewReadingTicketResponseDto(user.viewableUntil); + } }