input validation

This commit is contained in:
Joonas 2023-02-11 22:14:59 +02:00
parent 2d2b227a2b
commit 508892ad3b
1 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,9 @@ import {
} from "remix-utils";
import { useState } from "react";
const sortingFields = ["rank", "score", "SSranks", "Sranks", "Aranks"];
const sortingMethods = ["desc", "asc"];
const countys = [
"Ahvenanmaa",
"Etelä-Karjala",
@ -114,11 +117,21 @@ export async function loader({ request }) {
const toSort = url.searchParams.get("toSort");
const type = url.searchParams.get("type");
if (toSort)
if (!sortingFields.includes(toSort)) throw new Error("Bad sorting field");
if (type)
if (!sortingMethods.includes(type)) throw new Error("Bad sorting method");
const countyData = await prisma.county.findMany({
include: {
players: {
orderBy: {
[toSort ? toSort : "rank"]: type ? type : "asc",
[toSort ? toSort : "rank"]: type
? type
: toSort === "rank"
? "desc"
: "asc",
},
},
},