commit 2ab6cb637a8a21ef6746cbe9c37aa566aa8a36c8
parent 4e96d2d49541f54c1a22f9643c86970cfc9c97ac
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Mon, 23 Sep 2024 22:59:45 +0200
fix(postgresql): return insert rows
Diffstat:
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/api/db.cjs b/src/api/db.cjs
@@ -270,6 +270,7 @@ async function newHeat(name, heatLocation, plannedStart) {
${heatLocation},
${plannedStart}
)
+ returning *
`
return heat
} catch (error) {
@@ -358,7 +359,7 @@ async function scoreSummaryForHeatAndAthlete(heat, athlete) {
try {
const summary = await sql`
select score_summary
- from score_summary where heat = ${heat} and athlete = ${athlete}
+ from score_summary where heat_id = ${heat} and athlete_id = ${athlete}
`
return summary
} catch (error) {
diff --git a/src/frontend/Leaderboard.jsx b/src/frontend/Leaderboard.jsx
@@ -75,27 +75,29 @@ async function getScoreSummaryForHeatAndAthlete(heatId, athleteId) {
async function getScoreSummary(heatIds) {
const startListWithScores = []
+ let startlist = undefined
try {
- const startlist = await getStartlistForHeats(heatIds)
+ startlist = await getStartlistForHeats(heatIds)
} catch (error) {
console.error(error)
// fail silently & return empty startlist in case of errors
return []
}
- for (const i of startlist.data) {
+ for (const i of startlist) {
i.heats = []
for (const h of heatIds) {
try {
- const scores = await getScoreForHeatAndAthlete(h, i.athlete)
- const summary = await getScoreSummaryForHeatAndAthlete(h, i.athlete)
+ const { scores } = await getScoreForHeatAndAthlete(h, i.athlete)
+ const { score_summary } = await getScoreSummaryForHeatAndAthlete(h, i.athlete)
// add heat results of athlete to startlist entry
i.heats.push({
heatId: h,
- scores: scores.data,
- summary: summary.data.length > 0 ? summary.data[0].score_summary : 0
+ // this is an array, because the athlete can be scored by multiple judges
+ score: [scores],
+ summary: score_summary
})
} catch (error) {
// else don't push any heats (fail silently)
@@ -129,17 +131,22 @@ async function newHeatFromLeaderboard(e, {leaderboard, rankingComp, selectHeatRe
const formJson = Object.fromEntries(formData.entries());
// create new heat
- const heat = await addNewHeat(
- formJson.name,
- formJson.location,
- formJson.planned_start === '' ? null : formJson.planned_start
- )
+ let heat = undefined
+ try {
+ heat = await addNewHeat(
+ formJson.name,
+ formJson.location,
+ formJson.planned_start === '' ? null : formJson.planned_start
+ )
+ } catch (error) {
+ console.error(error)
+ }
const sortedBoard = leaderboard.sort(rankByHeat(rankingComp))
for (let i = 0; i < formJson.size && i < sortedBoard.length; i++ ) {
// add top N athletes from current leaderboard to new heat
try {
- await addAthleteToHeat(sortedBoard[i].athlete, data[0].id)
+ await addAthleteToHeat(sortedBoard[i].athlete, heat.id)
} catch (error) {
console.error(error)
}