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 c66645a914d70b1090625c7aeee6dafd1c12425b
parent 2ab6cb637a8a21ef6746cbe9c37aa566aa8a36c8
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Mon, 23 Sep 2024 23:12:36 +0200

fix(postgresql): return insert rows

Diffstat:
Msrc/api/db.cjs | 3+++
Msrc/api/server.cjs | 22+++++++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/api/db.cjs b/src/api/db.cjs @@ -186,6 +186,7 @@ async function addAthleteToHeat(athlete, heat) { ${athlete}, ${heat} ) + returning * ` return startlist } catch (error) { @@ -211,6 +212,7 @@ async function addAthlete(nr, firstname, lastname, birthday, school) { ${birthday}, ${school} ) + returning * ` return athlete } catch (error) { @@ -391,6 +393,7 @@ async function setScore(heat, athlete, judge, score) { on conflict (athlete, judge, heat) do update set score = ${score} where s.heat = ${heat} and s.athlete = ${athlete} and s.judge = ${judge} + returning * ` return scores } catch (error) { diff --git a/src/api/server.cjs b/src/api/server.cjs @@ -424,9 +424,13 @@ server.on('request', async (req, res) => { input.score, ); + if (scores.length < 1) { + throw new Error("Score not updated") + } + res.end(JSON.stringify({ message: 'Score update for heat, user and judge', - data: scores, + data: scores[0], })); } catch (error) { serverError(res, error); @@ -524,13 +528,17 @@ server.on('request', async (req, res) => { input = JSON.parse(b); console.log(' addAthleteToHeat request for:', input); - await db.addAthleteToHeat( + const startlist = await db.addAthleteToHeat( input.athlete, input.heat, ); + if (startlist.length < 1) { + throw new Error("Startlist not updated") + } res.end(JSON.stringify({ - message: 'Athlete added to startlist' + message: 'Athlete added to startlist', + data: startlist[0], })); } catch (error) { serverError(res, error); @@ -570,16 +578,20 @@ server.on('request', async (req, res) => { input = JSON.parse(b); console.log(' addAthlete request for:', input); - await db.addAthlete( + const athlete = await db.addAthlete( input.nr, input.firstname, input.lastname, input.birthday, input.school, ); + if (athlete.length < 1) { + throw new Error("Startlist not updated") + } res.end(JSON.stringify({ - message: 'Athlete created' + message: 'Athlete created', + data: athlete[0] })); } catch (error) { serverError(res, error);