update reservation
This commit is contained in:
@@ -8,6 +8,17 @@ import { coerceNotificationLocale } from '../../services/notificationLocalizatio
|
||||
import { buildReservationWorkflow, parseReservationExtras, serializeReservationForDashboard } from './reservation.presenter'
|
||||
import * as repo from './reservation.repo'
|
||||
|
||||
function buildPickupAddress(value: unknown) {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return ''
|
||||
|
||||
const address = value as Record<string, unknown>
|
||||
return [
|
||||
typeof address.streetAddress === 'string' ? address.streetAddress.trim() : '',
|
||||
typeof address.city === 'string' ? address.city.trim() : '',
|
||||
typeof address.country === 'string' ? address.country.trim() : '',
|
||||
].filter(Boolean).join(', ')
|
||||
}
|
||||
|
||||
async function assertLicenseCompliance(reservationId: string, companyId: string) {
|
||||
const reservation = await repo.findForLicenseCheck(reservationId, companyId)
|
||||
|
||||
@@ -46,6 +57,7 @@ export async function confirmReservation(id: string, companyId: string) {
|
||||
repo.findVehicle(reservation.vehicleId, companyId),
|
||||
])
|
||||
const fallbackLocale = coerceNotificationLocale(company?.brand?.defaultLocale)
|
||||
const pickupLocation = reservation.pickupLocation?.trim() || buildPickupAddress(company?.address)
|
||||
await sendNotification({
|
||||
type: 'BOOKING_CONFIRMED',
|
||||
companyId,
|
||||
@@ -57,8 +69,29 @@ export async function confirmReservation(id: string, companyId: string) {
|
||||
templateVariables: {
|
||||
firstName: customer.firstName,
|
||||
companyName: company?.brand?.displayName ?? company?.name ?? 'RentalDriveGo',
|
||||
startDate: reservation.startDate,
|
||||
endDate: reservation.endDate,
|
||||
startDate: {
|
||||
type: 'date',
|
||||
value: reservation.startDate,
|
||||
options: {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
},
|
||||
},
|
||||
endDate: {
|
||||
type: 'date',
|
||||
value: reservation.endDate,
|
||||
options: {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
},
|
||||
},
|
||||
pickupLocation,
|
||||
vehicleName: `${vehicle.year} ${vehicle.make} ${vehicle.model}`,
|
||||
},
|
||||
}).catch(() => null)
|
||||
|
||||
Reference in New Issue
Block a user