From 60c5ca23b2dbc2dd23c2f04d68c1f6b29552cd4b Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 5 May 2026 22:52:03 +0530 Subject: [PATCH] feat: role-aware welcome email (USER vs Professional/AGENT variants) --- src/auth/auth.service.ts | 3 +- src/email/email.listener.ts | 6 ++-- src/email/email.service.ts | 9 ++++-- src/email/templates/welcome.template.ts | 40 ++++++++++++++++++------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 9ff91e4..1e86982 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -708,10 +708,11 @@ export class AuthService { const profile = user.role === UserRole.AGENT ? user.agentProfile : user.userProfile; - // Emit event for welcome email + // Emit event for welcome email (role-aware template selection) this.eventEmitter.emit('user.email-verified', { email: user.email, name: profile?.firstName, + role: user.role, }); this.audit.log({ diff --git a/src/email/email.listener.ts b/src/email/email.listener.ts index 2eb9545..2509ad9 100644 --- a/src/email/email.listener.ts +++ b/src/email/email.listener.ts @@ -88,12 +88,12 @@ export class EmailListener { } @OnEvent('user.email-verified') - async handleEmailVerified(payload: { email: string; name?: string }) { + async handleEmailVerified(payload: { email: string; name?: string; role?: string }) { this.logger.log(`Email verified for: ${payload.email}`); try { - // Send welcome email after verification - await this.emailService.sendWelcomeEmail(payload.email, payload.name); + // Send welcome email after verification (role-aware: USER vs AGENT) + await this.emailService.sendWelcomeEmail(payload.email, payload.name, payload.role); this.logger.log(`Welcome email sent to: ${payload.email}`); } catch (error) { this.logger.error(`Failed to send welcome email to ${payload.email}:`, error); diff --git a/src/email/email.service.ts b/src/email/email.service.ts index 9f16ea2..f1e63fd 100644 --- a/src/email/email.service.ts +++ b/src/email/email.service.ts @@ -101,10 +101,13 @@ export class EmailService { // ========================================== // WELCOME EMAIL // ========================================== - async sendWelcomeEmail(email: string, name?: string): Promise { + async sendWelcomeEmail(email: string, name?: string, role?: 'USER' | 'AGENT' | string): Promise { const frontendUrl = this.configService.get('FRONTEND_URL') || 'http://localhost:3000'; - const html = getWelcomeEmailTemplate({ name, frontendUrl }); - const text = `Welcome to RE-Quest, ${name || 'User'}! Your real estate journey starts now.`; + const html = getWelcomeEmailTemplate({ name, frontendUrl, role }); + const isAgent = role === 'AGENT'; + const text = isAgent + ? `Welcome to RE-Quest, ${name || 'there'}! Complete your profile and upload your license, E&O insurance, and certifications to start receiving leads.` + : `Welcome to RE-Quest, ${name || 'there'}! Explore and connect with top real estate professionals.`; return this.sendEmail({ to: email, diff --git a/src/email/templates/welcome.template.ts b/src/email/templates/welcome.template.ts index d8f5168..19cc495 100644 --- a/src/email/templates/welcome.template.ts +++ b/src/email/templates/welcome.template.ts @@ -2,30 +2,48 @@ import { getBaseTemplate } from './base.template'; /** * Welcome email template - * Sent after email verification is complete + * Sent after email verification is complete. + * + * Two variants: + * - USER → simple welcome + "Start Exploring" CTA + * - AGENT → "Professional" onboarding checklist + "Complete Profile" CTA */ export interface WelcomeTemplateData { name?: string; frontendUrl?: string; + role?: 'USER' | 'AGENT' | string; } export function getWelcomeEmailTemplate(data: WelcomeTemplateData): string { - const { name, frontendUrl } = data; + const { name, frontendUrl, role } = data; const logoUrl = frontendUrl ? `${frontendUrl}/assets/images/splash-logo.png` : undefined; + const greetingName = name || 'there'; + const isAgent = role === 'AGENT'; - const content = ` + const content = isAgent + ? `

Welcome to RE-Quest!

-

Hi ${name || 'there'},

-

We're thrilled to have you join RE-Quest - your trusted real estate platform!

-

Here's what you can do:

+

Hi ${greetingName},

+

We're thrilled to have you join RE-Quest — your trusted real estate platform.

+

Your next steps:

    -
  • Browse thousands of property listings
  • -
  • Connect with top real estate agents
  • -
  • Save your favorite properties
  • -
  • Get personalized recommendations
  • +
  • Complete your profile
  • +
  • Upload your license, E&O insurance, and certifications for verification
  • +
  • Activate your subscription
  • +
  • and let your leads chase you
+

If you have any questions, our support team is always here to help!

+ ` + : ` +

Welcome to RE-Quest!

+

Hi ${greetingName},

+

We're thrilled to have you join RE-Quest — your trusted real estate platform.

+

From here you can explore and connect with top real estate professionals and begin your real estate journey!

+

If you have any questions, our support team is always here to help!

`;