feat: role-aware welcome email (USER vs Professional/AGENT variants)

This commit is contained in:
pradeepkumar
2026-05-05 22:52:03 +05:30
parent b082d5d3a2
commit 60c5ca23b2
4 changed files with 40 additions and 18 deletions

View File

@@ -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({

View File

@@ -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);

View File

@@ -101,10 +101,13 @@ export class EmailService {
// ==========================================
// WELCOME EMAIL
// ==========================================
async sendWelcomeEmail(email: string, name?: string): Promise<boolean> {
async sendWelcomeEmail(email: string, name?: string, role?: 'USER' | 'AGENT' | string): Promise<boolean> {
const frontendUrl = this.configService.get<string>('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,

View File

@@ -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
? `
<h1>Welcome to RE-Quest!</h1>
<p>Hi ${name || 'there'},</p>
<p>We're thrilled to have you join RE-Quest - your trusted real estate platform!</p>
<p>Here's what you can do:</p>
<p>Hi ${greetingName},</p>
<p>We're thrilled to have you join RE-Quest &mdash; your trusted real estate platform.</p>
<p>Your next steps:</p>
<ul>
<li>Browse thousands of property listings</li>
<li>Connect with top real estate agents</li>
<li>Save your favorite properties</li>
<li>Get personalized recommendations</li>
<li>Complete your profile</li>
<li>Upload your license, E&amp;O insurance, and certifications for verification</li>
<li>Activate your subscription</li>
<li>and let your leads chase you</li>
</ul>
<div class="button-container">
<a href="${frontendUrl || '#'}" class="button">Start Exploring</a>
<a href="${frontendUrl ? `${frontendUrl}/agent/edit` : '#'}" class="button">Complete Profile</a>
</div>
<p>If you have any questions, our support team is always here to help!</p>
`
: `
<h1>Welcome to RE-Quest!</h1>
<p>Hi ${greetingName},</p>
<p>We're thrilled to have you join RE-Quest &mdash; your trusted real estate platform.</p>
<p>From here you can explore and connect with top real estate professionals and begin your real estate journey!</p>
<div class="button-container">
<a href="${frontendUrl ? `${frontendUrl}/user/profiles` : '#'}" class="button">Start Exploring</a>
</div>
<p>If you have any questions, our support team is always here to help!</p>
`;