/** * Email Templates Service * * Renders email templates using MJML and Handlebars */ import { Injectable } from '@nestjs/common'; import mjml2html from 'mjml'; import Handlebars from 'handlebars'; @Injectable() export class EmailTemplates { /** * Render booking confirmation email */ async renderBookingConfirmation(data: { bookingNumber: string; bookingDetails: any; }): Promise { const mjmlTemplate = ` Booking Confirmation Your booking has been confirmed successfully! Booking Number: {{bookingNumber}} Thank you for using Xpeditis. Your booking confirmation is attached as a PDF. View in Dashboard © 2025 Xpeditis. All rights reserved. `; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } /** * Render verification email */ async renderVerificationEmail(data: { verifyUrl: string }): Promise { const mjmlTemplate = ` Verify Your Email Welcome to Xpeditis! Please verify your email address to get started. Verify Email Address If you didn't create an account, you can safely ignore this email. © 2025 Xpeditis. All rights reserved. `; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } /** * Render password reset email */ async renderPasswordResetEmail(data: { resetUrl: string }): Promise { const mjmlTemplate = ` Reset Your Password You requested to reset your password. Click the button below to set a new password. Reset Password This link will expire in 1 hour. If you didn't request this, please ignore this email. © 2025 Xpeditis. All rights reserved. `; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } /** * Render welcome email */ async renderWelcomeEmail(data: { firstName: string; dashboardUrl: string }): Promise { const mjmlTemplate = ` Welcome to Xpeditis, {{firstName}}! We're excited to have you on board. Xpeditis helps you search and book maritime freight with ease. Get started: • Search for shipping rates
• Compare carriers and prices
• Book containers online
• Track your shipments
Go to Dashboard
© 2025 Xpeditis. All rights reserved.
`; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } /** * Render user invitation email */ async renderUserInvitation(data: { organizationName: string; inviterName: string; tempPassword: string; loginUrl: string; }): Promise { const mjmlTemplate = ` You've Been Invited! {{inviterName}} has invited you to join {{organizationName}} on Xpeditis. Your temporary password: {{tempPassword}} Please change your password after your first login. Login Now © 2025 Xpeditis. All rights reserved. `; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } /** * Render CSV booking request email */ async renderCsvBookingRequest(data: { bookingId: string; origin: string; destination: string; volumeCBM: number; weightKG: number; palletCount: number; priceUSD: number; priceEUR: number; primaryCurrency: string; transitDays: number; containerType: string; documents: Array<{ type: string; fileName: string; }>; acceptUrl: string; rejectUrl: string; }): Promise { const mjmlTemplate = ` .info-row { padding: 8px 0; border-bottom: 1px solid #e0e0e0; } .info-label { font-weight: bold; color: #0066cc; } Nouvelle demande de réservation Xpeditis Bonjour, Vous avez reçu une nouvelle demande de réservation via Xpeditis. Veuillez examiner les détails ci-dessous et confirmer ou refuser cette demande. Détails du transport Route {{origin}} → {{destination}} Volume {{volumeCBM}} CBM Poids {{weightKG}} kg Palettes {{palletCount}} Type de conteneur {{containerType}} Transit {{transitDays}} jours Prix {{#if (eq primaryCurrency "EUR")}} {{priceEUR}} EUR {{else}} {{priceUSD}} USD {{/if}} {{#if (eq primaryCurrency "EUR")}} (≈ {{priceUSD}} USD) {{else}} (≈ {{priceEUR}} EUR) {{/if}} 📄 Documents fournis {{#each documents}} {{this.type}}: {{this.fileName}} {{/each}} Veuillez confirmer votre décision: ✓ Accepter la demande ✗ Refuser la demande ⚠️ Important Cette demande expire automatiquement dans 7 jours si aucune action n'est prise. Merci de répondre dans les meilleurs délais. Référence de réservation: {{bookingId}} © 2025 Xpeditis. Tous droits réservés. Cet email a été envoyé automatiquement. Merci de ne pas y répondre directement. `; // Register Handlebars helper for equality check Handlebars.registerHelper('eq', function (a, b) { return a === b; }); const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } }