Added prize field

This commit is contained in:
Felix Albrigtsen 2022-04-23 13:08:03 +02:00
parent cd83a4944a
commit 8c6b5e8326
3 changed files with 11 additions and 8 deletions

View File

@ -183,6 +183,7 @@ api.post("/tournament/:tournamentId/edit", (req, res) => {
tournamentId = parseInt(tournamentId); tournamentId = parseInt(tournamentId);
let name = req.body.name; let name = req.body.name;
let description = req.body.description; let description = req.body.description;
let prize = req.body.prize;
let startDate = req.body.startDate; let startDate = req.body.startDate;
let endDate = req.body.endDate; let endDate = req.body.endDate;
console.log(startDate); console.log(startDate);
@ -211,7 +212,7 @@ api.post("/tournament/:tournamentId/edit", (req, res) => {
return return
} }
tmdb.editTournament(tournamentId, name, description, startDate, endDate) tmdb.editTournament(tournamentId, name, description, prize, startDate, endDate)
.then(msg => res.json({"status": "OK", "data": msg})) .then(msg => res.json({"status": "OK", "data": msg}))
.catch(err => res.json({"status": "error", "data": err})); .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")); console.log(req.get("Content-Type"));
let name = req.body.name; let name = req.body.name;
let description = req.body.description; let description = req.body.description;
let prize = req.body.prize;
let teamLimit = req.body.teamLimit; let teamLimit = req.body.teamLimit;
let startDate = req.body.startDate; //TODO: timezones, 2 hr skips let startDate = req.body.startDate; //TODO: timezones, 2 hr skips
let endDate = req.body.endDate; let endDate = req.body.endDate;
@ -410,7 +412,7 @@ api.post("/tournament/create", async (req, res) => {
} }
console.log(startDate); 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})) .then(msg => res.json({"status": "OK", "data": msg}))
.catch(err => res.json({"status": "error", "data": err})); .catch(err => res.json({"status": "error", "data": err}));
}); });

View File

@ -10,6 +10,7 @@ CREATE TABLE tournaments (
id INTEGER PRIMARY KEY AUTO_INCREMENT, id INTEGER PRIMARY KEY AUTO_INCREMENT,
name TEXT NOT NULL, name TEXT NOT NULL,
description TEXT, description TEXT,
prize TEXT,
teamLimit INTEGER NOT NULL, teamLimit INTEGER NOT NULL,
startTime DATETIME NOT NULL, startTime DATETIME NOT NULL,
endTime DATETIME NOT NULL endTime DATETIME NOT NULL

View File

@ -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', ' '); startDate = startDate.toISOString().slice(0, 19).replace('T', ' ');
endDate = endDate.toISOString().slice(0, 19).replace('T', ' '); endDate = endDate.toISOString().slice(0, 19).replace('T', ' ');
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
connection.query("INSERT INTO tournaments (name, description, startTime, endTime, teamLimit) VALUES (?, ?, ?, ?, ?)", connection.query("INSERT INTO tournaments (name, description, prize, startTime, endTime, teamLimit) VALUES (?, ?, ?, ?, ?, ?)",
[escapeString(name), escapeString(description), startDate, endDate, teamLimit], async (err, sets) => { [escapeString(name), escapeString(description), escapeString(prize), startDate, endDate, teamLimit], async (err, sets) => {
if (err) { if (err) {
console.log(err); console.log(err);
reject(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', ' '); startDate = startDate.toISOString().slice(0, 19).replace('T', ' ');
endDate = endDate.toISOString().slice(0, 19).replace('T', ' '); endDate = endDate.toISOString().slice(0, 19).replace('T', ' ');
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
connection.query("UPDATE tournaments SET name = ?, description = ?, startTime = ?, endTime = ? WHERE id = ?", connection.query("UPDATE tournaments SET name = ?, description = ?, prize = ?, startTime = ?, endTime = ? WHERE id = ?",
[escapeString(name), escapeString(description), startDate, endDate, escapeString(tournamentId)], (err, sets) => { [escapeString(name), escapeString(description), escapeString(prize), startDate, endDate, escapeString(tournamentId)], (err, sets) => {
if (err) { if (err) {
console.log(err); console.log(err);
reject(err); reject(err);