mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-14 15:16:09 -05:00
Fix group being able to be in two matches
This commit is contained in:
13
app/features/sendouq/queries/groupHasMatch.server.ts
Normal file
13
app/features/sendouq/queries/groupHasMatch.server.ts
Normal 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 }));
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user