Add rename sport rename function
parent
64f4f9fb32
commit
2191218fe1
|
@ -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;
|
||||
|
||||
|
||||
exports.create = create;
|
||||
exports.rename = rename;
|
Reference in New Issue