From e37b10596e7f45668bf5a7235eb512947353414e Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Sat, 20 Nov 2021 21:43:19 -0700 Subject: [PATCH] Add function to retrieve teams by sport --- database/scores/teams.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/database/scores/teams.js b/database/scores/teams.js index 3e09496..fe27d6b 100644 --- a/database/scores/teams.js +++ b/database/scores/teams.js @@ -35,4 +35,18 @@ async function remove(id) { RETURNING team_name;`; name = (await database.executeQuery(query, [id]))[0][0]; return new Team(id, name); +} + +async function retrieveBySport(sportID) { + query = `SELECT * + FROM scores.teams + WHERE sport_id = $1 + ORDER BY team_name;`; + const table = await database.executeQuery(query); + + const teamsList = []; + table.forEach((row) => { + teamsList.push(new Team(row[0], row[1])); + }); + return teamsList; } \ No newline at end of file