sendou.ink/app/features/tournament/queries/upsertCounterpickMaps.server.ts
Kalle c0ec15b7de
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Unify db type files
2025-03-21 21:47:08 +02:00

38 lines
875 B
TypeScript

import { sql } from "~/db/sql";
import type { Tables } from "~/db/tables";
import type { MapPool } from "~/features/map-list-generator/core/map-pool";
const deleteCounterpickMapsByTeamIdStm = sql.prepare(/* sql */ `
delete from
"MapPoolMap"
where
"tournamentTeamId" = @tournamentTeamId
`);
const addCounterpickMapStm = sql.prepare(/* sql */ `
insert into
"MapPoolMap" ("tournamentTeamId", "stageId", "mode")
values
(@tournamentTeamId, @stageId, @mode)
`);
export const upsertCounterpickMaps = sql.transaction(
({
tournamentTeamId,
mapPool,
}: {
tournamentTeamId: Tables["TournamentTeam"]["id"];
mapPool: MapPool;
}) => {
deleteCounterpickMapsByTeamIdStm.run({ tournamentTeamId });
for (const { stageId, mode } of mapPool.stageModePairs) {
addCounterpickMapStm.run({
tournamentTeamId,
stageId,
mode,
});
}
},
);