This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
2021-11-21 04:52:32 +00:00
|
|
|
const database = require('./../database');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Season {
|
|
|
|
constructor(id, year) {
|
|
|
|
this.id = id;
|
|
|
|
this.year = year;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-21 05:01:55 +00:00
|
|
|
async function add(year) {
|
2021-11-21 04:52:32 +00:00
|
|
|
const query = `INSERT INTO scores.seasons(school_year)
|
|
|
|
VALUES($1)
|
|
|
|
RETURNING season_id;`;
|
|
|
|
const id = (await database.executeQuery(query, [year]))[0][0];
|
|
|
|
return new Season(id, year);
|
2021-11-21 04:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function remove(id) {
|
|
|
|
const query = `DELETE FROM scores.seasons
|
|
|
|
WHERE season_id = $1
|
|
|
|
RETURNING school_year;`;
|
|
|
|
const year = (await database.executeQuery(query, [id]))[0][0];
|
|
|
|
return new Season(id, year);
|
2021-11-21 04:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function retrieveAll() {
|
|
|
|
const query = `SELECT *
|
|
|
|
FROM scores.seasons
|
2021-11-21 22:53:58 +00:00
|
|
|
ORDER BY school_year DESC;`;
|
2021-11-21 04:57:27 +00:00
|
|
|
const table = await database.executeQuery(query);
|
|
|
|
|
|
|
|
const seasonsList = [];
|
|
|
|
table.forEach((row) => {
|
|
|
|
seasonsList.push(new Season(row[0], row[1]));
|
|
|
|
});
|
|
|
|
return seasonsList;
|
2021-11-21 05:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.add = add;
|
|
|
|
exports.remove = remove;
|
|
|
|
exports.retrieveAll = retrieveAll;
|