Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved comments on /App/FeatureSet/Notification/API/SMTPConfig.ts #1735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions App/FeatureSet/Notification/API/SMTPConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import ProjectSmtpConfig from "Common/Models/DatabaseModels/ProjectSmtpConfig";

const router: ExpressRouter = Express.getRouter();

// POST endpoint to test email sending functionality
router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
// Parse request body as a JSON object
const body: JSONObject = req.body;

// Extract and parse smtpConfigId from request
const smtpConfigId: ObjectID = new ObjectID(body["smtpConfigId"] as string);

// Retrieve SMTP configuration from database using the ID
const config: ProjectSmtpConfig | null =
await ProjectSMTPConfigService.findOneById({
id: smtpConfigId,
Expand All @@ -42,6 +46,7 @@ router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
},
});

// Check if config is found, else return an error response
if (!config) {
return Response.sendErrorResponse(
req,
Expand All @@ -52,6 +57,7 @@ router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
);
}

// Extract and validate 'toEmail' from request body
const toEmail: Email = new Email(body["toEmail"] as string);

if (!toEmail) {
Expand All @@ -62,6 +68,7 @@ router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
);
}

// Construct the email message to be sent
const mail: EmailMessage = {
templateType: EmailTemplateType.SMTPTest,
toEmail: new Email(body["toEmail"] as string),
Expand All @@ -70,6 +77,7 @@ router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
body: "",
};

// Construct the email server configuration
const mailServer: EmailServer = {
id: config.id!,
host: config.hostname!,
Expand All @@ -82,6 +90,7 @@ router.post("/test", async (req: ExpressRequest, res: ExpressResponse) => {
};

try {
// Attempt to send the email
await MailService.send(mail, {
emailServer: mailServer,
projectId: config.projectId!,
Expand Down
Loading