Create function to retrieve divisions from database
parent
2db5bc4480
commit
6e108ef975
|
@ -14,11 +14,17 @@ class Division {
|
|||
|
||||
|
||||
|
||||
function getGenderID(gender) {
|
||||
return (gender == genders.male) ? "M" : "F";
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 genderID = getGenderID(gender);
|
||||
const id = (await database.executeQuery(query, [name, genderID, sportID]))[0][0];
|
||||
return new Division(id, name);
|
||||
}
|
||||
|
@ -38,3 +44,18 @@ async function remove(id) {
|
|||
name = (await database.executeQuery(query, [id]))[0][0];
|
||||
return new Division(id, name);
|
||||
}
|
||||
|
||||
async function retrieveBySportAndGender(sportID, gender) {
|
||||
query = `SELECT *
|
||||
FROM scores.divisions
|
||||
WHERE sport_id = $1 AND gender = $2
|
||||
ORDER BY division_name;`;
|
||||
const genderID = getGenderID(gender);
|
||||
const table = await database.executeQuery(query, [sportID, genderID]);
|
||||
|
||||
const divisionsList = [];
|
||||
table.forEach((row) => {
|
||||
divisionsList.push(new Division(row[0], row[1]));
|
||||
});
|
||||
return divisionsList;
|
||||
}
|
Reference in New Issue