Add functions to get division by ID
parent
fe659184f4
commit
1f55ba3ff9
|
@ -20,6 +20,10 @@ function getGenderID(gender) {
|
||||||
return (gender == genders.MALE) ? "M" : "F";
|
return (gender == genders.MALE) ? "M" : "F";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGenderFromID(genderID) {
|
||||||
|
return (genderID == "F") ? genders.FEMALE : genders.MALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function add(name, gender, sportID) {
|
async function add(name, gender, sportID) {
|
||||||
|
@ -69,12 +73,21 @@ async function retrieve(sportID = undefined, gender = undefined) {
|
||||||
|
|
||||||
const divisionsList = [];
|
const divisionsList = [];
|
||||||
table.forEach((row) => {
|
table.forEach((row) => {
|
||||||
let gender = (row[2] == "F") ? genders.FEMALE : genders.MALE;
|
divisionsList.push(new Division(row[0], row[1], getGenderFromID(row[2]), row[3]));
|
||||||
divisionsList.push(new Division(row[0], row[1], gender, row[3]));
|
|
||||||
});
|
});
|
||||||
return divisionsList;
|
return divisionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getFromID(id) {
|
||||||
|
const query = `SELECT division_id, division_name, gender, sport_id
|
||||||
|
FROM scores.divisions
|
||||||
|
WHERE division_id = $1;`;
|
||||||
|
const row = (await database.executeQuery(query, [id]))[0];
|
||||||
|
|
||||||
|
|
||||||
|
return new Division(id, row[1], getGenderFromID(row[2]), row[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,4 +95,5 @@ async function retrieve(sportID = undefined, gender = undefined) {
|
||||||
exports.add = add;
|
exports.add = add;
|
||||||
exports.rename = rename;
|
exports.rename = rename;
|
||||||
exports.remove = remove;
|
exports.remove = remove;
|
||||||
exports.retrieve = retrieve;
|
exports.retrieve = retrieve;
|
||||||
|
exports.getFromID = getFromID;
|
|
@ -32,6 +32,12 @@ export async function getDivisions(sportID = undefined, gender = undefined) {
|
||||||
return divisionsList;
|
return divisionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getDivision(divisionID) {
|
||||||
|
const response = await fetch(`/data/division?division=${divisionID}`);
|
||||||
|
const division = await response.json();
|
||||||
|
return division;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getTeams(sportID = undefined) {
|
export async function getTeams(sportID = undefined) {
|
||||||
let URL = '/data/teams?';
|
let URL = '/data/teams?';
|
||||||
if(sportID) URL += `sport=${+sportID}&`;
|
if(sportID) URL += `sport=${+sportID}&`;
|
||||||
|
|
|
@ -164,6 +164,74 @@ CATEGORIES.push(new Category(
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
CATEGORIES.push(new Category(
|
||||||
|
"games",
|
||||||
|
async function getGames() {
|
||||||
|
return await Data.getGames();
|
||||||
|
},
|
||||||
|
async function listGameHeaders() {
|
||||||
|
const headerRow = document.createElement('tr');
|
||||||
|
|
||||||
|
const teamsHeader = document.createElement('th');
|
||||||
|
teamsHeader.textContent = "Teams";
|
||||||
|
headerRow.appendChild(teamsHeader);
|
||||||
|
|
||||||
|
const scoreHeader = document.createElement('th');
|
||||||
|
headerRow.appendChild(scoreHeader);
|
||||||
|
|
||||||
|
const sportNameHeader = document.createElement('th');
|
||||||
|
sportNameHeader.textContent = "Sport";
|
||||||
|
headerRow.appendChild(sportNameHeader);
|
||||||
|
|
||||||
|
const divisionNameHeader = document.createElement('th');
|
||||||
|
headerRow.appendChild(divisionNameHeader);
|
||||||
|
|
||||||
|
const divisionGenderHeader = document.createElement('th');
|
||||||
|
headerRow.appendChild(divisionGenderHeader);
|
||||||
|
|
||||||
|
const dateHeader = document.createElement('th');
|
||||||
|
dateHeader.textContent = "Date";
|
||||||
|
headerRow.appendChild(dateHeader);
|
||||||
|
|
||||||
|
itemsListTable.appendChild(headerRow);
|
||||||
|
},
|
||||||
|
function listGame(game, row) {
|
||||||
|
const teamsCell = document.createElement('td');
|
||||||
|
const team1NameSpan = document.createElement('span');
|
||||||
|
Data.getTeamName(game.team1ID)
|
||||||
|
.then(data => team1NameSpan.textContent = data);
|
||||||
|
teamsCell.appendChild(team1NameSpan);
|
||||||
|
const team2NameSpan = document.createElement('span');
|
||||||
|
Data.getTeamName(game.team2ID)
|
||||||
|
.then(data => team2NameSpan.textContent = data);
|
||||||
|
teamsCell.appendChild(team2NameSpan);
|
||||||
|
row.appendChild(teamsCell);
|
||||||
|
|
||||||
|
const scoresCell = document.createElement('td');
|
||||||
|
const team1ScoreSpan = document.createElement('span');
|
||||||
|
team1ScoreSpan.textContent = game.team1Score;
|
||||||
|
scoresCell.appendChild(team1ScoreSpan);
|
||||||
|
const team2ScoreSpan = document.createElement('span');
|
||||||
|
team2ScoreSpan.textContent = game.team2Score;
|
||||||
|
scoresCell.appendChild(team2ScoreSpan);
|
||||||
|
row.appendChild(scoresCell);
|
||||||
|
|
||||||
|
const sportCell = document.createElement('td');
|
||||||
|
Data.getSportName(team.sportID)
|
||||||
|
.then(data => sportCell.textContent = data);
|
||||||
|
row.appendChild(sportCell);
|
||||||
|
},
|
||||||
|
async function addSeason() {
|
||||||
|
//
|
||||||
|
},
|
||||||
|
async function submitSeason() {
|
||||||
|
//
|
||||||
|
},
|
||||||
|
async function editSeason() {
|
||||||
|
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function listItems(category) {
|
async function listItems(category) {
|
||||||
|
|
|
@ -36,6 +36,11 @@ router.get('/divisions', function(req, res, next) {
|
||||||
.then(data => res.json(data));
|
.then(data => res.json(data));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.get('/division', function(req, res, next) {
|
||||||
|
divisions.getFromID(req.query.division)
|
||||||
|
.then(data => res.json(data));
|
||||||
|
})
|
||||||
|
|
||||||
router.get('/teams', function(req, res, next) {
|
router.get('/teams', function(req, res, next) {
|
||||||
teams.retrieve(req.query.sport)
|
teams.retrieve(req.query.sport)
|
||||||
.then(data => res.json(data));
|
.then(data => res.json(data));
|
||||||
|
|
Reference in New Issue