This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/database/scores/genders.js

48 lines
927 B
JavaScript
Raw Permalink Normal View History

const database = require('./../database');
class Gender {
constructor(name) {
this.name = name;
}
}
const MALE = new Gender("male");
const FEMALE = new Gender("female");
async function retrieveBySport(sportID) {
const query = `SELECT DISTINCT(gender)
FROM scores.divisions
WHERE sport_id = $1;`;
const table = await database.executeQuery(query, [sportID]);
const gendersList = [];
if(table.length == 0) {
return gendersList;
}
if(table.length == 2) {
gendersList.push(FEMALE);
gendersList.push(MALE);
return gendersList;
}
else if(table[0][0] = "F") {
gendersList.push(FEMALE);
return gendersList;
}
else if(table[0][0] = "M") {
gendersList.push(MALE);
return gendersList;
}
}
exports.MALE = MALE;
exports.FEMALE = FEMALE;
exports.retrieveBySport = retrieveBySport;