Add functions to retrieve sport by ID
parent
435748ae76
commit
b6f8b6bdaa
|
@ -48,6 +48,14 @@ async function retrieveAll() {
|
||||||
return sportsList;
|
return sportsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getFromID(id) {
|
||||||
|
const query = `SELECT sport_name
|
||||||
|
FROM scores.sports
|
||||||
|
WHERE sport_id = $1;`;
|
||||||
|
const name = (await database.executeQuery(query, [id]))[0][0];
|
||||||
|
return new Sport(id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,4 +63,5 @@ async function retrieveAll() {
|
||||||
exports.add = add;
|
exports.add = add;
|
||||||
exports.rename = rename;
|
exports.rename = rename;
|
||||||
exports.remove = remove;
|
exports.remove = remove;
|
||||||
exports.retrieveAll = retrieveAll;
|
exports.retrieveAll = retrieveAll;
|
||||||
|
exports.getFromID = getFromID;
|
|
@ -1,11 +1,17 @@
|
||||||
export async function getSports() {
|
export async function getSports() {
|
||||||
const response = await fetch('/data/sports');
|
const response = await fetch(`/data/sports`);
|
||||||
const sportsList = await response.json();
|
const sportsList = await response.json();
|
||||||
return sportsList;
|
return sportsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSportName(sportID) {
|
||||||
|
const response = await fetch(`/data/sport?sport=${sportID}`);
|
||||||
|
const sport = await response.json();
|
||||||
|
return sport.name;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getSeasons() {
|
export async function getSeasons() {
|
||||||
const response = await fetch('/data/seasons');
|
const response = await fetch(`/data/seasons`);
|
||||||
const seasonsList = await response.json();
|
const seasonsList = await response.json();
|
||||||
return seasonsList;
|
return seasonsList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,11 @@ router.get('/sports', function(req, res, next) {
|
||||||
.then(data => res.json(data));
|
.then(data => res.json(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/sport', function(req, res, next) {
|
||||||
|
sports.getFromID(req.query.sport)
|
||||||
|
.then(data => res.json(data));
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/seasons', function(req, res, next) {
|
router.get('/seasons', function(req, res, next) {
|
||||||
seasons.retrieveAll()
|
seasons.retrieveAll()
|
||||||
.then(data => res.json(data));
|
.then(data => res.json(data));
|
||||||
|
|
Reference in New Issue