Skip to content

Commit

Permalink
Merge pull request #516 from haseebzaki-07/new_branch_%
Browse files Browse the repository at this point in the history
Add complaints with email
  • Loading branch information
dhairyagothi authored Nov 7, 2024
2 parents ae47151 + 5c68414 commit a3e969d
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 138 deletions.
1 change: 1 addition & 0 deletions backend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
EMAIL_USER=your_gmail
#your email
EMAIL_USER=your_gmail
MONGODB_URI=

# To create a passkey on the phone or computer you’re on:

Expand Down
47 changes: 47 additions & 0 deletions backend/controllers/complaintController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import nodemailer from 'nodemailer'
import Complaint from '../models/Complaint.js';

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
});


const sendConfirmationEmail = (email, name) => {
const mailOptions = {
from: process.env.EMAIL_USER,
to: email,
subject: 'Complaint Received - Station Saarthi',
text: `Dear ${name},\n\nThank you for submitting your complaint. We have received your complaint and will look into the matter soon.\n\nBest regards,\nStation Saarthi`
};

return transporter.sendMail(mailOptions);
};

const submitComplaint = async (req, res) => {
const { name, phoneNumber, email, complain } = req.body;

if (!name || !phoneNumber || !email || !complain) {
return res.status(400).json({ message: 'All fields are required.' });
}

try {
// Create a new complaint record in the database
const newComplaint = new Complaint({ name, phoneNumber, email, complain });
await newComplaint.save();

// Send a confirmation email to the user
await sendConfirmationEmail(email, name);

res.status(200).json({ message: 'Complaint submitted successfully! We will get back to you soon.' });
} catch (error) {
console.error('Error submitting complaint:', error);
res.status(500).json({ message: 'There was an error submitting your complaint. Please try again later.' });
}
}

export default submitComplaint;
2 changes: 2 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import authRoutes from "./routes/authRoutes.js";
import stationRoutes from "./routes/stationRoutes.js";
import trainRoutes from "./routes/trainRoutes.js";
import contactUs from "./routes/contactUsRouter.js";
import complaintRoutes from "./routes/complaintRoutes.js";

app.use("/auth", authRoutes);
app.use("/api", authRoutes);
app.use("/api", complaintRoutes);
app.use("/station", stationRoutes);
app.use("/train", trainRoutes);
app.use("/contact", contactUs);
Expand Down
27 changes: 27 additions & 0 deletions backend/models/Complaint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import mongoose from "mongoose";

const complaintSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
phoneNumber: {
type: String,
required: true
},
email: {
type: String,
required: true
},
complain: {
type: String,
required: true
},
createdAt: {
type: Date,
default: Date.now
}
});

const Complaint = mongoose.model('Complaint', complaintSchema);
export default Complaint;
50 changes: 17 additions & 33 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"express": "^4.21.1",
"express-rate-limit": "^7.4.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.0",
"mongoose": "^8.8.0",
"node": "^22.8.0",
"nodemailer": "^6.9.15",
"nodemailer": "^6.9.16",
"nodemon": "^3.1.7",
"socket.io": "^4.8.0"
},
Expand Down
11 changes: 11 additions & 0 deletions backend/routes/complaintRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// routes/complaint.js
import express from 'express'
import submitComplaint from '../controllers/complaintController.js';


const router = express.Router();

// Handle complaint submission
router.post('/complaint', submitComplaint);

export default router
1 change: 0 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3e969d

Please sign in to comment.