-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/17arindam/PlayCafe into goo…
…gle_translate
- Loading branch information
Showing
39 changed files
with
895 additions
and
384 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
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
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
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
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
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
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 |
---|---|---|
@@ -1,35 +1,44 @@ | ||
const NewsletterEmail = require('../models/newsletter.model'); // Import the Mongoose model | ||
const { sendSubscriptionConfirmation } = require('../config/nodemailer'); // Import the mailer function | ||
const NewsletterEmail = require("../models/newsletter.model"); // Import the Mongoose model | ||
const { sendSubscriptionConfirmation } = require("../config/nodemailer"); // Import the mailer function | ||
|
||
// Controller for handling newsletter subscriptions | ||
exports.subscribeToNewsletter = async (req, res) => { | ||
const { email } = req.body; | ||
const { email } = req.body; | ||
|
||
if (!email) { | ||
return res.status(400).json({ error: 'Email is required' }); | ||
} | ||
|
||
try { | ||
// Check if the email already exists in the database | ||
const existingEmail = await NewsletterEmail.findOne({ email }); | ||
if (existingEmail) { | ||
return res.status(400).json({ error: 'This email is already subscribed.' }); | ||
} | ||
if (!email) { | ||
return res.status(400).json({ error: "Email is required" }); | ||
} | ||
|
||
// Save the email to the database | ||
const newEmail = new NewsletterEmail({ email }); | ||
await newEmail.save(); | ||
try { | ||
// Check if the email already exists in the database | ||
const existingEmail = await NewsletterEmail.findOne({ email }); | ||
if (existingEmail) { | ||
return res | ||
.status(400) | ||
.json({ error: "This email is already subscribed." }); | ||
} | ||
|
||
try { | ||
await sendSubscriptionConfirmation(email); | ||
} catch (error) { | ||
console.error('Error sending confirmation email:', error); | ||
return res.status(500).json({ error: 'Subscription successful, but there was an error sending the confirmation email.' }); | ||
} | ||
// Save the email to the database | ||
const newEmail = new NewsletterEmail({ email }); | ||
await newEmail.save(); | ||
|
||
return res.status(201).json({ message: 'Subscription successful! A confirmation email has been sent.' }); | ||
try { | ||
await sendSubscriptionConfirmation(email); | ||
} catch (error) { | ||
console.error('Error subscribing to newsletter:', error); | ||
return res.status(500).json({ error: 'Error subscribing to the newsletter.' }); | ||
console.error("Error sending confirmation email:", error); | ||
return res.status(500).json({ | ||
error: | ||
"Subscription successful, but there was an error sending the confirmation email.", | ||
}); | ||
} | ||
|
||
return res.status(201).json({ | ||
message: "Subscription successful! A confirmation email has been sent.", | ||
}); | ||
} catch (error) { | ||
console.error("Error subscribing to newsletter:", error); | ||
return res | ||
.status(500) | ||
.json({ error: "Error subscribing to the newsletter." }); | ||
} | ||
}; |
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
Oops, something went wrong.