From 793ed3a434225409fa3fce7ea324c57e7b599d4d Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Fri, 29 Mar 2024 09:46:30 -0700 Subject: [PATCH] modified day post to check if date already exists --- routes/day.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/routes/day.js b/routes/day.js index 388f8c1..faf7762 100644 --- a/routes/day.js +++ b/routes/day.js @@ -40,6 +40,15 @@ dayRouter.get('/:id', async (req, res) => { dayRouter.post('/', async (req, res) => { try { const { eventDate, location, notes } = req.body; + const inUse = await db.query(`SELECT * FROM day WHERE event_date = $1;`, [eventDate]); + if (inUse.length) { + res.status(201).json({ + status: 'Failed', + message: 'Day already exists', + }); + return; + } + const newDay = await db.query( ` INSERT INTO day (