mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-02 22:26:57 -05:00
Fix some internal server errors
This commit is contained in:
parent
7c8dc8b8ae
commit
882973bbfe
|
|
@ -1,18 +1,18 @@
|
|||
import type { LoaderFunctionArgs } from "@remix-run/node";
|
||||
import { redirect } from "@remix-run/node";
|
||||
import { z } from "zod";
|
||||
import * as CalendarRepository from "~/features/calendar/CalendarRepository.server";
|
||||
import { notFoundIfFalsy } from "~/utils/remix.server";
|
||||
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
||||
import { tournamentPage } from "~/utils/urls";
|
||||
import { actualNumber, id } from "~/utils/zod";
|
||||
import { idObject } from "~/utils/zod";
|
||||
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const parsedParams = z
|
||||
.object({ id: z.preprocess(actualNumber, id) })
|
||||
.parse(params);
|
||||
export const loader = async (args: LoaderFunctionArgs) => {
|
||||
const params = parseParams({
|
||||
params: args.params,
|
||||
schema: idObject,
|
||||
});
|
||||
const event = notFoundIfFalsy(
|
||||
await CalendarRepository.findById({
|
||||
id: parsedParams.id,
|
||||
id: params.id,
|
||||
includeBadgePrizes: true,
|
||||
includeMapPool: true,
|
||||
}),
|
||||
|
|
@ -24,6 +24,6 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|||
|
||||
return {
|
||||
event,
|
||||
results: await CalendarRepository.findResultsByEventId(parsedParams.id),
|
||||
results: await CalendarRepository.findResultsByEventId(params.id),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
import type { LoaderFunctionArgs } from "@remix-run/node";
|
||||
import { removeDuplicates } from "~/utils/arrays";
|
||||
import { notFoundIfFalsy } from "~/utils/remix.server";
|
||||
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
||||
import { idObject } from "~/utils/zod";
|
||||
import { findPlacementsByPlayerId } from "../queries/findPlacements.server";
|
||||
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const placements = notFoundIfFalsy(
|
||||
findPlacementsByPlayerId(Number(params.id)),
|
||||
);
|
||||
export const loader = async (args: LoaderFunctionArgs) => {
|
||||
const params = parseParams({
|
||||
params: args.params,
|
||||
schema: idObject,
|
||||
});
|
||||
|
||||
const placements = notFoundIfFalsy(findPlacementsByPlayerId(params.id));
|
||||
|
||||
const primaryName = placements[0].name;
|
||||
const aliases = removeDuplicates(
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ export function findPlacementsByPlayerId(
|
|||
playerId: Tables["XRankPlacement"]["playerId"],
|
||||
) {
|
||||
const results = byPlayerStm.all({ playerId }) as Array<FindPlacement>;
|
||||
if (!results) return null;
|
||||
if (results.length === 0) return null;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export const action: ActionFunction = async ({ params, request }) => {
|
|||
invariant(bracket, "Bracket not found");
|
||||
|
||||
const seeding = bracket.seeding;
|
||||
invariant(seeding, "Seeding not found");
|
||||
errorToastIfFalsy(seeding, "Bracket already started");
|
||||
|
||||
errorToastIfFalsy(
|
||||
bracket.canBeStarted,
|
||||
|
|
|
|||
|
|
@ -208,6 +208,11 @@ export const action: ActionFunction = async ({ request, params }) => {
|
|||
|
||||
const previousTeam = tournament.teamMemberOfByUser({ id: data.userId });
|
||||
|
||||
errorToastIfFalsy(
|
||||
!previousTeam?.id || previousTeam.id !== team.id,
|
||||
"User is already in this team",
|
||||
);
|
||||
|
||||
errorToastIfFalsy(
|
||||
tournament.hasStarted || !previousTeam,
|
||||
"User is already in a team",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import type { Unpacked } from "./types";
|
|||
import { assertType } from "./types";
|
||||
|
||||
export const id = z.coerce.number({ message: "Required" }).int().positive();
|
||||
export const idObject = z.object({
|
||||
id,
|
||||
});
|
||||
export const optionalId = z.coerce.number().int().positive().optional();
|
||||
|
||||
export const nonEmptyString = z.string().trim().min(1, {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user