-
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.
- Loading branch information
1 parent
31bc746
commit 6c75ea0
Showing
8 changed files
with
174 additions
and
16 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// src/controllers/directoryController.ts | ||
import { Request, Response } from "express"; | ||
|
||
import { sendApprovalEmail, sendDenialEmail } from "../services/emailService"; | ||
|
||
type ApproveDirectoryRequestBody = { | ||
email: string; | ||
name: string; | ||
}; | ||
|
||
type DenyDirectoryRequestBody = { | ||
email: string; | ||
name: string; | ||
reason: string; | ||
}; | ||
|
||
export const approveDirectoryEntry = async ( | ||
req: Request<unknown, unknown, ApproveDirectoryRequestBody>, | ||
res: Response, | ||
) => { | ||
try { | ||
const { email, name } = req.body; | ||
|
||
if (!email || !name) { | ||
res.status(400).json({ error: "Email and name are required" }); | ||
return; | ||
} | ||
|
||
// Send the approval email | ||
await sendApprovalEmail(email, name); | ||
|
||
res.status(200).json({ message: "Directory entry approved and email sent" }); | ||
} catch (error) { | ||
console.error("Error approving directory entry:", error); | ||
res.status(500).json({ error: "Internal server error" }); | ||
} | ||
}; | ||
|
||
export const denyDirectoryEntry = async ( | ||
req: Request<unknown, unknown, DenyDirectoryRequestBody>, | ||
res: Response, | ||
) => { | ||
try { | ||
const { email, name, reason } = req.body; | ||
|
||
if (!email || !name || !reason) { | ||
res.status(400).json({ error: "Email, name, and reason are required" }); | ||
return; | ||
} | ||
|
||
// Send the denial email | ||
await sendDenialEmail(email, name, reason); | ||
|
||
res.status(200).json({ message: "Directory entry denied and email sent" }); | ||
} catch (error) { | ||
console.error("Error denying directory entry:", error); | ||
res.status(500).json({ error: "Internal server error" }); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// src/routes/directoryRoutes.ts | ||
import express from "express"; | ||
|
||
import * as DirectoryController from "../controllers/directory"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/approve", DirectoryController.approveDirectoryEntry); | ||
router.post("/deny", DirectoryController.denyDirectoryEntry); | ||
|
||
export default router; |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// src/services/sendEmail.ts | ||
import { config } from "dotenv"; | ||
import nodemailer from "nodemailer"; | ||
config(); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", // You can change this if you're using another provider | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_APP_PASSWORD, | ||
}, | ||
}); | ||
|
||
const sendApprovalEmail = async (to: string, name: string) => { | ||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: process.env.EMAIL_NOTIFICATIONS_RECIPIENT, | ||
subject: "Your Directory Approval", | ||
html: `<p>Dear ${name},</p><p>Your directory entry has been approved!</p><p>Thank you for your submission.</p>`, | ||
}; | ||
|
||
try { | ||
await transporter.sendMail(mailOptions); | ||
} catch (error) { | ||
console.error("Error sending approval email:", error); | ||
throw new Error("Failed to send approval email"); | ||
} | ||
}; | ||
|
||
const sendDenialEmail = async (to: string, name: string, reason: string) => { | ||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: process.env.EMAIL_NOTIFICATIONS_RECIPIENT, | ||
subject: "Your Directory Denial", | ||
html: `<p>Dear ${name},</p><p>Your directory entry has been denied for the following reason: ${reason}</p><p>If you have any questions, feel free to reach out.</p>`, | ||
}; | ||
|
||
try { | ||
await transporter.sendMail(mailOptions); | ||
} catch (error) { | ||
console.error("Error sending denial email:", error); | ||
throw new Error("Failed to send denial email"); | ||
} | ||
}; | ||
|
||
export { sendApprovalEmail, sendDenialEmail }; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
purge: [], | ||
darkMode: false, // or 'media' or 'class' | ||
theme: { | ||
extend: {}, | ||
}, | ||
variants: { | ||
extend: {}, | ||
}, | ||
plugins: [], | ||
} |