Skip to content

Commit

Permalink
Add email notification for bug reports
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnie4k committed May 27, 2024
1 parent 0a72eee commit cb40c82
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/src/bugReports/controllers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nodemailer from "nodemailer";
import { BugReport, BugReportModel } from "./models";

const getBugReports = () => BugReportModel.find();
Expand All @@ -11,6 +12,33 @@ const createBugReport = async (
await BugReportModel.create(
new BugReport(email, appName, desc, creationTime)
);
sendReportEmail(email, appName, desc, creationTime).catch((err) =>
console.error(err)
);
};

const sendReportEmail = (
userEmail: string,
appName: string,
desc: string,
creationTime: Date
) => {
const mailTransporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});

const emailDetails = {
from: process.env.EMAIL_USER,
to: process.env.EMAIL_USER,
subject: `[Cornell AppDev] ${appName} Bug Report`,
text: `Email: ${userEmail}\nReport Date: ${creationTime.toDateString()}\nApp: ${appName}\nDescription: ${desc}`,
};

return mailTransporter.sendMail(emailDetails);
};

export default {
Expand Down

0 comments on commit cb40c82

Please sign in to comment.