input validation
This commit is contained in:
parent
2d2b227a2b
commit
508892ad3b
|
@ -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",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue