From 11241c382d3198e6cb0191c1e925e933d21b2c76 Mon Sep 17 00:00:00 2001 From: Steven Zhou Date: Sun, 5 May 2024 17:39:11 -0700 Subject: [PATCH] updated volunteer route --- routes/data.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/routes/data.js b/routes/data.js index ad1ebc6..6479a99 100644 --- a/routes/data.js +++ b/routes/data.js @@ -30,6 +30,18 @@ dataRouter.get('/:id', async (req, res) => { } }); +dataRouter.get('/:id', async (req, res) => { + // Returns data from event_data table with a given event_id + try { + const { id } = req.params; + const events = await pool.query('SELECT * FROM event_data WHERE event_id =$1', [id]); + + res.status(200).json(events.rows); + } catch (err) { + res.status(500).json(err.message); + } +}); + dataRouter.post('/', async (req, res) => { // Add new event to event_data table, requires event info in body try { @@ -196,13 +208,14 @@ dataRouter.get('/event/:eventId', async (req, res) => { }); dataRouter.get('/volunteer/:volunteerId/event/:eventId', async (req, res) => { + // retrieves event data associated with the volunteerID and eventID try { - const { eventId } = req.params; + const { eventId, volunteerId } = req.params; const eventData = await pool.query( `SELECT * FROM event_data D - WHERE D.event_id = $1`, - [eventId], + WHERE D.event_id = $1 AND D.volunteer_id = $2`, + [eventId, volunteerId], ); res.status(200).json(eventData.rows); } catch (err) {