fix: get test works without a provided date

This commit is contained in:
Elie Baier 2023-12-06 00:09:24 +01:00
parent fe914efa41
commit b9b0c079d8
1 changed files with 3 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import prisma from "@/lib/prisma";
export async function GET(req: NextRequest){ export async function GET(req: NextRequest){
const date = req.nextUrl.searchParams.get("date"); const date = req.nextUrl.searchParams.get("date");
const key = req.nextUrl.searchParams.get("key"); const key = req.nextUrl.searchParams.get("key");
const usableDate = new Date(date || new Date());
const test = await prisma.test.findFirst({ const test = await prisma.test.findFirst({
select: { select: {
@ -31,7 +33,7 @@ export async function GET(req: NextRequest){
} }
}, },
where: { 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()))
} }
}); });