150 lines
3.8 KiB
TypeScript
150 lines
3.8 KiB
TypeScript
import { brevoService } from "@/common/email/brevoApi";
|
|
import ApiError from "@/common/utils/helper/ApiError";
|
|
import config from '../../../config/config';
|
|
|
|
export async function sendEmailToAM(
|
|
emailAddress: string,
|
|
amName: string,
|
|
hostCompanyName: string,
|
|
activityName: string
|
|
): Promise<{
|
|
sent: boolean;
|
|
// messageId: string
|
|
}> {
|
|
|
|
const subject = `${hostCompanyName} Has Resubmitted Their Application`;
|
|
|
|
const htmlContent = `
|
|
<p>Hello ${amName},</p>
|
|
|
|
<p>
|
|
${hostCompanyName} has updated and re-submitted their pre-qualification details of ${activityName} for your review.
|
|
</p>
|
|
|
|
<p>
|
|
Please click on the link below to log in to your dashboard to review the revised submission and proceed with the necessary action.
|
|
</p>
|
|
|
|
<p>
|
|
<strong>Review Application</strong><br/>
|
|
<a href="${config.AM_INTERFACE_LINK}" target="_blank">${config.AM_INTERFACE_LINK}</a>
|
|
</p>
|
|
|
|
<p>
|
|
Thank you,<br/>
|
|
Minglar Team
|
|
</p>
|
|
`;
|
|
|
|
try {
|
|
const result = await brevoService.sendEmail({
|
|
recipients: [{ email: emailAddress }],
|
|
subject,
|
|
htmlContent,
|
|
});
|
|
|
|
// console.log("📧 Email sent successfully:", result);
|
|
|
|
return {
|
|
sent: true,
|
|
// messageId: result.messageId
|
|
};
|
|
} catch (err) {
|
|
console.error("Brevo email send failed:", err);
|
|
throw new ApiError(500, "Failed to send OTP to host via email.");
|
|
}
|
|
}
|
|
|
|
export async function sendEmailToMinglarAdmin(
|
|
emailAddress: string,
|
|
minglarAdminName: string,
|
|
hostCompanyName: string,
|
|
hostRefNumber: string
|
|
): Promise<{
|
|
sent: boolean;
|
|
// messageId: string
|
|
}> {
|
|
|
|
const subject = "New Host Application Submitted for Review";
|
|
|
|
const htmlContent = `
|
|
<p>Hi ${minglarAdminName},</p>
|
|
<p>${hostCompanyName} has submitted their application and is awaiting your review.</p>
|
|
<p>Reference number: <strong>${hostRefNumber}</strong></p>
|
|
<p>Please log in to your dashboard to review the submission and take the necessary action.</p>
|
|
<p>Thank you,<br/>Minglar Team</p>
|
|
`;
|
|
|
|
try {
|
|
const result = await brevoService.sendEmail({
|
|
recipients: [{ email: emailAddress }],
|
|
subject,
|
|
htmlContent,
|
|
});
|
|
|
|
// console.log("📧 Email sent successfully:", result);
|
|
|
|
return {
|
|
sent: true,
|
|
// messageId: result.messageId
|
|
};
|
|
} catch (err) {
|
|
console.error("Brevo email send failed:", err);
|
|
throw new ApiError(500, "Failed to send OTP to host via email.");
|
|
}
|
|
}
|
|
|
|
export async function sendPQPEmailToAM(
|
|
emailAddress: string,
|
|
minglarAdminName: string,
|
|
hostCompanyName: string,
|
|
activityName: string
|
|
): Promise<{
|
|
sent: boolean;
|
|
// messageId: string
|
|
}> {
|
|
|
|
const subject = "New Host Application Submitted for Review";
|
|
|
|
const htmlContent = `
|
|
<p>Hi ${minglarAdminName},</p>
|
|
|
|
<p>
|
|
${hostCompanyName} has submitted the pre-qualification details for ${activityName} and is awaiting your review.
|
|
</p>
|
|
|
|
<p>
|
|
Please click the link below to log in to your dashboard, review the submission, and take the necessary action:
|
|
</p>
|
|
|
|
<p>
|
|
<strong>Review Application</strong><br/>
|
|
<a href="${config.HOST_LINK_PQ}" target="_blank">${config.HOST_LINK_PQ}</a>
|
|
</p>
|
|
|
|
<p>
|
|
Thank you,<br/>
|
|
Minglar Team
|
|
</p>
|
|
`;
|
|
|
|
try {
|
|
const result = await brevoService.sendEmail({
|
|
recipients: [{ email: emailAddress }],
|
|
subject,
|
|
htmlContent,
|
|
});
|
|
|
|
// console.log("📧 Email sent successfully:", result);
|
|
|
|
return {
|
|
sent: true,
|
|
// messageId: result.messageId
|
|
};
|
|
} catch (err) {
|
|
console.error("Brevo email send failed:", err);
|
|
throw new ApiError(500, "Failed to send OTP to host via email.");
|
|
}
|
|
}
|
|
|