From 3b3bfe210b0b8efd976827772df064836e980ec4 Mon Sep 17 00:00:00 2001
From: Frank <frank38112@gmail.com>
Date: Sat, 26 Oct 2024 16:50:59 -0400
Subject: [PATCH] Update server.js

---
 backend/server.js | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/backend/server.js b/backend/server.js
index 74d2c8b..26f6690 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -71,19 +71,20 @@ const Contact = mongoose.model("contact", ContactSchema)
 // Contact
 
 // TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database
-app.post('/contact', async (req, res) => {
+app.post('/api/contact', async (req, res) => {
+    const{ name, email, subject, message } = req.body
     try {
-        const newContact = new Contact ({
-            name,
-            email,
-            subject,
-            message
+        await Contact.create({
+            name: name,
+            email: email,
+            subject: subject,
+            message: message
         })
-        await newContact.save()
+        res.status(201).json({message: 'Inquiry submitted successfully'})
     }
     catch (err) {
-        console.error('Error saving contact data:', err);
-        process.exit(1);
+        console.error('Error submitting inquiry:', err);
+        res.status(500).json({message: 'Error submitting inquiry'})
     }
 })