myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 78dd7a5bc4e8cdc7025dfb93eedfbd02358e866e
parent d8d967656b07f8fa2b1f2f37627ead006f5df957
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Mon, 23 Sep 2024 23:28:07 +0200

fix: scoreForHeatAndAthlete multiple judges

Diffstat:
Msrc/api/db.cjs | 6+++---
Msrc/api/server.cjs | 16++++++++--------
Msrc/frontend/Leaderboard.jsx | 10+++++-----
3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/api/db.cjs b/src/api/db.cjs @@ -330,7 +330,7 @@ async function startlistWithAthletes(heatId) { } } -async function scoreForHeatAndAthlete(heat, athlete) { +async function scoresForHeatAndAthlete(heat, athlete) { try { const score = await sql` select @@ -342,7 +342,7 @@ async function scoreForHeatAndAthlete(heat, athlete) { ` return score } catch (error) { - console.log('Error occurred in scoreForHeatAndAthlete:', error); + console.log('Error occurred in scoresForHeatAndAthlete:', error); throw error } } @@ -425,7 +425,7 @@ module.exports = { removeHeat, distinctStartlist, startlistWithAthletes, - scoreForHeatAndAthlete, + scoresForHeatAndAthlete, scoreSummaryForHeatAndAthlete, getScore, setScore, diff --git a/src/api/server.cjs b/src/api/server.cjs @@ -64,7 +64,7 @@ const paths = [ '/v1/leaderboard/removeHeat', '/v1/leaderboard/distinctStartlist', '/v1/leaderboard/startlistWithAthletes', - '/v1/leaderboard/scoreForHeatAndAthlete', + '/v1/leaderboard/scoresForHeatAndAthlete', '/v1/leaderboard/scoreSummaryForHeatAndAthlete', '/v1/leaderboard/getScore', '/v1/leaderboard/setScore', @@ -313,7 +313,7 @@ server.on('request', async (req, res) => { serverError(res, error); } }) - } else if (url.pathname === '/v1/leaderboard/scoreForHeatAndAthlete') { + } else if (url.pathname === '/v1/leaderboard/scoresForHeatAndAthlete') { let body = []; req.on('data', chunk => { body.push(chunk); @@ -324,20 +324,20 @@ server.on('request', async (req, res) => { throw new Error("Empty request body") } input = JSON.parse(b); - console.log(' scoreForHeatAndAthlete request with heat and athlete:', + console.log(' scoresForHeatAndAthlete request with heat and athlete:', input.heat, input.athlete); - const score = await db.scoreForHeatAndAthlete( + const scores = await db.scoresForHeatAndAthlete( input.heat, input.athlete ) - if (score.length < 1) { - throw new Error("Score not found") + if (scores.length < 1) { + throw new Error("No scores found") } res.end(JSON.stringify({ - message: 'Score for heat and athlete', - data: score[0], + message: 'Scores for heat and athlete', + data: scores, })); } catch(error) { serverError(res, error); diff --git a/src/frontend/Leaderboard.jsx b/src/frontend/Leaderboard.jsx @@ -40,8 +40,8 @@ export async function getStartlistForHeats(heatIds) { return data } -async function getScoreForHeatAndAthlete(heatId, athleteId) { - const res = await fetch(`${api_uri}:${api_port}/v1/leaderboard/scoreForHeatAndAthlete`, { +async function getScoresForHeatAndAthlete(heatId, athleteId) { + const res = await fetch(`${api_uri}:${api_port}/v1/leaderboard/scoresForHeatAndAthlete`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ @@ -89,14 +89,14 @@ async function getScoreSummary(heatIds) { for (const h of heatIds) { try { - const { scores } = await getScoreForHeatAndAthlete(h, i.athlete) + // this is an array, because the athlete can be scored by multiple judges + const scores = await getScoresForHeatAndAthlete(h, i.athlete) const { score_summary } = await getScoreSummaryForHeatAndAthlete(h, i.athlete) // add heat results of athlete to startlist entry i.heats.push({ heatId: h, - // this is an array, because the athlete can be scored by multiple judges - score: [scores], + scores: scores, summary: score_summary }) } catch (error) {