Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanRomero03 committed Nov 2, 2024
1 parent 6cea752 commit ee457ee
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/server/api/routers/scoreboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ type TeamScores = {
total: number;
};

import { Role } from "@prisma/client";
import { createTRPCRouter, publicProcedure } from "../trpc";
import { Round } from "rbrgs/lib/round";

export const scoreboardRouter = createTRPCRouter({
getScoreboard: publicProcedure.query(async ({ ctx }) => {
// Check if scoreboard frozen
const config = await ctx.db.config.findFirst();
const isFrozen = config?.freeze ?? false;
const isAdmin = ctx.session?.user.role == Role.ADMIN;
let isFrozen = config?.freeze ?? false;
if (isAdmin) {
isFrozen = false;
}

// Fetch all teams
const teams = await ctx.db.team.findMany({
Expand Down Expand Up @@ -103,7 +108,7 @@ export const scoreboardRouter = createTRPCRouter({
A: [] as number[],
B: [] as number[],
C: [] as number[],
}
};

for (const round of Object.values(scores.rounds)) {
challenge_scores_sorted.A.push(round.challengeA);
Expand All @@ -125,7 +130,8 @@ export const scoreboardRouter = createTRPCRouter({
// 0,
// );

scores.total = challenge_scores_sorted.A.reduce((sum, score) => sum + score, 0) +
scores.total =
challenge_scores_sorted.A.reduce((sum, score) => sum + score, 0) +
challenge_scores_sorted.B.reduce((sum, score) => sum + score, 0) +
challenge_scores_sorted.C.reduce((sum, score) => sum + score, 0);

Expand All @@ -138,6 +144,10 @@ export const scoreboardRouter = createTRPCRouter({

isScoreboardFrozen: publicProcedure.query(async ({ ctx }) => {
const config = await ctx.db.config.findFirst();
const isAdmin = ctx.session?.user.role == Role.ADMIN;
if (isAdmin) {
return false;
}
return config?.freeze ?? false;
}),
});

0 comments on commit ee457ee

Please sign in to comment.