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