From acb987ffd40854aeeab1541f596eb2ebc1db28c2 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sat, 20 Nov 2021 22:14:12 -0700 Subject: [PATCH] Add function to create game --- database/scores/games.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 database/scores/games.js diff --git a/database/scores/games.js b/database/scores/games.js new file mode 100644 index 0000000..256919b --- /dev/null +++ b/database/scores/games.js @@ -0,0 +1,26 @@ +const database = require('./../database'); + + + + + +class Game { + constructor(id, date, team1ID, team2ID, team1Score, team2Score) { + this.id = id; + this.date = date; + this.team1ID = team1ID; + this.team2ID = team2ID; + this.team1Score = team1Score; + this.team2Score = team2Score; + } +} + + + +async function add(divisionID, seasonID, date, team1ID, team2ID, team1Score, team2Score) { + const query = `INSERT INTO scores.games(division_id, season_id, game_date, team1_id, team2_id, team1_score, team2_score) + VALUES($1, $2, $3, $4, $5, $6, $7) + RETURNING game_id;`; + const id = (await database.executeQuery(query, [divisionID, seasonID, date, team1ID, team2ID, team1Score, team2Score]))[0][0]; + return new Game(id, date, team1ID, team2ID, team1Score, team2Score); +} \ No newline at end of file