From 1c0a499bf8fed29276a35f04e19b768294fcd5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A0=95=EC=9B=90?= Date: Thu, 25 Feb 2021 09:07:21 +0900 Subject: [PATCH] Fix calendar event schema --- backend/routes/calendar/event.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/backend/routes/calendar/event.js b/backend/routes/calendar/event.js index a03def5..136d56f 100644 --- a/backend/routes/calendar/event.js +++ b/backend/routes/calendar/event.js @@ -22,10 +22,10 @@ async function getEvents(req, res) { const lastDay = new Date(year, month); events = await prisma.event.findMany({ where: { - startDate: { + start: { lt: lastDay, }, - endDate: { + end: { gte: firstDay, }, }, @@ -35,10 +35,10 @@ async function getEvents(req, res) { const lastDay = new Date(year + 1, 0); events = await prisma.event.findMany({ where: { - startDate: { + start: { lt: lastDay, }, - endDate: { + end: { gte: firstDay, }, }, @@ -58,8 +58,8 @@ async function createNewEvent(req, res) { const eventCreated = await prisma.event.create({ data: { ...req.body, - startDate: new Date(req.body.startDate), - endDate: new Date(req.body.endDate), + start: new Date(req.body.start), + end: new Date(req.body.end), }, }); res.status(201).send(eventCreated); @@ -78,11 +78,7 @@ async function removeEventById(req, res) { }); res.status(200).send(eventRemoved); } catch (e) { - if (e.code === 'P2016') { - res.status(404).send(e); - } else { - res.status(400).send(e); - } + res.status(400).send(e); } } @@ -97,11 +93,7 @@ async function updateEventById(req, res) { }); res.status(200).send(eventUpdated); } catch (e) { - if (e.code === 'P2016') { - res.status(404).send(e); - } else { - res.status(400).send(e); - } + res.status(400).send(e); } }