Skip to content

Commit

Permalink
Merge pull request #90 from DevKor-github/feature/user
Browse files Browse the repository at this point in the history
Feature/user
  • Loading branch information
Devheun authored Aug 31, 2024
2 parents 42a79c8 + 46a3b5e commit 5f6b038
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/course-review/course-review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('열람권을 구매해야 합니다.');
}

Expand Down
10 changes: 10 additions & 0 deletions src/user/dto/check-course-review-reading-ticket.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';

export class CheckCourseReviewReadingTicketResponseDto {
constructor(date: Date) {
this.date = date;
}

@ApiProperty({ description: '강의평 열람권 만료 일자' })
date: Date;
}
18 changes: 18 additions & 0 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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<CheckCourseReviewReadingTicketResponseDto> {
return await this.userService.checkCourseReviewReadingTicket(user.id);
}

@ApiOperation({
summary: '회원탈퇴',
description: '사용자의 계정을 삭제합니다.',
Expand Down
23 changes: 23 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -397,4 +398,26 @@ export class UserService {

return result;
}

async checkCourseReviewReadingTicket(
userId: number,
): Promise<CheckCourseReviewReadingTicketResponseDto> {
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);
}
}

0 comments on commit 5f6b038

Please sign in to comment.