Save tournamentTeamId for TournamentMatchGameResultParticipant (multi-team work)

This commit is contained in:
Kalle 2024-12-15 12:14:17 +02:00
parent 58dc9068da
commit dd94bb2396
6 changed files with 37 additions and 7 deletions

View File

@ -530,6 +530,8 @@ export interface TournamentMatchGameResult {
export interface TournamentMatchGameResultParticipant {
matchGameResultId: number;
userId: number;
// it only started mattering when we added the possibility to join many teams in a tournament, null for legacy events
tournamentTeamId: number | null;
}
export interface TournamentResult {

View File

@ -346,7 +346,7 @@ function EditScoreForm({
<input
type="hidden"
name="rosters"
value={JSON.stringify(checkedPlayers.flat())}
value={JSON.stringify(checkedPlayers)}
/>
{points ? (
<input type="hidden" name="points" value={JSON.stringify(points)} />

View File

@ -2,14 +2,15 @@ import { sql } from "~/db/sql";
const stm = sql.prepare(/* sql */ `
insert into "TournamentMatchGameResultParticipant"
("matchGameResultId", "userId")
("matchGameResultId", "userId", "tournamentTeamId")
values
(@matchGameResultId, @userId)
(@matchGameResultId, @userId, @tournamentTeamId)
`);
export function insertTournamentMatchGameResultParticipant(args: {
matchGameResultId: number;
userId: number;
tournamentTeamId: number;
}) {
stm.run(args);
}

View File

@ -211,10 +211,18 @@ export const action: ActionFunction = async ({ params, request }) => {
opponentTwoPoints: data.points?.[1] ?? null,
});
for (const userId of [...teamOneRoster, ...teamTwoRoster]) {
for (const userId of teamOneRoster) {
insertTournamentMatchGameResultParticipant({
matchGameResultId: result.id,
userId,
tournamentTeamId: match.opponentOne!.id!,
});
}
for (const userId of teamTwoRoster) {
insertTournamentMatchGameResultParticipant({
matchGameResultId: result.id,
userId,
tournamentTeamId: match.opponentTwo!.id!,
});
}
})();
@ -333,7 +341,8 @@ export const action: ActionFunction = async ({ params, request }) => {
);
validate(result, "Result not found");
validate(
data.rosters.length === tournament.minMembersPerTeam * 2,
data.rosters[0].length === tournament.minMembersPerTeam &&
data.rosters[1].length === tournament.minMembersPerTeam,
"Invalid roster length",
);
@ -377,10 +386,18 @@ export const action: ActionFunction = async ({ params, request }) => {
deleteParticipantsByMatchGameResultId(result.id);
for (const userId of data.rosters) {
for (const userId of data.rosters[0]) {
insertTournamentMatchGameResultParticipant({
matchGameResultId: result.id,
userId,
tournamentTeamId: match.opponentOne!.id!,
});
}
for (const userId of data.rosters[1]) {
insertTournamentMatchGameResultParticipant({
matchGameResultId: result.id,
userId,
tournamentTeamId: match.opponentTwo!.id!,
});
}
})();

View File

@ -13,7 +13,10 @@ import * as PreparedMaps from "./core/PreparedMaps";
const activeRosterPlayerIds = z.preprocess(safeJSONParse, z.array(id));
const bothTeamPlayerIds = z.preprocess(safeJSONParse, z.array(id));
const bothTeamPlayerIds = z.preprocess(
safeJSONParse,
z.tuple([z.array(id), z.array(id)]),
);
const reportedMatchPosition = z.preprocess(
Number,

View File

@ -0,0 +1,7 @@
export function up(db) {
db.transaction(() => {
db.prepare(
/* sql */ `alter table "TournamentMatchGameResultParticipant" add "tournamentTeamId" integer`,
).run();
})();
}