From c176e279877db26d5f4066656ad7eb06b4a67fed Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sat, 20 Nov 2021 17:58:29 -0700 Subject: [PATCH] Add function to remove sport --- database/scores/sports.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/database/scores/sports.js b/database/scores/sports.js index b1be445..bd719fc 100644 --- a/database/scores/sports.js +++ b/database/scores/sports.js @@ -15,21 +15,30 @@ async function create(name) { query = `INSERT INTO scores.sports(sport_name) VALUES($1) RETURNING sport_id;`; - const sportId = await database.executeQuery(query, [name]); - return new Sport(sportId[0][0], name); + const id = (await database.executeQuery(query, [name]))[0][0]; + return new Sport(id, name); } async function rename(id, name) { query = `UPDATE scores.sports SET sport_name = $2 - WHERE sport_id = $1;` + WHERE sport_id = $1;`; await database.executeQuery(query, [id, name]); return new Sport(id, name); } +async function remove(id) { + query = `DELETE FROM scores.sports + WHERE sport_id = $1 + RETURNING sport_name;`; + name = (await database.executeQuery(query, [id]))[0][0]; + return new Sport(id, name); +} + exports.create = create; -exports.rename = rename; \ No newline at end of file +exports.rename = rename; +exports.remove = remove; \ No newline at end of file