This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/database/scores/teams.js

30 lines
632 B
JavaScript
Raw Normal View History

2021-11-21 04:35:56 +00:00
const database = require('./../database');
class Team {
constructor(id, name) {
this.id = id;
this.name = name;
}
}
async function create(name, sportID) {
query = `INSERT INTO scores.teams(team_name, sport_id)
VALUES($1, $2)
RETURNING team_id;`;
const id = (await database.executeQuery(query, [name, sportID]))[0][0];
return new Team(id, name);
2021-11-21 04:38:08 +00:00
}
async function rename(id, name) {
query = `UPDATE scores.teams
SET team_name = $2
WHERE team_id = $1;`;
await database.executeQuery(query, [id, name]);
return new Team(id, name);
2021-11-21 04:35:56 +00:00
}