mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-02 15:03:39 +00:00
Cut off time configuration
This commit is contained in:
@@ -7,6 +7,7 @@ import { PushAdapter, NotificationChannel } from './notification.adapters';
|
||||
import { EmailClientService } from './email-client.service';
|
||||
import { SmsClientService } from './sms-client.service';
|
||||
import { CreateTemplateDto, UpdateTemplateDto } from './notifications.dto';
|
||||
import { resolveBookingSegment } from '../../common/utils/segment-resolver.utils';
|
||||
|
||||
export type NotificationChannelType = 'EMAIL' | 'SMS' | 'PUSH' | 'IN_APP';
|
||||
|
||||
@@ -353,27 +354,6 @@ export class NotificationsService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the user's actual boarding/alighting stations from the booking's originStationId /
|
||||
* destinationStationId via stopTimes, falling back to the schedule's full-route endpoints when
|
||||
* the booking has no segment override (e.g. older records or packages).
|
||||
*/
|
||||
private resolveSegmentStations(booking: any): { originStation: any; destinationStation: any } {
|
||||
const s = booking?.schedule ?? {};
|
||||
const stopTimes: any[] = s.stopTimes ?? [];
|
||||
const findStation = (stationId: string | null | undefined, fallback: any) => {
|
||||
if (stationId && stopTimes.length > 0) {
|
||||
const stop = stopTimes.find((st: any) => st.stationId === stationId);
|
||||
if (stop?.station) return stop.station;
|
||||
}
|
||||
return fallback ?? null;
|
||||
};
|
||||
return {
|
||||
originStation: findStation(booking?.originStationId, s.originStation),
|
||||
destinationStation: findStation(booking?.destinationStationId, s.destinationStation),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the interpolation context for the `booking.created` template. `trainSeatLines` is a
|
||||
* pre-joined block of one "Train/Seat: …" line per booked seat (multi-passenger bookings get
|
||||
@@ -400,17 +380,17 @@ export class NotificationsService {
|
||||
// Lead passenger (leg-1 seat). Booking has no contactName; the traveller name lives on the seat.
|
||||
const passengerName = seats[0]?.passengerName ?? 'Passenger';
|
||||
const payLink = `${process.env.PORTAL_URL ?? 'http://localhost:5174'}/booking/detail?ref=${ref}`;
|
||||
const { originStation: originSt, destinationStation: destSt } = this.resolveSegmentStations(booking);
|
||||
const segment = resolveBookingSegment(s, booking?.originStationId, booking?.destinationStationId);
|
||||
|
||||
return {
|
||||
passengerName,
|
||||
bookingRef: ref,
|
||||
origin: originSt?.name ?? '',
|
||||
destination: destSt?.name ?? '',
|
||||
origin: segment.origin?.name ?? '',
|
||||
destination: segment.destination?.name ?? '',
|
||||
trainSeatLines,
|
||||
travelDate: fmtDate(s.departureAt),
|
||||
departureTime: fmtTime(s.departureAt),
|
||||
arrivalTime: fmtTime(s.arrivalAt),
|
||||
travelDate: fmtDate(segment.departureAt),
|
||||
departureTime: fmtTime(segment.departureAt),
|
||||
arrivalTime: fmtTime(segment.arrivalAt),
|
||||
payLink,
|
||||
};
|
||||
}
|
||||
@@ -509,12 +489,12 @@ export class NotificationsService {
|
||||
|
||||
private buildTicketEmailText(booking: any, amount: string, currency: string, url: string): string {
|
||||
const s = booking.schedule ?? {};
|
||||
const dep = s.departureAt ? new Date(s.departureAt).toLocaleString('en-GB') : 'TBD';
|
||||
const segment = resolveBookingSegment(s, booking?.originStationId, booking?.destinationStationId);
|
||||
const dep = segment.departureAt ? new Date(segment.departureAt).toLocaleString('en-GB') : 'TBD';
|
||||
const passengers = (booking.seats ?? []).map((bs: any) => bs.passengerName).filter(Boolean).join(', ');
|
||||
const { originStation: originSt, destinationStation: destSt } = this.resolveSegmentStations(booking);
|
||||
return [
|
||||
`Booking ${booking.bookingRef} confirmed.`,
|
||||
`${originSt?.name ?? ''} -> ${destSt?.name ?? ''}`,
|
||||
`${segment.origin?.name ?? ''} -> ${segment.destination?.name ?? ''}`,
|
||||
`Train: ${s.train?.name ?? s.train?.number ?? ''}`,
|
||||
`Departs: ${dep}`,
|
||||
passengers ? `Passengers: ${passengers}` : '',
|
||||
@@ -527,7 +507,9 @@ export class NotificationsService {
|
||||
const s = booking.schedule ?? {};
|
||||
const fmt = (d: any) =>
|
||||
d ? new Date(d).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) : 'TBD';
|
||||
const { originStation: originSt, destinationStation: destSt } = this.resolveSegmentStations(booking);
|
||||
const segment = resolveBookingSegment(s, booking?.originStationId, booking?.destinationStationId);
|
||||
const originSt = segment.origin;
|
||||
const destSt = segment.destination;
|
||||
const seatRows = (booking.seats ?? [])
|
||||
.map((bs: any) => {
|
||||
const coach = bs.seat?.coach?.number ?? '-';
|
||||
@@ -568,11 +550,11 @@ export class NotificationsService {
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:8px 0;color:#666;">Departs</td>
|
||||
<td style="padding:8px 0;text-align:right;">${fmt(s.departureAt)}</td>
|
||||
<td style="padding:8px 0;text-align:right;">${fmt(segment.departureAt)}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding:8px 0;color:#666;">Arrives</td>
|
||||
<td style="padding:8px 0;text-align:right;">${fmt(s.arrivalAt)}</td>
|
||||
<td style="padding:8px 0;text-align:right;">${fmt(segment.arrivalAt)}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -636,12 +618,12 @@ export class NotificationsService {
|
||||
const fmt = (d: any) =>
|
||||
d ? new Date(d).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) : 'TBD';
|
||||
const legLabel = leg ? ` (${leg.replace(/_/g, ' ')})` : '';
|
||||
const { originStation: originSt, destinationStation: destSt } = this.resolveSegmentStations(booking);
|
||||
const origin = originSt?.name ?? '';
|
||||
const dest = destSt?.name ?? '';
|
||||
const segment = resolveBookingSegment(s, booking?.originStationId, booking?.destinationStationId);
|
||||
const origin = segment.origin?.name ?? '';
|
||||
const dest = segment.destination?.name ?? '';
|
||||
const train = s.train?.name ?? s.train?.number ?? '';
|
||||
const dep = fmt(s.departureAt);
|
||||
const arr = fmt(s.arrivalAt);
|
||||
const dep = fmt(segment.departureAt);
|
||||
const arr = fmt(segment.arrivalAt);
|
||||
|
||||
const seats: { name: string; coach: string; seat: string; cls: string }[] = (booking.seats ?? []).map((bs: any) => ({
|
||||
name: bs.passengerName ?? '',
|
||||
|
||||
Reference in New Issue
Block a user