2021-11-21 22:52:54 +00:00
|
|
|
const database = require('./../database');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 23:30:36 +00:00
|
|
|
class Gender {
|
|
|
|
constructor(name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const MALE = new Gender("male");
|
|
|
|
const FEMALE = new Gender("female");
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 22:59:07 +00:00
|
|
|
async function retrieveBySport(sportID) {
|
2021-11-26 23:16:01 +00:00
|
|
|
const query = `SELECT DISTINCT(gender)
|
|
|
|
FROM scores.divisions
|
2021-11-21 22:52:54 +00:00
|
|
|
WHERE sport_id = $1;`;
|
|
|
|
const table = await database.executeQuery(query, [sportID]);
|
|
|
|
|
|
|
|
const gendersList = [];
|
|
|
|
|
2021-11-21 23:24:43 +00:00
|
|
|
if(table.length == 0) {
|
|
|
|
return gendersList;
|
|
|
|
}
|
|
|
|
if(table.length == 2) {
|
2021-11-21 23:39:51 +00:00
|
|
|
gendersList.push(FEMALE);
|
|
|
|
gendersList.push(MALE);
|
2021-11-21 23:24:43 +00:00
|
|
|
return gendersList;
|
2021-11-21 22:52:54 +00:00
|
|
|
}
|
|
|
|
else if(table[0][0] = "F") {
|
2021-11-21 23:39:51 +00:00
|
|
|
gendersList.push(FEMALE);
|
2021-11-21 23:24:43 +00:00
|
|
|
return gendersList;
|
2021-11-21 22:52:54 +00:00
|
|
|
}
|
|
|
|
else if(table[0][0] = "M") {
|
2021-11-21 23:39:51 +00:00
|
|
|
gendersList.push(MALE);
|
2021-11-21 23:24:43 +00:00
|
|
|
return gendersList;
|
2021-11-21 22:52:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 23:30:36 +00:00
|
|
|
exports.MALE = MALE;
|
|
|
|
exports.FEMALE = FEMALE;
|
2021-11-21 22:57:09 +00:00
|
|
|
exports.retrieveBySport = retrieveBySport;
|