/** * 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; bookingNumber?: string; documentPassword?: 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 { // Register Handlebars helper for equality check Handlebars.registerHelper('eq', function (a, b) { return a === b; }); const htmlTemplate = ` Nouvelle demande de réservation

🚢 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.

{{#if bookingNumber}}

Numéro de devis

{{bookingNumber}}

{{#if documentPassword}}

🔐 Mot de passe pour accéder aux documents

{{documentPassword}}

Conservez ce mot de passe, il vous sera demandé pour télécharger les documents

{{/if}}
{{/if}}
📋 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 :

⚠️ Important
Cette demande expire automatiquement dans 7 jours si aucune action n'est prise. Merci de répondre dans les meilleurs délais.

`; const template = Handlebars.compile(htmlTemplate); return template(data); } /** * Render invitation email with registration link */ async renderInvitationWithToken(data: { firstName: string; lastName: string; organizationName: string; inviterName: string; invitationLink: string; expiresAt: string; }): Promise { const mjmlTemplate = ` 🚢 Bienvenue sur Xpeditis ! Bonjour {{firstName}} {{lastName}}, {{inviterName}} vous invite à rejoindre {{organizationName}} sur la plateforme Xpeditis. Xpeditis est la solution complète pour gérer vos expéditions maritimes en ligne. Recherchez des tarifs, réservez des containers et suivez vos envois en temps réel. Créer mon compte Ou copiez ce lien dans votre navigateur: {{invitationLink}} ⏱️ Cette invitation expire le {{expiresAt}} Créez votre compte avant cette date pour rejoindre votre organisation. © 2025 Xpeditis. Tous droits réservés. Si vous n'avez pas sollicité cette invitation, vous pouvez ignorer cet email. `; const { html } = mjml2html(mjmlTemplate); const template = Handlebars.compile(html); return template(data); } }