diff --git a/src/server/index.js b/src/server/index.js index f10e519..c8ffd27 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -137,6 +137,23 @@ api.get("/team/:teamId", (req, res) => { .catch(err => res.send({"status": "error", "data": err})); }); +api.post("/team/:teamId/delete", (req, res) => { + let teamId = req.params.teamId; + if (isNaN(teamId)) { + res.json({"status": "error", "data": "teamId must be a number"}); + return + } + try { + teamId = parseInt(teamId); + } catch (err) { + res.json({"status": "error", "data": "teamId must be a number"}); + return + } + tmdb.deleteTeam(teamId) + .then(match => res.send({"status": "OK", "data": match})) + .catch(err => res.send({"status": "error", "data": err})); +}); + api.post("/team/:teamId/edit", (req, res) => { let teamId = req.params.teamId; let teamName = req.body.name; diff --git a/src/server/management/initDB.sql b/src/server/management/initDB.sql index c33966f..a858525 100644 --- a/src/server/management/initDB.sql +++ b/src/server/management/initDB.sql @@ -33,9 +33,9 @@ CREATE TABLE matches ( tier INTEGER, FOREIGN KEY (tournamentId) REFERENCES tournaments (id), - FOREIGN KEY (team1Id) REFERENCES teams (id), - FOREIGN KEY (team2Id) REFERENCES teams (id), - FOREIGN KEY (winnerId) REFERENCES teams (id) + FOREIGN KEY (team1Id) REFERENCES teams (id) ON DELETE SET NULL, + FOREIGN KEY (team2Id) REFERENCES teams (id) ON DELETE SET NULL, + FOREIGN KEY (winnerId) REFERENCES teams (id) ON DELETE SET NULL ); CREATE TABLE players ( diff --git a/src/server/tmdb.js b/src/server/tmdb.js index 7b0c5ca..39c00ff 100644 --- a/src/server/tmdb.js +++ b/src/server/tmdb.js @@ -8,6 +8,7 @@ module.exports = { getTeam: getTeam, createTeam: createTeam, editTeam: editTeam, + deleteTeam: deleteTeam, getMatch: getMatch, setMatchWinner: setMatchWinner, createTournament: createTournament, @@ -338,7 +339,6 @@ function deleteTeam(teamId) { console.log(err); reject(err); } else { - resolve("Team deleted"); } });