mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
Fix finalizing test tournament + track user created at Closes #2352
This commit is contained in:
parent
b621e2ff96
commit
7ed228fe7e
|
|
@ -483,6 +483,8 @@ export interface Tournament {
|
||||||
rules: string | null;
|
rules: string | null;
|
||||||
/** Related "parent tournament", the tournament that contains the original sign-ups (for leagues) */
|
/** Related "parent tournament", the tournament that contains the original sign-ups (for leagues) */
|
||||||
parentTournamentId: number | null;
|
parentTournamentId: number | null;
|
||||||
|
/** Is the tournament finalized meaning all the matches are played and TO has locked it making it read-only */
|
||||||
|
isFinalized: Generated<DBBoolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreparedMaps {
|
export interface PreparedMaps {
|
||||||
|
|
@ -850,6 +852,8 @@ export interface User {
|
||||||
noScreen: Generated<DBBoolean>;
|
noScreen: Generated<DBBoolean>;
|
||||||
buildSorting: JSONColumnTypeNullable<BuildSort[]>;
|
buildSorting: JSONColumnTypeNullable<BuildSort[]>;
|
||||||
preferences: JSONColumnTypeNullable<UserPreferences>;
|
preferences: JSONColumnTypeNullable<UserPreferences>;
|
||||||
|
/** User creation date. Can be null because we did not always save this. */
|
||||||
|
createdAt: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Represents User joined with PlusTier table */
|
/** Represents User joined with PlusTier table */
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import {
|
||||||
import { getServerTournamentManager } from "../core/brackets-manager/manager.server";
|
import { getServerTournamentManager } from "../core/brackets-manager/manager.server";
|
||||||
import { roundMapsFromInput } from "../core/mapList.server";
|
import { roundMapsFromInput } from "../core/mapList.server";
|
||||||
import { tournamentSummary } from "../core/summarizer.server";
|
import { tournamentSummary } from "../core/summarizer.server";
|
||||||
import { addSummary } from "../queries/addSummary.server";
|
import { addSummary, finalizeTournament } from "../queries/addSummary.server";
|
||||||
import { allMatchResultsByTournamentId } from "../queries/allMatchResultsByTournamentId.server";
|
import { allMatchResultsByTournamentId } from "../queries/allMatchResultsByTournamentId.server";
|
||||||
import { bracketSchema } from "../tournament-bracket-schemas.server";
|
import { bracketSchema } from "../tournament-bracket-schemas.server";
|
||||||
import { fillWithNullTillPowerOfTwo } from "../tournament-bracket-utils";
|
import { fillWithNullTillPowerOfTwo } from "../tournament-bracket-utils";
|
||||||
|
|
@ -260,16 +260,19 @@ export const action: ActionFunction = async ({ params, request }) => {
|
||||||
seedingSkillCountsFor,
|
seedingSkillCountsFor,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(
|
const tournamentSummaryString = `Tournament id: ${tournamentId}, mapResultDeltas.lenght: ${summary.mapResultDeltas.length}, playerResultDeltas.length ${summary.playerResultDeltas.length}, tournamentResults.length ${summary.tournamentResults.length}, skills.length ${summary.skills.length}, seedingSkills.length ${summary.seedingSkills.length}`;
|
||||||
`Inserting tournament summary. Tournament id: ${tournamentId}, mapResultDeltas.lenght: ${summary.mapResultDeltas.length}, playerResultDeltas.length ${summary.playerResultDeltas.length}, tournamentResults.length ${summary.tournamentResults.length}, skills.length ${summary.skills.length}, seedingSkills.length ${summary.seedingSkills.length}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!tournament.isTest) {
|
if (!tournament.isTest) {
|
||||||
|
logger.info(`Inserting tournament summary. ${tournamentSummaryString}`);
|
||||||
addSummary({
|
addSummary({
|
||||||
tournamentId,
|
tournamentId,
|
||||||
summary,
|
summary,
|
||||||
season,
|
season,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
logger.info(
|
||||||
|
`Did not insert tournament summary. ${tournamentSummaryString}`,
|
||||||
|
);
|
||||||
|
finalizeTournament(tournamentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tournament.ranked) {
|
if (tournament.ranked) {
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,12 @@ const addTournamentResultStm = sql.prepare(/* sql */ `
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
const finalizeTournamentStm = sql.prepare(/* sql */ `
|
||||||
|
update "Tournament" set
|
||||||
|
"isFinalized" = 1
|
||||||
|
where "id" = @tournamentId
|
||||||
|
`);
|
||||||
|
|
||||||
export const addSummary = sql.transaction(
|
export const addSummary = sql.transaction(
|
||||||
({
|
({
|
||||||
tournamentId,
|
tournamentId,
|
||||||
|
|
@ -195,5 +201,10 @@ export const addSummary = sql.transaction(
|
||||||
tournamentTeamId: tournamentResult.tournamentTeamId,
|
tournamentTeamId: tournamentResult.tournamentTeamId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalizeTournamentStm.run({ tournamentId });
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const finalizeTournament = (tournamentId: number) =>
|
||||||
|
finalizeTournamentStm.run({ tournamentId });
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export async function findById(id: number) {
|
||||||
"CalendarEvent.id",
|
"CalendarEvent.id",
|
||||||
"CalendarEventDate.eventId",
|
"CalendarEventDate.eventId",
|
||||||
)
|
)
|
||||||
.select(({ eb, exists, selectFrom }) => [
|
.select(({ eb }) => [
|
||||||
"Tournament.id",
|
"Tournament.id",
|
||||||
"CalendarEvent.id as eventId",
|
"CalendarEvent.id as eventId",
|
||||||
"CalendarEvent.discordUrl",
|
"CalendarEvent.discordUrl",
|
||||||
|
|
@ -50,6 +50,7 @@ export async function findById(id: number) {
|
||||||
"CalendarEvent.name",
|
"CalendarEvent.name",
|
||||||
"CalendarEvent.description",
|
"CalendarEvent.description",
|
||||||
"CalendarEventDate.startTime",
|
"CalendarEventDate.startTime",
|
||||||
|
"Tournament.isFinalized",
|
||||||
jsonObjectFrom(
|
jsonObjectFrom(
|
||||||
eb
|
eb
|
||||||
.selectFrom("TournamentOrganization")
|
.selectFrom("TournamentOrganization")
|
||||||
|
|
@ -149,11 +150,6 @@ export async function findById(id: number) {
|
||||||
"Tournament.id",
|
"Tournament.id",
|
||||||
),
|
),
|
||||||
).as("bracketProgressionOverrides"),
|
).as("bracketProgressionOverrides"),
|
||||||
exists(
|
|
||||||
selectFrom("TournamentResult")
|
|
||||||
.where("TournamentResult.tournamentId", "=", id)
|
|
||||||
.select("TournamentResult.tournamentId"),
|
|
||||||
).as("isFinalized"),
|
|
||||||
jsonArrayFrom(
|
jsonArrayFrom(
|
||||||
eb
|
eb
|
||||||
.selectFrom("TournamentTeam")
|
.selectFrom("TournamentTeam")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import type {
|
||||||
import type { ChatUser } from "~/features/chat/components/Chat";
|
import type { ChatUser } from "~/features/chat/components/Chat";
|
||||||
import { userRoles } from "~/modules/permissions/mapper.server";
|
import { userRoles } from "~/modules/permissions/mapper.server";
|
||||||
import { isSupporter } from "~/modules/permissions/utils";
|
import { isSupporter } from "~/modules/permissions/utils";
|
||||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
import { databaseTimestampNow, dateToDatabaseTimestamp } from "~/utils/dates";
|
||||||
import invariant from "~/utils/invariant";
|
import invariant from "~/utils/invariant";
|
||||||
import type { CommonUser } from "~/utils/kysely.server";
|
import type { CommonUser } from "~/utils/kysely.server";
|
||||||
import { COMMON_USER_FIELDS, userChatNameColor } from "~/utils/kysely.server";
|
import { COMMON_USER_FIELDS, userChatNameColor } from "~/utils/kysely.server";
|
||||||
|
|
@ -661,7 +661,9 @@ export function upsert(
|
||||||
.onConflict((oc) => {
|
.onConflict((oc) => {
|
||||||
const { discordId, ...rest } = args;
|
const { discordId, ...rest } = args;
|
||||||
|
|
||||||
return oc.column("discordId").doUpdateSet(rest);
|
return oc
|
||||||
|
.column("discordId")
|
||||||
|
.doUpdateSet({ ...rest, createdAt: databaseTimestampNow() });
|
||||||
})
|
})
|
||||||
.returning("id")
|
.returning("id")
|
||||||
.executeTakeFirstOrThrow();
|
.executeTakeFirstOrThrow();
|
||||||
|
|
|
||||||
25
migrations/087-finalize-tournament-bool.js
Normal file
25
migrations/087-finalize-tournament-bool.js
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
export function up(db) {
|
||||||
|
db.transaction(() => {
|
||||||
|
db.prepare(/* sql */ `alter table "User" add "createdAt" integer`).run();
|
||||||
|
|
||||||
|
db.prepare(
|
||||||
|
/* sql */ `alter table "Tournament" add "isFinalized" integer not null default 0`,
|
||||||
|
).run();
|
||||||
|
|
||||||
|
const finalizedTournamentIds = db
|
||||||
|
.prepare(
|
||||||
|
/* sql */ `select "tournamentId" from "TournamentResult" group by "tournamentId"`,
|
||||||
|
)
|
||||||
|
.all();
|
||||||
|
|
||||||
|
const updateStatement = db.prepare(
|
||||||
|
/* sql */ `update "Tournament" set isFinalized = 1 where id = @tournamentId`,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const tournamentId of finalizedTournamentIds) {
|
||||||
|
updateStatement.run({
|
||||||
|
tournamentId: tournamentId.tournamentId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user