From b9b0c079d8052c2a00a6eba18607a522ac097f35 Mon Sep 17 00:00:00 2001 From: Fayorg Date: Wed, 6 Dec 2023 00:09:24 +0100 Subject: [PATCH] fix: get test works without a provided date --- app/api/test/route.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/api/test/route.ts b/app/api/test/route.ts index 0d7b03d..2a8d7fe 100644 --- a/app/api/test/route.ts +++ b/app/api/test/route.ts @@ -4,6 +4,8 @@ import prisma from "@/lib/prisma"; export async function GET(req: NextRequest){ const date = req.nextUrl.searchParams.get("date"); const key = req.nextUrl.searchParams.get("key"); + + const usableDate = new Date(date || new Date()); const test = await prisma.test.findFirst({ select: { @@ -31,7 +33,7 @@ export async function GET(req: NextRequest){ } }, where: { - testOn: (date ? new Date(date) : new Date()) + testOn: new Date(usableDate.getFullYear() + "-" + (usableDate.getMonth() + 1) + "-" + (usableDate.getDate().toString().length === 1 ? "0" + usableDate.getDate() : usableDate.getDate())) } });