-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from JumboCode/contact-connection
Contact connection
- Loading branch information
Showing
2 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,15 @@ const User = mongoose.model("users", UserSchema) | |
// Contact Schema | ||
|
||
// TODO (Frank & Madeline): Create a ContactSchema | ||
const ContactSchema = new Schema ({ | ||
name: { type: String, required: false }, | ||
email: { type: String, required: true}, | ||
subject: { type: String, required: true}, | ||
message: { type: String, required: true} | ||
}) | ||
|
||
const Contact = mongoose.model('Contact', ContactSchema); | ||
// export default Contact; | ||
|
||
// Class Schema | ||
|
||
|
@@ -140,7 +148,41 @@ app.post('/api/login', async (req, res) => { | |
// Contact | ||
|
||
// TODO (Frank & Madeline): Create an endpoint to receive and upload contact inquiries to the database | ||
|
||
// async function uploadContact () { | ||
// const article = new Contact({ | ||
// name: 'test user', | ||
// email: '[email protected]', | ||
// subject: 'Test Inquiry', | ||
// message: 'Test message' | ||
|
||
// }); | ||
|
||
// await article.save(); | ||
// const firstContact = await Contact.findOne({}); | ||
// console.log(firstContact); | ||
// } | ||
// uploadContact().catch(console.error); | ||
|
||
// const firstArticle = await Contact.findOne({}); | ||
// console.log(firstArticle); | ||
app.post('/api/contact', async (req, res) => { | ||
const{ name, email, subject, message } = req.body | ||
try { | ||
const newContact = new Contact({ | ||
name, | ||
email, | ||
subject, | ||
message | ||
}) | ||
await newContact.save() | ||
|
||
res.status(201).json({message: 'Inquiry submitted successfully'}) | ||
} | ||
catch (err) { | ||
console.error('Error submitting inquiry:', err); | ||
res.status(500).json({message: 'Error submitting inquiry'}) | ||
} | ||
}) | ||
|
||
// Classes | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters