Add functions to get division by ID

main
sudoer777 2021-11-22 16:27:50 -07:00
parent fe659184f4
commit 1f55ba3ff9
4 changed files with 96 additions and 3 deletions

View File

@ -20,6 +20,10 @@ function getGenderID(gender) {
return (gender == genders.MALE) ? "M" : "F";
}
function getGenderFromID(genderID) {
return (genderID == "F") ? genders.FEMALE : genders.MALE;
}
async function add(name, gender, sportID) {
@ -69,12 +73,21 @@ async function retrieve(sportID = undefined, gender = undefined) {
const divisionsList = [];
table.forEach((row) => {
let gender = (row[2] == "F") ? genders.FEMALE : genders.MALE;
divisionsList.push(new Division(row[0], row[1], gender, row[3]));
divisionsList.push(new Division(row[0], row[1], getGenderFromID(row[2]), row[3]));
});
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.rename = rename;
exports.remove = remove;
exports.retrieve = retrieve;
exports.retrieve = retrieve;
exports.getFromID = getFromID;

View File

@ -32,6 +32,12 @@ export async function getDivisions(sportID = undefined, gender = undefined) {
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) {
let URL = '/data/teams?';
if(sportID) URL += `sport=${+sportID}&`;

View File

@ -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) {

View File

@ -36,6 +36,11 @@ router.get('/divisions', function(req, res, next) {
.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) {
teams.retrieve(req.query.sport)
.then(data => res.json(data));