Add function to remove sport
parent
2191218fe1
commit
c176e27987
|
@ -15,21 +15,30 @@ async function create(name) {
|
||||||
query = `INSERT INTO scores.sports(sport_name)
|
query = `INSERT INTO scores.sports(sport_name)
|
||||||
VALUES($1)
|
VALUES($1)
|
||||||
RETURNING sport_id;`;
|
RETURNING sport_id;`;
|
||||||
const sportId = await database.executeQuery(query, [name]);
|
const id = (await database.executeQuery(query, [name]))[0][0];
|
||||||
return new Sport(sportId[0][0], name);
|
return new Sport(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rename(id, name) {
|
async function rename(id, name) {
|
||||||
query = `UPDATE scores.sports
|
query = `UPDATE scores.sports
|
||||||
SET sport_name = $2
|
SET sport_name = $2
|
||||||
WHERE sport_id = $1;`
|
WHERE sport_id = $1;`;
|
||||||
await database.executeQuery(query, [id, name]);
|
await database.executeQuery(query, [id, name]);
|
||||||
return new Sport(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.create = create;
|
||||||
exports.rename = rename;
|
exports.rename = rename;
|
||||||
|
exports.remove = remove;
|
Reference in New Issue