Add rename sport rename function

main
sudoer777 2021-11-20 17:52:09 -07:00
parent 64f4f9fb32
commit 2191218fe1
1 changed files with 20 additions and 11 deletions

View File

@ -1,26 +1,35 @@
const database = require('./database'); const database = require('./../database');
class Sport { class Sport {
constructor(id) { constructor(id, name) {
this.id = id; this.id = id;
this.name = name;
} }
} }
async function createSport(name) {
async function create(name) {
query = `INSERT INTO scores.sports(sport_name) query = `INSERT INTO scores.sports(sport_name)
VALUES($1);`; VALUES($1)
await database.executeQuery(query, [name]); RETURNING sport_id;`;
query = `SELECT sport_id FROM scores.sports
WHERE sport_name = $1`
const sportId = await database.executeQuery(query, [name]); 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;
exports.create = create;
exports.rename = rename;