Fix group being able to be in two matches

This commit is contained in:
Kalle
2023-08-15 18:34:38 +03:00
parent 75998bbc6e
commit d473cdd6a8
2 changed files with 21 additions and 2 deletions

View File

@@ -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 }));
}

View File

@@ -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,