From dce4dac84eb9f9760904bbfd22179a33dc59e6a2 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 28 Oct 2024 14:37:18 -0700 Subject: [PATCH] add groq query to fetch clubs (#197) --- .../src/app/(home)/sections/Clubs/getClubs.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 apps/site/src/app/(home)/sections/Clubs/getClubs.ts diff --git a/apps/site/src/app/(home)/sections/Clubs/getClubs.ts b/apps/site/src/app/(home)/sections/Clubs/getClubs.ts new file mode 100644 index 00000000..ced96af0 --- /dev/null +++ b/apps/site/src/app/(home)/sections/Clubs/getClubs.ts @@ -0,0 +1,20 @@ +import { z } from "zod"; +import { cache } from "react"; +import { client } from "@/lib/sanity/client"; +import { SanityDocument, SanityImageReference } from "@/lib/sanity/types"; + +const Clubs = SanityDocument.extend({ + clubs: z.array( + z.object({ + _type: z.literal("club"), + _key: z.string(), + name: z.string(), + url: z.string().url().optional(), + logo: SanityImageReference, + }), + ), +}); + +export const getClubs = cache(async () => { + return Clubs.parse(await client.fetch("*[_id == 'clubs'][0]")); +});