From 2191218fe1809c7cfb049d5ac47bb7fd30729658 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sat, 20 Nov 2021 17:52:09 -0700 Subject: [PATCH] Add rename sport rename function --- database/scores/sports.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/database/scores/sports.js b/database/scores/sports.js index abdea6b..b1be445 100644 --- a/database/scores/sports.js +++ b/database/scores/sports.js @@ -1,26 +1,35 @@ -const database = require('./database'); +const database = require('./../database'); class Sport { - constructor(id) { + constructor(id, name) { this.id = id; + this.name = name; } } -async function createSport(name) { + + +async function create(name) { query = `INSERT INTO scores.sports(sport_name) - VALUES($1);`; - await database.executeQuery(query, [name]); - - query = `SELECT sport_id FROM scores.sports - WHERE sport_name = $1` + VALUES($1) + RETURNING sport_id;`; const sportId = await database.executeQuery(query, [name]); - console.log(sportId); + return new Sport(sportId[0][0], name); +} - return new Sport(sportId[0][0]); +async function rename(id, name) { + query = `UPDATE scores.sports + SET sport_name = $2 + WHERE sport_id = $1;` + await database.executeQuery(query, [id, name]); + return new Sport(id, name); } -exports.createSport = createSport; \ No newline at end of file + + +exports.create = create; +exports.rename = rename; \ No newline at end of file