51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
const database = require('./../database');
|
|
|
|
|
|
|
|
|
|
|
|
class Season {
|
|
constructor(id, year) {
|
|
this.id = id;
|
|
this.year = year;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function add(year) {
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
async function retrieveAll() {
|
|
const query = `SELECT *
|
|
FROM scores.seasons
|
|
ORDER BY school_year DESC;`;
|
|
const table = await database.executeQuery(query);
|
|
|
|
const seasonsList = [];
|
|
table.forEach((row) => {
|
|
seasonsList.push(new Season(row[0], row[1]));
|
|
});
|
|
return seasonsList;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.add = add;
|
|
exports.remove = remove;
|
|
exports.retrieveAll = retrieveAll; |