1- import { Injectable , NotFoundException } from '@nestjs/common' ;
1+ import { Injectable } from '@nestjs/common' ;
22import { ActivityRepository } from '../repository/activity.repository' ;
3- import { UserRepository } from '../../user/repository/user.repository' ;
43import {
54 ActivityReadResponseDto ,
65 DailyActivityDto ,
76} from '../dto/response/activity-read.dto' ;
7+ import { UserService } from '../../user/service/user.service' ;
88
99@Injectable ( )
1010export class ActivityService {
1111 constructor (
1212 private readonly activityRepository : ActivityRepository ,
13- private readonly userRepository : UserRepository ,
13+ private readonly userService : UserService ,
1414 ) { }
1515
1616 async readActivities (
1717 userId : number ,
1818 year : number ,
1919 ) : Promise < ActivityReadResponseDto > {
20- const user = await this . userRepository . findOneBy ( { id : userId } ) ;
21- if ( ! user ) {
22- throw new NotFoundException ( '존재하지 않는 사용자입니다.' ) ;
23- }
20+ const user = await this . userService . getUser ( userId ) ;
2421
2522 const activities =
2623 await this . activityRepository . findActivitiesByUserIdAndYear ( userId , year ) ;
@@ -33,12 +30,7 @@ export class ActivityService {
3330 } ) ,
3431 ) ;
3532
36- return new ActivityReadResponseDto ( {
37- dailyActivities,
38- maxStreak : user . maxStreak ,
39- currentStreak : user . currentStreak ,
40- totalViews : user . totalViews ,
41- } ) ;
33+ return ActivityReadResponseDto . toResponseDto ( dailyActivities , user ) ;
4234 }
4335
4436 async upsertActivity ( userId : number ) {
0 commit comments