34 lines
No EOL
1.1 KiB
JavaScript
34 lines
No EOL
1.1 KiB
JavaScript
const database = require('./../database');
|
|
|
|
|
|
|
|
|
|
|
|
class Game {
|
|
constructor(id, date, team1ID, team2ID, team1Score, team2Score) {
|
|
this.id = id;
|
|
this.date = date;
|
|
this.team1ID = team1ID;
|
|
this.team2ID = team2ID;
|
|
this.team1Score = team1Score;
|
|
this.team2Score = team2Score;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function add(divisionID, seasonID, date, team1ID, team2ID, team1Score, team2Score) {
|
|
const query = `INSERT INTO scores.games(division_id, season_id, game_date, team1_id, team2_id, team1_score, team2_score)
|
|
VALUES($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING game_id;`;
|
|
const id = (await database.executeQuery(query, [divisionID, seasonID, date, team1ID, team2ID, team1Score, team2Score]))[0][0];
|
|
return new Game(id, date, team1ID, team2ID, team1Score, team2Score);
|
|
}
|
|
|
|
async function remove(id) {
|
|
const query = `DELETE FROM scores.games
|
|
WHERE game_id = $1
|
|
RETURNING * ;`;
|
|
const row = (await database.executeQuery(query, [id]))[0];
|
|
return new Game(id, row[3], row[4], row[5], row[6], row[7]);
|
|
} |