From aff1b5991c539c0ef6a010c54f3dc0dec679bbad Mon Sep 17 00:00:00 2001 From: minie4 Date: Tue, 3 May 2022 20:27:57 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Return=20all=20future=20substitutio?= =?UTF-8?q?ns=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/api/index.js b/server/api/index.js index 5c7a3bd..befba44 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -36,9 +36,8 @@ export async function getSubstitutions(req, res) { if (req.query.from && req.query.to) { from = new Date(req.query.from).setUTCHours(0, 0, 0, 0); to = new Date(req.query.to).setUTCHours(0, 0, 0, 0); - } else { - date = new Date(req.query.date || new Date()).setUTCHours(0, 0, 0, 0); - console.log(date); + } else if (req.query.date) { + date = new Date(req.query.date).setUTCHours(0, 0, 0, 0); } const prismaOptions = { @@ -57,8 +56,12 @@ export async function getSubstitutions(req, res) { gte: new Date(from), lte: new Date(to), }; - } else { + } else if (date) { prismaOptions.where.date = new Date(date); + } else { + prismaOptions.where.date = { + gte: new Date(new Date().setUTCHours(0, 0, 0, 0)), + }; } const rawSubstitutions = await prisma.substitution.findMany(prismaOptions);