fixed duplicate check
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m22s

This commit is contained in:
christian 2024-06-02 16:05:45 +02:00
parent aa209bc0a8
commit f52d6d6004

View File

@ -6,16 +6,19 @@ import { countries } from "../db/schema";
import { ZodError, z } from "zod";
import { eq } from "drizzle-orm";
const schema = z.object({
name: z.string().min(1, { message: "Name is required" }),
});
export async function addCountry(prevstate: any, formData: FormData) {
const name = formData.get("name") as string;
const exists = await db
.select({ name: countries.name })
.from(countries)
.where(eq(countries.name, name));
const schema = z.object({
name: z
.string()
.min(1, { message: "Name is required" })
.refine(() => !exists[0], { message: "Country already exists" }),
});
try {
schema.parse({
name,