diff --git a/database/scores/divisions.js b/database/scores/divisions.js new file mode 100644 index 0000000..0a0e8be --- /dev/null +++ b/database/scores/divisions.js @@ -0,0 +1,40 @@ +const database = require('./../database'); +const genders = require('../../constants/genders'); + + + + + +class Division { + constructor(id, name) { + this.id = id; + this.name = name; + } +} + + + +async function create(name, gender, sportID) { + query = `INSERT INTO scores.divisions(division_name,gender,sport_id) + VALUES($1,$2,$3) + RETURNING division_id;`; + const genderID = (gender == genders.male) ? "M" : "F"; + const id = (await database.executeQuery(query, [name, genderID, sportID]))[0][0]; + return new Division(id, name); +} + +async function rename(id, division) { + query = `UPDATE scores.divisions + SET division_name = $2 + WHERE division_id = $1;`; + await database.executeQuery(query, [id, name]); + return new Division(id, name); +} + +async function remove(id) { + query = `DELETE FROM scores.divisions + WHERE division_id = $1 + RETURNING division_name;`; + name = (await database.executeQuery(query, [id]))[0][0]; + return new Division(id, name); +} \ No newline at end of file