From d473cdd6a8ce567437f8d161a6f2c6d54ecce5e5 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:34:38 +0300 Subject: [PATCH] Fix group being able to be in two matches --- .../sendouq/queries/groupHasMatch.server.ts | 13 +++++++++++++ app/features/sendouq/routes/q.looking.tsx | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/features/sendouq/queries/groupHasMatch.server.ts diff --git a/app/features/sendouq/queries/groupHasMatch.server.ts b/app/features/sendouq/queries/groupHasMatch.server.ts new file mode 100644 index 000000000..3eee73af1 --- /dev/null +++ b/app/features/sendouq/queries/groupHasMatch.server.ts @@ -0,0 +1,13 @@ +import { sql } from "~/db/sql"; + +const stm = sql.prepare(/* sql */ ` + select 1 + from "GroupMatch" + where + "alphaGroupId" = @groupId + or "bravoGroupId" = @groupId +`); + +export function groupHasMatch(groupId: number) { + return Boolean(stm.get({ groupId })); +} diff --git a/app/features/sendouq/routes/q.looking.tsx b/app/features/sendouq/routes/q.looking.tsx index 5f5e274c3..35771e6b4 100644 --- a/app/features/sendouq/routes/q.looking.tsx +++ b/app/features/sendouq/routes/q.looking.tsx @@ -5,7 +5,7 @@ import type { V2_MetaFunction, } from "@remix-run/node"; import { redirect } from "@remix-run/node"; -import { useFetcher, useLoaderData, useRevalidator } from "@remix-run/react"; +import { useFetcher, useLoaderData } from "@remix-run/react"; import clsx from "clsx"; import * as React from "react"; import { Flipper } from "react-flip-toolkit"; @@ -14,7 +14,6 @@ import { Main } from "~/components/Main"; import { SubmitButton } from "~/components/SubmitButton"; import { useIsMounted } from "~/hooks/useIsMounted"; import { useTranslation } from "~/hooks/useTranslation"; -import { useVisibilityChange } from "~/hooks/useVisibilityChange"; import { getUser, requireUserId } from "~/modules/auth/user.server"; import { MapPool } from "~/modules/map-pool-serializer"; import { @@ -68,6 +67,7 @@ import { userSkills } from "~/features/mmr/tiered.server"; import { useWindowSize } from "~/hooks/useWindowSize"; import { Tab, Tabs } from "~/components/Tabs"; import { useAutoRefresh } from "~/hooks/useAutoRefresh"; +import { groupHasMatch } from "../queries/groupHasMatch.server"; export const handle: SendouRouteHandle = { i18n: ["q"], @@ -214,6 +214,12 @@ export const action: ActionFunction = async ({ request }) => { "'theirGroup' is not full" ); + validate(!groupHasMatch(ourGroup.id), "Our group already has a match"); + validate( + !groupHasMatch(theirGroup.id), + "Their group already has a match" + ); + const createdMatch = createMatch({ alphaGroupId: ourGroup.id, bravoGroupId: theirGroup.id,