From 8c6b5e83261acce2830e0697be9a9b97f645f2b8 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sat, 23 Apr 2022 13:08:03 +0200 Subject: [PATCH] Added prize field --- src/server/index.js | 6 ++++-- src/server/management/initDB.sql | 1 + src/server/tmdb.js | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/server/index.js b/src/server/index.js index 7a23223..2c75a10 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -183,6 +183,7 @@ api.post("/tournament/:tournamentId/edit", (req, res) => { tournamentId = parseInt(tournamentId); let name = req.body.name; let description = req.body.description; + let prize = req.body.prize; let startDate = req.body.startDate; let endDate = req.body.endDate; console.log(startDate); @@ -211,7 +212,7 @@ api.post("/tournament/:tournamentId/edit", (req, res) => { return } - tmdb.editTournament(tournamentId, name, description, startDate, endDate) + tmdb.editTournament(tournamentId, name, description, prize, startDate, endDate) .then(msg => res.json({"status": "OK", "data": msg})) .catch(err => res.json({"status": "error", "data": err})); @@ -370,6 +371,7 @@ api.post("/tournament/create", async (req, res) => { console.log(req.get("Content-Type")); let name = req.body.name; let description = req.body.description; + let prize = req.body.prize; let teamLimit = req.body.teamLimit; let startDate = req.body.startDate; //TODO: timezones, 2 hr skips let endDate = req.body.endDate; @@ -410,7 +412,7 @@ api.post("/tournament/create", async (req, res) => { } console.log(startDate); - tmdb.createTournament(name, description, startDate, endDate, teamLimit) + tmdb.createTournament(name, description, prize, startDate, endDate, teamLimit) .then(msg => res.json({"status": "OK", "data": msg})) .catch(err => res.json({"status": "error", "data": err})); }); diff --git a/src/server/management/initDB.sql b/src/server/management/initDB.sql index a3b5beb..0aa0eef 100644 --- a/src/server/management/initDB.sql +++ b/src/server/management/initDB.sql @@ -10,6 +10,7 @@ CREATE TABLE tournaments ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL, description TEXT, + prize TEXT, teamLimit INTEGER NOT NULL, startTime DATETIME NOT NULL, endTime DATETIME NOT NULL diff --git a/src/server/tmdb.js b/src/server/tmdb.js index bdd3423..d725350 100644 --- a/src/server/tmdb.js +++ b/src/server/tmdb.js @@ -274,12 +274,12 @@ function createMatch(tournamentId, parentMatchId, tier) { }); } -function createTournament(name, description, startDate, endDate, teamLimit) { +function createTournament(name, description, prize, startDate, endDate, teamLimit) { startDate = startDate.toISOString().slice(0, 19).replace('T', ' '); endDate = endDate.toISOString().slice(0, 19).replace('T', ' '); return new Promise(function(resolve, reject) { - connection.query("INSERT INTO tournaments (name, description, startTime, endTime, teamLimit) VALUES (?, ?, ?, ?, ?)", - [escapeString(name), escapeString(description), startDate, endDate, teamLimit], async (err, sets) => { + connection.query("INSERT INTO tournaments (name, description, prize, startTime, endTime, teamLimit) VALUES (?, ?, ?, ?, ?, ?)", + [escapeString(name), escapeString(description), escapeString(prize), startDate, endDate, teamLimit], async (err, sets) => { if (err) { console.log(err); reject(err); @@ -307,12 +307,12 @@ function createTournament(name, description, startDate, endDate, teamLimit) { }); } -function editTournament(tournamentId, name, description, startDate, endDate) { +function editTournament(tournamentId, name, description, prize, startDate, endDate) { startDate = startDate.toISOString().slice(0, 19).replace('T', ' '); endDate = endDate.toISOString().slice(0, 19).replace('T', ' '); return new Promise(function(resolve, reject) { - connection.query("UPDATE tournaments SET name = ?, description = ?, startTime = ?, endTime = ? WHERE id = ?", - [escapeString(name), escapeString(description), startDate, endDate, escapeString(tournamentId)], (err, sets) => { + connection.query("UPDATE tournaments SET name = ?, description = ?, prize = ?, startTime = ?, endTime = ? WHERE id = ?", + [escapeString(name), escapeString(description), escapeString(prize), startDate, endDate, escapeString(tournamentId)], (err, sets) => { if (err) { console.log(err); reject(err);