Add function to remove sport

main
sudoer777 2021-11-20 17:58:29 -07:00
parent 2191218fe1
commit c176e27987
1 changed files with 13 additions and 4 deletions

View File

@ -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;
exports.rename = rename;
exports.remove = remove;