Add HOST_LINK environment variable and update related configurations. Normalize email addresses to lowercase in login and registration handlers. Enhance email notifications for approved and rejected applications with HOST_LINK.
This commit is contained in:
@@ -15,20 +15,22 @@ export const handler = safeHandler(async (
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Parse request body
|
||||
let body: { emailAddress?: string; userPassword?: string };
|
||||
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch (error) {
|
||||
throw new ApiError(400, 'Invalid JSON in request body');
|
||||
}
|
||||
|
||||
const { emailAddress ,userPassword} = body;
|
||||
const { emailAddress, userPassword } = body;
|
||||
|
||||
if (!emailAddress) {
|
||||
throw new ApiError(400, 'Email is required');
|
||||
}
|
||||
|
||||
const loginForMinglar = await minglarSerivce.loginForMinglar(emailAddress ,userPassword);
|
||||
const emailToLowerCase = emailAddress.toLowerCase()
|
||||
|
||||
const loginForMinglar = await minglarSerivce.loginForMinglar(emailToLowerCase, userPassword);
|
||||
|
||||
if (!loginForMinglar) {
|
||||
throw new ApiError(400, 'Failed to login');
|
||||
|
||||
@@ -5,6 +5,7 @@ import { safeHandler } from '../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import { generateOtpHelper } from '../../../common/utils/helper/sendOtp';
|
||||
import { MinglarService } from './../services/minglar.service';
|
||||
import { sendOtpEmailForMinglarAdmin } from '../services/sendOTPEmail.service';
|
||||
|
||||
const minglarService = new MinglarService(prismaClient);
|
||||
|
||||
@@ -26,11 +27,15 @@ export const handler = safeHandler(async (
|
||||
if (!email) {
|
||||
throw new ApiError(400, 'Email is required');
|
||||
}
|
||||
console.log(email, " -: Email")
|
||||
|
||||
const emailToLowerCase = email.toLowerCase()
|
||||
|
||||
const user = await prismaClient.user.findUnique({
|
||||
where: { emailAddress: email, isActive: true, userStatus: USER_STATUS.INVITED },
|
||||
where: { emailAddress: emailToLowerCase, isActive: true, userStatus: USER_STATUS.INVITED },
|
||||
select: { emailAddress: true, id: true, userPassword: true, roleXid: true },
|
||||
});
|
||||
console.log(user, "sljdfjdf")
|
||||
|
||||
if (!user) {
|
||||
throw new ApiError(403, 'You are not allowed to register directly. Please contact minglar admin.');
|
||||
@@ -66,7 +71,7 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(500, 'Failed to send OTP');
|
||||
}
|
||||
|
||||
// await sendOtpEmailForMinglarAdmin(newUser?.emailAddress, otpResult.otp);
|
||||
await sendOtpEmailForMinglarAdmin(newUser?.emailAddress, otpResult.otp);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
||||
@@ -61,6 +61,8 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(400, 'Role is required');
|
||||
}
|
||||
|
||||
const emailToLowerCase = emailAddress.toLowerCase()
|
||||
|
||||
// Validate role is either Co_Admin or Account_Manager
|
||||
if (![ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER].includes(roleXid)) {
|
||||
throw new ApiError(400, 'Invalid role. Only Co_Admin and Account_Manager roles can be assigned.');
|
||||
@@ -79,7 +81,7 @@ export const handler = safeHandler(async (
|
||||
|
||||
// Use single service method that encapsulates the transaction
|
||||
await minglarService.inviteTeammate(
|
||||
emailAddress,
|
||||
emailToLowerCase,
|
||||
roleXid,
|
||||
isFixedSalary,
|
||||
perValue || 0,
|
||||
@@ -87,7 +89,7 @@ export const handler = safeHandler(async (
|
||||
);
|
||||
|
||||
// send email after transaction commits
|
||||
await sendInvitationEmailForMinglarAdmin(emailAddress, config.AM_INVITATION_LINK);
|
||||
await sendInvitationEmailForMinglarAdmin(emailToLowerCase, config.AM_INVITATION_LINK);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { brevoService } from "@/common/email/brevoApi";
|
||||
import ApiError from "@/common/utils/helper/ApiError";
|
||||
import { brevoService } from "../../../common/email/brevoApi";
|
||||
import ApiError from "../../../common/utils/helper/ApiError";
|
||||
import config from "../../../config/config";
|
||||
|
||||
export async function sendEmailToHostForApprovedApplication(
|
||||
emailAddress: string,
|
||||
@@ -14,6 +15,8 @@ export async function sendEmailToHostForApprovedApplication(
|
||||
<p>Dear Host,</p>
|
||||
<p>Congratulations, Your application to minglar admin has been approved.</p>
|
||||
<p>You can start onboarding your activities through the host panel.</p>
|
||||
<p> You can login to your account using the link below:<br/>
|
||||
<strong>Link:</strong> ${config.HOST_LINK} </p>
|
||||
<p>Best regards,<br/>Minglar Team</p>
|
||||
`;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { brevoService } from "@/common/email/brevoApi";
|
||||
import ApiError from "@/common/utils/helper/ApiError";
|
||||
import { brevoService } from "../../../common/email/brevoApi";
|
||||
import ApiError from "../../../common/utils/helper/ApiError";
|
||||
import config from "../../../config/config";
|
||||
|
||||
export async function sendEmailToHostForRejectedApplication(
|
||||
emailAddress: string,
|
||||
@@ -47,10 +48,13 @@ export async function sendAMRejectionMailtoHost(
|
||||
|
||||
const htmlContent = `
|
||||
<p>Dear Host,</p>
|
||||
<p>Your account manager has made some suggestions on your application.<br/>
|
||||
Please improve it and re-submit the application to onboard on minglar.</p>
|
||||
<p>If you have any questions please contact to minglar admin.</p>
|
||||
<p>Best regards,<br/>Minglar Team</p>
|
||||
<p> Your account manager has reviewed your application and provided some suggestions. <br/>
|
||||
Please make the necessary improvements and re-submit your application to proceed with the onboarding process on Minglar.</p>
|
||||
<p> You may access your application using the link below:<br/>
|
||||
<strong>Link:</strong> ${config.HOST_LINK} </p>
|
||||
<p> If you have any questions, please feel free to contact the Minglar Support Team. </p>
|
||||
<p> Best regards,<br/>
|
||||
<strong>Minglar Team</strong> </p>
|
||||
`;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user