Skip to content

Commit

Permalink
Update rank and point endpoint to use point
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandiny committed Feb 27, 2021
1 parent d36fd31 commit 11f5004
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/controller/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,32 +480,15 @@ export class UserController {
try {
const id = +response.locals.auth.id;

const userScoreBoard = await this.globalScoreboardRepository.findOne({
const scoreData = await this.visitorRepository.findOne({ where: { userId: id } });
const rankData = await this.visitorRepository.count({
where: {
user: { id } as User
point: MoreThan(scoreData.point)
}
});
const totalCount = await this.visitorRepository.count();

let score = 0, rank = -1;
if (userScoreBoard) {
rank = 1;
score = userScoreBoard.score;

const scoreboardData = await this.globalScoreboardRepository.find({
where: {
score: MoreThan(score)
}
});


if (scoreboardData) {
rank = scoreboardData.length + 1;
}
}

const totalCount = await this.globalScoreboardRepository.count();

return responseGenerator(response, 200, "ok", { score, rank, total: totalCount });
return responseGenerator(response, 200, "ok", { score: scoreData.point, rank: rankData + 1, total: totalCount });

} catch (err) {
console.error(err);
Expand Down

0 comments on commit 11f5004

Please sign in to comment.