mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-13 22:56:05 -05:00
Remember reported weapons even when map is undone, trim at the end
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user