Skip to content

Commit f127b73

Browse files
committed
Match fixes
1 parent 88e90a1 commit f127b73

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/utils/matchHelpers.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getMatchChannel,
2222
getMatchData,
2323
getMatchResultsChannel,
24+
getMatchStatus,
2425
getQueueIdFromMatch,
2526
getQueueSettings,
2627
getStakeByName,
@@ -566,6 +567,15 @@ export async function endMatch(
566567
matchId: number,
567568
cancelled = false,
568569
): Promise<boolean> {
570+
console.log(`Attempting to close match ${matchId}`)
571+
572+
const matchCheck = await getMatchStatus(matchId)
573+
if (!matchCheck) {
574+
console.log(`match ${matchId} already closed, aborting`)
575+
return true
576+
}
577+
578+
await closeMatch(matchId)
569579
console.log(`Ending match ${matchId}, cancelled: ${cancelled}`)
570580

571581
if (cancelled) {
@@ -623,7 +633,9 @@ export async function endMatch(
623633
// Save elo_change and winstreak to database
624634
const updatePromises = teamResults.teams.flatMap((team) =>
625635
team.players.map(async (player) => {
626-
console.log(`Team ${team} player ${player} in match ${matchId}`)
636+
console.log(
637+
`Team ${team.id} player ${player.user_id} in match ${matchId}`,
638+
)
627639
// Update win streak
628640
await updatePlayerWinStreak(player.user_id, queueId, team.score == 1)
629641

@@ -644,7 +656,6 @@ export async function endMatch(
644656
try {
645657
// close match in DB
646658
console.log(`Ending match ${matchId}, cancelled: ${cancelled}`)
647-
await closeMatch(matchId)
648659

649660
// get log file using glob library
650661
// const pattern = path

src/utils/queryDB.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,14 @@ export async function getActiveMatches(): Promise<Matches[]> {
790790
return res.rows
791791
}
792792

793+
export async function getMatchStatus(matchId: number): Promise<boolean> {
794+
const res = await pool.query(`SELECT open FROM matches WHERE id = $1`, [
795+
matchId,
796+
])
797+
798+
return res.rows[0].open ?? false
799+
}
800+
793801
export async function closeMatch(matchId: number): Promise<boolean> {
794802
const res = await pool.query(
795803
`UPDATE matches SET open = false WHERE id = $1`,

0 commit comments

Comments
 (0)