From ea461b605650f630959a6645e30338ca4c7678ca Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Sat, 4 Apr 2026 19:12:28 +0530 Subject: [PATCH] sending welcome email to host and changed the email template for sending otp --- .../Host_Admin/onboarding/createPassword.ts | 4 +- src/modules/host/services/host.service.ts | 6 +- .../host/services/sendOTPEmail.service.ts | 63 ++++++++++++++++--- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/modules/host/handlers/Host_Admin/onboarding/createPassword.ts b/src/modules/host/handlers/Host_Admin/onboarding/createPassword.ts index cdf3f79..59810f4 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/createPassword.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/createPassword.ts @@ -4,6 +4,7 @@ import { prismaClient } from '../../../../../common/database/prisma.lambda.servi import { HostService } from '../../../services/host.service'; import ApiError from '../../../../../common/utils/helper/ApiError'; import { verifyHostToken } from '../../../../../common/middlewares/jwt/authForHost'; +import { sendWelcomeEmailToHost } from '../../../services/sendOTPEmail.service'; const hostService = new HostService(prismaClient); @@ -46,7 +47,8 @@ export const handler = safeHandler(async ( throw new ApiError(400, 'Password must be at least 8 characters long'); } - await hostService.createPassword(user_xid, password); + const result = await hostService.createPassword(user_xid, password); + await sendWelcomeEmailToHost(result.emailAddress); return { statusCode: 200, diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index ec8c4bb..d8f9096 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -879,10 +879,10 @@ export class HostService { return newUser; } - async createPassword(user_xid: number, password: string): Promise { + async createPassword(user_xid: number, password: string): Promise> { // Find user by id const user = await this.prisma.user.findUnique({ - where: { id: user_xid }, + where: { id: user_xid, isActive: true }, select: { id: true, emailAddress: true, userPassword: true }, }); @@ -912,7 +912,7 @@ export class HostService { }, }); - return true; + return user; } async getBankBranchById(bankBranchXid: number) { diff --git a/src/modules/host/services/sendOTPEmail.service.ts b/src/modules/host/services/sendOTPEmail.service.ts index e1d9b1f..0debf80 100644 --- a/src/modules/host/services/sendOTPEmail.service.ts +++ b/src/modules/host/services/sendOTPEmail.service.ts @@ -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 sendOtpEmailForHost( emailAddress: string, @@ -9,14 +10,60 @@ export async function sendOtpEmailForHost( // messageId: string }> { - const subject = "OTP for Host Registration"; + const subject = "Your Minglar Verification Code"; const htmlContent = ` -

Dear Host,

-

You’re almost all set! 🎉

-

Enter ${otp} to wrap your registration.

-

This code will be valid for the next 5 minutes.

-

Warm regards,
Minglar Team

+

Hi there 👋

+

Here’s your verification code to get started:

+

${otp}

+

This code is valid for the next 5 minutes.

+

Once verified, you can continue setting up your Minglar account. If you didn’t request this, you can safely ignore this email.

+

Need help? Reach out to us at info@minglargroup.com.

+

Warm regards,
Team Minglar

+ `; + + 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 sendWelcomeEmailToHost( + emailAddress: string, +): Promise<{ + sent: boolean; + // messageId: string +}> { + + const subject = "Get Started as a Minglar Host"; + + const htmlContent = ` +

Hi ${emailAddress}



+

We’re excited to have you join Minglar as a host. Welcome aboard! 🌟



+

To get started and bring your activities live, here’s what comes next:



+

Your next steps:


+

1. Complete your host profile


+

2. Complete the pre-qualification process for all your activities


+

3. Submit your activity details for review


+

4. Go live and start receiving bookings



+

👉 Access your Host Portal:


+

${config.HOST_LINK}




+

If you need any support along the way, our team is always here to help. You can reach us anytime at info@minglargroup.com.



+

We’re looking forward to seeing your experiences come to life on Minglar.



+

Warm regards,
Team Minglar

`; try {