Skip to content

Commit f871382

Browse files
committed
fix: 새로운 유저 update시 scoreHistory로 인해 발생하던 에러 수정
1 parent a7ecf0e commit f871382

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

backend/src/user/user.service.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ export class UserService {
3636
if (!user) {
3737
try {
3838
user = await this.updateUser(lowerUsername, githubToken);
39-
if (!user.scoreHistory) {
40-
user.scoreHistory = [];
41-
}
42-
user.scoreHistory.push({ date: new Date(), score: user.score });
43-
user = await this.userRepository.createOrUpdate(user);
4439
} catch {
45-
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
40+
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
4641
}
4742
}
4843
const { totalRank, tierRank } =
@@ -79,18 +74,19 @@ export class UserService {
7974
organizations,
8075
pinnedRepositories,
8176
};
82-
if (!updatedUser.scoreHistory) {
83-
updatedUser.scoreHistory = [];
77+
78+
if (!updatedUser?.scoreHistory?.length) {
79+
updatedUser.scoreHistory = [{ date: new Date(), score: updatedUser.score }];
8480
}
8581
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
8682
const utc = updatedUser.scoreHistory[updatedUser.scoreHistory.length - 1].date.getTime();
87-
if (new Date(utc + KR_TIME_DIFF).getDate() == new Date().getDate()) {
83+
if (new Date(utc + KR_TIME_DIFF).getDate() === new Date().getDate()) {
8884
updatedUser.scoreHistory.pop();
85+
updatedUser.scoreHistory.push({
86+
date: new Date(),
87+
score: updatedUser.score,
88+
});
8989
}
90-
updatedUser.scoreHistory.push({
91-
date: new Date(),
92-
score: updatedUser.score,
93-
});
9490
if (updatedUser.scoreHistory.length > 1) {
9591
updatedUser.scoreDifference =
9692
updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score;
@@ -274,7 +270,7 @@ export class UserService {
274270
primaryLanguages: Array.from(languagesScore.keys()).slice(0, 3),
275271
};
276272
} catch {
277-
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
273+
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
278274
}
279275
}
280276

0 commit comments

Comments
 (0)