Skip to content

Commit

Permalink
Merge pull request #305 from boostcampwm-2022/develop
Browse files Browse the repository at this point in the history
v0.2.2 배포
  • Loading branch information
wkddntjr1123 authored Dec 13, 2022
2 parents 53ab800 + 54675df commit 33358b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
8 changes: 5 additions & 3 deletions backend/libs/common/filters/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ export class HttpExceptionFilter implements ExceptionFilter {
public catch(exception: Error, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
if (!(exception instanceof HttpException)) {
if (!(exception instanceof HttpException) || exception.getStatus() >= 500) {
logger.error(exception);
exception = new InternalServerErrorException('Unknown Error');
logger.error(`${exception.stack}`);
return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse());
}
return response.status((exception as HttpException).getStatus()).json((exception as HttpException).getResponse());
logger.log(exception);
return response.status(exception.getStatus()).json(exception.getResponse());
}
}
24 changes: 10 additions & 14 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ export class UserService {
if (!user) {
try {
user = await this.updateUser(lowerUsername, githubToken);
if (!user.scoreHistory) {
user.scoreHistory = [];
}
user.scoreHistory.push({ date: new Date(), score: user.score });
user = await this.userRepository.createOrUpdate(user);
} catch {
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
}
}
const { totalRank, tierRank } =
Expand Down Expand Up @@ -79,18 +74,19 @@ export class UserService {
organizations,
pinnedRepositories,
};
if (!updatedUser.scoreHistory) {
updatedUser.scoreHistory = [];

if (!updatedUser?.scoreHistory?.length) {
updatedUser.scoreHistory = [{ date: new Date(), score: updatedUser.score }];
}
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const utc = updatedUser.scoreHistory[updatedUser.scoreHistory.length - 1].date.getTime();
if (new Date(utc + KR_TIME_DIFF).getDate() == new Date().getDate()) {
if (new Date(utc + KR_TIME_DIFF).getDate() === new Date().getDate()) {
updatedUser.scoreHistory.pop();
updatedUser.scoreHistory.push({
date: new Date(),
score: updatedUser.score,
});
}
updatedUser.scoreHistory.push({
date: new Date(),
score: updatedUser.score,
});
if (updatedUser.scoreHistory.length > 1) {
updatedUser.scoreDifference =
updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score;
Expand Down Expand Up @@ -274,7 +270,7 @@ export class UserService {
primaryLanguages: Array.from(languagesScore.keys()).slice(0, 3),
};
} catch {
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
throw new HttpException(`can't update this user.`, HttpStatus.SERVICE_UNAVAILABLE);
}
}

Expand Down

0 comments on commit 33358b9

Please sign in to comment.