Skip to content

Commit

Permalink
fix: sort rankings on profile based on rank
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes committed Nov 4, 2024
1 parent fb3265e commit 2db49bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,18 @@ export const getUserRanking = async function(prisma: PrismaClient, rankingType:
return (userRanking ? userRanking : null);
}

export const getUserRankingAcrossAllRankings = async function(prisma: PrismaClient, userId: number, atDateTime: Date = new Date()): Promise<{ [key: string]: SingleRanking | null; }> {
export const getUserRankingAcrossAllRankings = async function(prisma: PrismaClient, userId: number, atDateTime: Date = new Date()): Promise<SingleRanking[]> {
const rankings = await prisma.codamCoalitionRanking.findMany({
select: {
type: true,
}
});
const userRankings: { [key: string]: SingleRanking | null } = {};
const userRankings: SingleRanking[] = [];
for (const ranking of rankings) {
const userRanking = await getUserRanking(prisma, ranking.type, userId, atDateTime);
userRankings[ranking.type] = userRanking;
if (userRanking) {
userRankings.push(userRanking);
}
}
return userRankings;
return userRankings.sort((a, b) => a.rank - b.rank);
};
6 changes: 2 additions & 4 deletions templates/profile.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
<li>Coalition: {{ profileUser.coalition_users[0].coalition.name }}</li>
<li>Total score: {{ totalScore | thousands }}</li>
<li>Coalition ranking: #{{ ranking }}</li>
{% for rankingType, userRanking in userRankings %}
{% if userRanking %}
<li>{{ userRanking.rankingName }} ranking: #{{ userRanking.rank }}</li>
{% endif %}
{% for userRanking in userRankings %}
<li>{{ userRanking.rankingName }} ranking: #{{ userRanking.rank }}</li>
{% endfor %}
</ul>
</div>
Expand Down

0 comments on commit 2db49bd

Please sign in to comment.