mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -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;
|
||||
/** Related "parent tournament", the tournament that contains the original sign-ups (for leagues) */
|
||||
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 {
|
||||
|
|
@ -850,6 +852,8 @@ export interface User {
|
|||
noScreen: Generated<DBBoolean>;
|
||||
buildSorting: JSONColumnTypeNullable<BuildSort[]>;
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import {
|
|||
import { getServerTournamentManager } from "../core/brackets-manager/manager.server";
|
||||
import { roundMapsFromInput } from "../core/mapList.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 { bracketSchema } from "../tournament-bracket-schemas.server";
|
||||
import { fillWithNullTillPowerOfTwo } from "../tournament-bracket-utils";
|
||||
|
|
@ -260,16 +260,19 @@ export const action: ActionFunction = async ({ params, request }) => {
|
|||
seedingSkillCountsFor,
|
||||
});
|
||||
|
||||
logger.info(
|
||||
`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}`,
|
||||
);
|
||||
|
||||
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}`;
|
||||
if (!tournament.isTest) {
|
||||
logger.info(`Inserting tournament summary. ${tournamentSummaryString}`);
|
||||
addSummary({
|
||||
tournamentId,
|
||||
summary,
|
||||
season,
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
`Did not insert tournament summary. ${tournamentSummaryString}`,
|
||||
);
|
||||
finalizeTournament(tournamentId);
|
||||
}
|
||||
|
||||
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(
|
||||
({
|
||||
tournamentId,
|
||||
|
|
@ -195,5 +201,10 @@ export const addSummary = sql.transaction(
|
|||
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",
|
||||
"CalendarEventDate.eventId",
|
||||
)
|
||||
.select(({ eb, exists, selectFrom }) => [
|
||||
.select(({ eb }) => [
|
||||
"Tournament.id",
|
||||
"CalendarEvent.id as eventId",
|
||||
"CalendarEvent.discordUrl",
|
||||
|
|
@ -50,6 +50,7 @@ export async function findById(id: number) {
|
|||
"CalendarEvent.name",
|
||||
"CalendarEvent.description",
|
||||
"CalendarEventDate.startTime",
|
||||
"Tournament.isFinalized",
|
||||
jsonObjectFrom(
|
||||
eb
|
||||
.selectFrom("TournamentOrganization")
|
||||
|
|
@ -149,11 +150,6 @@ export async function findById(id: number) {
|
|||
"Tournament.id",
|
||||
),
|
||||
).as("bracketProgressionOverrides"),
|
||||
exists(
|
||||
selectFrom("TournamentResult")
|
||||
.where("TournamentResult.tournamentId", "=", id)
|
||||
.select("TournamentResult.tournamentId"),
|
||||
).as("isFinalized"),
|
||||
jsonArrayFrom(
|
||||
eb
|
||||
.selectFrom("TournamentTeam")
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import type {
|
|||
import type { ChatUser } from "~/features/chat/components/Chat";
|
||||
import { userRoles } from "~/modules/permissions/mapper.server";
|
||||
import { isSupporter } from "~/modules/permissions/utils";
|
||||
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import { databaseTimestampNow, dateToDatabaseTimestamp } from "~/utils/dates";
|
||||
import invariant from "~/utils/invariant";
|
||||
import type { CommonUser } from "~/utils/kysely.server";
|
||||
import { COMMON_USER_FIELDS, userChatNameColor } from "~/utils/kysely.server";
|
||||
|
|
@ -661,7 +661,9 @@ export function upsert(
|
|||
.onConflict((oc) => {
|
||||
const { discordId, ...rest } = args;
|
||||
|
||||
return oc.column("discordId").doUpdateSet(rest);
|
||||
return oc
|
||||
.column("discordId")
|
||||
.doUpdateSet({ ...rest, createdAt: databaseTimestampNow() });
|
||||
})
|
||||
.returning("id")
|
||||
.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