Skip to content

Commit

Permalink
modified day post to check if date already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
michellelin1 committed Mar 29, 2024
1 parent 037f981 commit 793ed3a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions routes/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 793ed3a

Please sign in to comment.