notification implemented
This commit is contained in:
@@ -3,7 +3,8 @@ import { prisma } from '../../lib/prisma'
|
||||
import { AppError } from '../../http/errors'
|
||||
import { validateLicense } from '../../services/licenseValidationService'
|
||||
import { sendNotification, sendTransactionalEmail } from '../../services/notificationService'
|
||||
import { bookingConfirmedNotif, reviewRequestEmail, type Lang } from '../../lib/emailTranslations'
|
||||
import { reviewRequestEmail, type Lang } from '../../lib/emailTranslations'
|
||||
import { coerceNotificationLocale } from '../../services/notificationLocalizationService'
|
||||
import { buildReservationWorkflow, parseReservationExtras, serializeReservationForDashboard } from './reservation.presenter'
|
||||
import * as repo from './reservation.repo'
|
||||
|
||||
@@ -39,19 +40,27 @@ export async function confirmReservation(id: string, companyId: string) {
|
||||
|
||||
const updated = await repo.updateById(id, { status: 'CONFIRMED' })
|
||||
|
||||
const [customer, brand] = await Promise.all([
|
||||
const [customer, company, vehicle] = await Promise.all([
|
||||
repo.findCustomerById(reservation.customerId),
|
||||
repo.findBrandLocale(companyId),
|
||||
repo.findCompanyWithBrand(companyId),
|
||||
repo.findVehicle(reservation.vehicleId, companyId),
|
||||
])
|
||||
const lang = (brand?.defaultLocale ?? 'fr') as Lang
|
||||
const fallbackLocale = coerceNotificationLocale(company?.brand?.defaultLocale)
|
||||
await sendNotification({
|
||||
type: 'BOOKING_CONFIRMED',
|
||||
title: bookingConfirmedNotif.title(lang),
|
||||
body: bookingConfirmedNotif.body(lang),
|
||||
companyId,
|
||||
renterId: reservation.renterId ?? undefined,
|
||||
email: customer.email,
|
||||
channels: ['EMAIL', 'IN_APP'],
|
||||
locale: lang,
|
||||
locale: reservation.renterId ? undefined : fallbackLocale,
|
||||
templateKey: 'booking.confirmed',
|
||||
templateVariables: {
|
||||
firstName: customer.firstName,
|
||||
companyName: company?.brand?.displayName ?? company?.name ?? 'RentalDriveGo',
|
||||
startDate: reservation.startDate,
|
||||
endDate: reservation.endDate,
|
||||
vehicleName: `${vehicle.year} ${vehicle.make} ${vehicle.model}`,
|
||||
},
|
||||
}).catch(() => null)
|
||||
|
||||
return updated
|
||||
|
||||
Reference in New Issue
Block a user