.server. models to keep them out of browser bundle

This commit is contained in:
Kalle (Sendou) 2022-01-21 09:29:52 +02:00
parent fcce761c12
commit 6162528eea
12 changed files with 22 additions and 19 deletions

View File

@ -8,10 +8,7 @@ import {
import { z } from "zod";
import Modal from "~/components/Modal";
import { TeamRosterInputs } from "~/components/tournament/TeamRosterInputs";
import {
FindMatchModalInfoByNumber,
findMatchModalInfoByNumber,
} from "~/db/tournament/queries/findMatchModalInfoByNumber";
import * as TournamentMatch from "~/models/TournamentMatch.server";
import { Unpacked } from "~/utils";
import styles from "~/styles/tournament-match.css";
import { FancyStageBanner } from "~/components/tournament/FancyStageBanner";
@ -20,21 +17,25 @@ export const links: LinksFunction = () => {
return [{ rel: "stylesheet", href: styles }];
};
const typedJson = (args: NonNullable<FindMatchModalInfoByNumber>) => json(args);
const typedJson = (args: NonNullable<TournamentMatch.FindInfoForModal>) =>
json(args);
export const loader: LoaderFunction = async ({ params }) => {
const { bid: bracketId, num: matchNumber } = z
.object({ bid: z.string(), num: z.preprocess(Number, z.number()) })
.parse(params);
const match = await findMatchModalInfoByNumber({ bracketId, matchNumber });
const match = await TournamentMatch.findInfoForModal({
bracketId,
matchNumber,
});
if (!match) throw new Response("No match found", { status: 404 });
return typedJson(match);
};
export default function MatchModal() {
const data = useLoaderData<NonNullable<FindMatchModalInfoByNumber>>();
const data = useLoaderData<NonNullable<TournamentMatch.FindInfoForModal>>();
const location = useLocation();
return (
@ -78,7 +79,9 @@ export default function MatchModal() {
}
function matchInfoToCheckedPlayers(
matchInfo: Unpacked<NonNullable<FindMatchModalInfoByNumber>["matchInfos"]>
matchInfo: Unpacked<
NonNullable<TournamentMatch.FindInfoForModal>["matchInfos"]
>
): [string[], string[]] {
return [
matchInfo.teamUpper.members

View File

@ -25,9 +25,9 @@ import {
roompassRegExpString,
} from "~/core/tournament/utils";
import { useBaseURL, useTimeoutState } from "~/hooks/common";
import * as TournamentTeam from "~/models/TournamentTeam";
import * as TournamentTeamMember from "~/models/TournamentTeamMember";
import type { FindManyByTrustReceiverId } from "~/models/TrustRelationship";
import * as TournamentTeam from "~/models/TournamentTeam.server";
import * as TournamentTeamMember from "~/models/TournamentTeamMember.server";
import type { FindManyByTrustReceiverId } from "~/models/TrustRelationship.server";
import {
editTeam,
ownTeamWithInviteCode,

View File

@ -38,7 +38,7 @@ import {
validate,
} from "~/utils";
import { useTimeoutState } from "~/hooks/common";
import * as Tournament from "~/models/Tournament";
import * as Tournament from "~/models/Tournament.server";
import {
isTournamentAdmin,
tournamentHasNotStarted,

View File

@ -9,8 +9,8 @@ import {
} from "~/core/tournament/bracket";
import { canReportMatchScore } from "~/core/tournament/permissions";
import { matchIsOver } from "~/core/tournament/utils";
import * as TournamentBracket from "~/models/TournamentBracket";
import * as TournamentMatch from "~/models/TournamentMatch";
import * as TournamentBracket from "~/models/TournamentBracket.server";
import * as TournamentMatch from "~/models/TournamentMatch.server";
import { Unpacked } from "~/utils";
import { db } from "~/utils/db.server";

View File

@ -5,10 +5,10 @@ import {
} from "~/constants";
import { MapListIds, tournamentRoundsForDB } from "~/core/tournament/bracket";
import { captainOfTeam, sortTeamsBySeed } from "~/core/tournament/utils";
import * as Tournament from "~/models/Tournament";
import * as TournamentTeam from "~/models/TournamentTeam";
import * as TournamentTeamMember from "~/models/TournamentTeamMember";
import * as TrustRelationship from "~/models/TrustRelationship";
import * as Tournament from "~/models/Tournament.server";
import * as TournamentTeam from "~/models/TournamentTeam.server";
import * as TournamentTeamMember from "~/models/TournamentTeamMember.server";
import * as TrustRelationship from "~/models/TrustRelationship.server";
import { Serialized, Unpacked } from "~/utils";
import { db } from "~/utils/db.server";
import { isTournamentAdmin } from "~/validators/tournament";

View File

@ -1,3 +1,3 @@
import * as TrustRelationship from "~/models/TrustRelationship";
import * as TrustRelationship from "~/models/TrustRelationship.server";
export const getTrustingUsers = TrustRelationship.findManyByTrustReceiverId;