Skip to content

Commit

Permalink
Fix group being able to be in two matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Aug 15, 2023
1 parent 75998bb commit d473cdd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/features/sendouq/queries/groupHasMatch.server.ts
Original file line number Diff line number Diff line change
@@ -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 }));
}
10 changes: 8 additions & 2 deletions app/features/sendouq/routes/q.looking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d473cdd

Please sign in to comment.