Skip to content

Commit dd05e6a

Browse files
authored
Merge pull request #89 from codeit-garden/develop
미션 응답 구체화
2 parents 004de85 + 21bd8a9 commit dd05e6a

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

src/services/missionService.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,44 @@ const calculateTime = require('../utils/calculateTime');
44

55
const prisma = new PrismaClient();
66

7-
const uncompletedMission = async(memberId) => {
8-
try{
9-
const missions = await prisma.memberMission.findMany({
10-
where: {
11-
memberId: Number(memberId),
12-
completed: false
13-
},
14-
include: {
15-
mission: {
16-
include: { flower: true }
17-
}
18-
},
19-
orderBy: {
20-
mission: {id: 'asc'}
21-
},
22-
});
23-
return missions;
24-
}catch(error){
25-
throw new CustomError(ErrorCodes.InternalServerError, '사용자의 미션 목록 조회 중 오류가 발생하였습니다.');
7+
const uncompletedMission = async (memberId) => {
8+
try {
9+
const missions = await prisma.memberMission.findMany({
10+
where: {
11+
memberId: Number(memberId),
12+
},
13+
include: {
14+
mission: {
15+
include: { flower: true },
16+
},
17+
},
18+
orderBy: {
19+
mission: { id: "asc" },
20+
},
21+
});
22+
23+
const missionList = [];
24+
25+
missions.forEach((mission) => {
26+
const formatMission = {
27+
title: mission.mission.title,
28+
description: mission.mission.description,
29+
type: mission.mission.type,
30+
targetValue: mission.mission.targetValue,
31+
currentValue: 0,
32+
completed: mission.completed,
33+
flowerName: mission.mission.flower.name,
34+
};
35+
36+
missionList.push(formatMission);
37+
});
38+
39+
return missionList;
40+
41+
} catch (error) {
42+
throw new CustomError(ErrorCodes.InternalServerError,"사용자의 미션 목록 조회 중 오류가 발생하였습니다.");
2643
}
2744
};
28-
29-
3045
//연속 심기 미션 업데이트(로그인시..?)
3146
const updateConsecutivePlantingMission = async(memberId) => {
3247
const today = new Date(new Date().setHours(0, 0, 0, 0)); //시간 자정으로 맞춤
@@ -208,7 +223,7 @@ const setupMission= async(memberId) => {
208223
lastUpdated: new Date()
209224
}))
210225
});
211-
226+
212227
console.log('미션 초기할당이 완료되었습니다'); //확인용
213228
}catch(error){
214229
console.error('미션 초기 생성 중 오류:', error);

0 commit comments

Comments
 (0)