From 24bb0f9fcfec3832a7aaf0131e2fb4509938714f Mon Sep 17 00:00:00 2001 From: Davin <71451687+bc-davin@users.noreply.github.com> Date: Sun, 20 Oct 2024 16:28:04 -0600 Subject: [PATCH] Update index.js --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 97d77d5..dc24686 100644 --- a/index.js +++ b/index.js @@ -98,7 +98,24 @@ app.post('/createevent', (req, res) => { res.status(500).json({ error: 'Failed to create event' }); } }); +app.post('/createevent', async (req, res) => { + const { title, date, description, image, link, location } = req.body; + const { lat, lng, amenity, city, country, state, postalCode } = location; + const query = ` + INSERT INTO events (title, date, description, image, link, lat, lng, amenity, city, country, state, postalCode) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + `; + const values = [title, date, description, image, link, lat, lng, amenity, city, country, state, postalCode]; + + try { + await pool.query(query, values); + res.status(200).json({ message: 'Event created successfully' }); + } catch (err) { + console.error('Error inserting event data:', err); + res.status(500).json({ error: 'Failed to create event' }); + } +}); // Start the server