Skip to content

Commit

Permalink
feat: implement dynamic email template based on user role
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyton505 committed Nov 25, 2024
1 parent 230f511 commit 1a2d6a2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ router.post("/send-email", async (req: any, res: any) => {
throw new Error("SendGrid API key or test email is missing");
}

const { email, name } = req.body;
const { email, name, role } = req.body;

sgMail.setApiKey(SENDGRID_API_KEY);

const templateId =
role.toLowerCase().trim() === "mentor"
? "d-1694192e437348e2a0517103acae3f00"
: "d-7e26b82cf8624bafa4077b6ed73b52bf";

await sgMail.send({
to: email,
from: SEND_GRID_TEST_EMAIL,
templateId: "d-7e26b82cf8624bafa4077b6ed73b52bf",
templateId: templateId,
dynamicTemplateData: {
name: name,
},
Expand Down

0 comments on commit 1a2d6a2

Please sign in to comment.