From ed3ed70f6f9226d201eb06c7b06493cd26f1877e Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 25 Jun 2026 19:17:31 +0300 Subject: [PATCH] Remember reported weapons even when map is undone, trim at the end --- .../ReportedWeaponRepository.server.ts | 27 ++++++++++++------- .../actions/to.$id.matches.$mid.server.ts | 23 ++++++++++++---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/features/sendouq-match/ReportedWeaponRepository.server.ts b/app/features/sendouq-match/ReportedWeaponRepository.server.ts index 75efaeb90..343611855 100644 --- a/app/features/sendouq-match/ReportedWeaponRepository.server.ts +++ b/app/features/sendouq-match/ReportedWeaponRepository.server.ts @@ -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, +) { + await (trx ?? db) .deleteFrom("ReportedWeapon") .where("tournamentMatchId", "=", tournamentMatchId) - .where("mapIndex", "=", mapIndex) + .where("mapIndex", ">=", gameCount) .execute(); } diff --git a/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts b/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts index a0654faa2..fbc9ad550 100644 --- a/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts +++ b/app/features/tournament-match/actions/to.$id.matches.$mid.server.ts @@ -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;