Skip to content

Commit

Permalink
Sending email functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
YashRavipati1 committed May 23, 2024
1 parent 7de4a9a commit 4dd63e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Binary file modified backend/bun.lockb
Binary file not shown.
23 changes: 23 additions & 0 deletions backend/src/controllers/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RequestHandler } from "express";

import { asyncHandler } from "./wrappers";

import { sendEmail } from "@/services/email";

type SendEmailRequestBody = {
recipient: string;
subject: string;
text: string;
};

export const sendEmailHandler: RequestHandler = asyncHandler(async (req, res, _) => {
const { recipient, subject, text } = req.body as SendEmailRequestBody;

const response = await sendEmail(recipient, subject, text);

if (response !== null) {
res.status(200).json(response);
} else {
res.status(400).send("Email Unsuccessful");
}
});
9 changes: 9 additions & 0 deletions backend/src/routes/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";

import * as EmailController from "@/controllers/email";

const router = express.Router();

router.post("/", EmailController.sendEmailHandler);

export default router;

0 comments on commit 4dd63e7

Please sign in to comment.