mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Save tournamentTeamId for TournamentMatchGameResultParticipant (multi-team work)
This commit is contained in:
parent
58dc9068da
commit
dd94bb2396
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)} />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!,
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
7
migrations/075-tournament-result-team-id.js
Normal file
7
migrations/075-tournament-result-team-id.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export function up(db) {
|
||||
db.transaction(() => {
|
||||
db.prepare(
|
||||
/* sql */ `alter table "TournamentMatchGameResultParticipant" add "tournamentTeamId" integer`,
|
||||
).run();
|
||||
})();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user