Remember reported weapons even when map is undone, trim at the end
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled

This commit is contained in:
Kalle
2026-06-25 19:17:31 +03:00
parent a129c32b23
commit ed3ed70f6f
2 changed files with 36 additions and 14 deletions

View File

@@ -150,17 +150,26 @@ export async function deleteOwnByMapIndexTournament({
.execute();
}
export async function deleteByMapIndexTournament({
tournamentMatchId,
mapIndex,
}: {
tournamentMatchId: number;
mapIndex: number;
}) {
await db
/**
* Deletes reported weapons that no longer correspond to a played game, i.e.
* those reported "in advance" for map indexes beyond the games that ended up
* being played. Called when a set ends to trim leftover weapons that earlier
* score undos intentionally left dangling.
*/
export async function deleteExtraByTournamentMatchId(
{
tournamentMatchId,
gameCount,
}: {
tournamentMatchId: number;
gameCount: number;
},
trx?: Transaction<DB>,
) {
await (trx ?? db)
.deleteFrom("ReportedWeapon")
.where("tournamentMatchId", "=", tournamentMatchId)
.where("mapIndex", "=", mapIndex)
.where("mapIndex", ">=", gameCount)
.execute();
}

View File

@@ -262,6 +262,15 @@ export const action: ActionFunction = async ({ params, request }) => {
throw error;
}
if (setOver) {
// the set ended, so weapons reported in advance for map indexes
// beyond the games actually played are trimmed
await ReportedWeaponRepository.deleteExtraByTournamentMatchId({
tournamentMatchId: matchId,
gameCount: data.position + 1,
});
}
emitMatchUpdate = true;
emitTournamentUpdate = true;
setIsOver = setOver;
@@ -377,11 +386,6 @@ export const action: ActionFunction = async ({ params, request }) => {
}
})();
await ReportedWeaponRepository.deleteByMapIndexTournament({
tournamentMatchId: matchId,
mapIndex: data.position,
});
emitMatchUpdate = true;
emitTournamentUpdate = true;
@@ -812,6 +816,15 @@ export const action: ActionFunction = async ({ params, request }) => {
});
})();
// the set ended early so no further games will be played; trim weapons
// reported in advance for map indexes beyond the games actually played
const playedResults =
await TournamentMatchRepository.findResultsByMatchId(matchId);
await ReportedWeaponRepository.deleteExtraByTournamentMatchId({
tournamentMatchId: matchId,
gameCount: playedResults.length,
});
emitMatchUpdate = true;
emitTournamentUpdate = true;
setIsOver = true;