Minor bugfix

This commit is contained in:
Felix Albrigtsen 2022-04-23 11:53:50 +02:00
parent 9f58f902b8
commit eb70ef67b5
1 changed files with 13 additions and 17 deletions

View File

@ -165,23 +165,19 @@ async function setMatchWinner(matchId, winnerId) {
async function unsetContestantAndWinner(matchId, teamId) {
let match = await getMatch(matchId);
return new Promise(function(resolve, reject) {
unsetContestant(matchId, teamId)
.then(() => {
// Find what the child match that supplied the team
connection.query("SELECT * FROM matches WHERE parentMatchId = ? AND winnerId = ?", [matchId, teamId], (err, childMatches) => {
if (err) { console.log(err); reject(err); }
if (childMatches.length != 1) {
reject("Error: Could not find the correct child match");
return;
}
let childMatch = childMatches[0];
// Remove the winner from the child match
setMatchWinner(childMatch.id, null)
.then(() => { resolve(); })
.catch(err => { reject(err); });
});
})
.catch(err => { reject(err); });
// Find what the child match that supplied the team
connection.query("SELECT * FROM matches WHERE parentMatchId = ? AND winnerId = ?", [matchId, teamId], (err, childMatches) => {
if (err) { console.log(err); reject(err); }
if (childMatches.length != 1) {
reject("Error: Could not find the correct child match");
return;
}
let childMatch = childMatches[0];
// Remove the winner from the child match
setMatchWinner(childMatch.id, null)
.then(() => { resolve(); })
.catch(err => { reject(err); });
});
});
}