mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-27 14:04:01 -05:00
38 lines
875 B
TypeScript
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,
|
|
});
|
|
}
|
|
},
|
|
);
|