mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
Seatmap rendering and other updates
This commit is contained in:
@@ -50,31 +50,56 @@ export class SearchService {
|
||||
const availabilityByClass: Record<string, number> = {};
|
||||
|
||||
for (const assignment of schedule.coachAssignments) {
|
||||
// Get seat class names from coach type
|
||||
const seatClassNames = assignment.coach.coachType?.seatClasses?.map((sc: any) => sc.name) || ['Standard'];
|
||||
|
||||
for (const seatClassName of seatClassNames) {
|
||||
if (!availabilityByClass[seatClassName]) availabilityByClass[seatClassName] = 0;
|
||||
}
|
||||
const isBedCoach = assignment.coach.seats.some((s: any) => s.bedPosition);
|
||||
|
||||
// Count available seats (skip blocked and removed seats)
|
||||
for (const seat of assignment.coach.seats) {
|
||||
// Skip blocked seats
|
||||
if (seat.status === 'BLOCKED') continue;
|
||||
if (isBedCoach) {
|
||||
const bedPositions = ['upper', 'middle', 'lower'];
|
||||
for (const bedPosition of bedPositions) {
|
||||
let count = 0;
|
||||
for (const seat of assignment.coach.seats) {
|
||||
if (seat.bedPosition !== bedPosition) continue;
|
||||
if (seat.status === 'BLOCKED') continue;
|
||||
if (!seat.seatNumber || !seat.seatNumber.trim()) continue;
|
||||
|
||||
const free = await this.segmentsService.isSeatFreeForLeg(
|
||||
schedule.id, seat.id,
|
||||
originStop.sequence, destStop.sequence,
|
||||
);
|
||||
if (free) count++;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
const matchingClass = seatClassNames.find((className: string) => {
|
||||
const classNameLower = className.toLowerCase();
|
||||
return (
|
||||
(bedPosition === 'upper' && classNameLower.includes('upper')) ||
|
||||
(bedPosition === 'middle' && classNameLower.includes('middle')) ||
|
||||
(bedPosition === 'lower' && classNameLower.includes('lower'))
|
||||
);
|
||||
});
|
||||
if (matchingClass) {
|
||||
if (!availabilityByClass[matchingClass]) availabilityByClass[matchingClass] = 0;
|
||||
availabilityByClass[matchingClass] += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let availableSeatsInCoach = 0;
|
||||
for (const seat of assignment.coach.seats) {
|
||||
if (seat.status === 'BLOCKED') continue;
|
||||
if (!seat.seatNumber || !seat.seatNumber.trim()) continue;
|
||||
|
||||
const free = await this.segmentsService.isSeatFreeForLeg(
|
||||
schedule.id, seat.id,
|
||||
originStop.sequence, destStop.sequence,
|
||||
);
|
||||
if (free) availableSeatsInCoach++;
|
||||
}
|
||||
|
||||
// Skip removed seats (empty seatNumber)
|
||||
if (!seat.seatNumber || !seat.seatNumber.trim()) continue;
|
||||
|
||||
const free = await this.segmentsService.isSeatFreeForLeg(
|
||||
schedule.id, seat.id,
|
||||
originStop.sequence, destStop.sequence,
|
||||
);
|
||||
|
||||
if (free) {
|
||||
// Group by seat class - use the first seat class for now
|
||||
// In a full implementation, seats would have a seatClassId
|
||||
const className = seatClassNames[0] || 'Standard';
|
||||
availabilityByClass[className]++;
|
||||
for (const seatClassName of seatClassNames) {
|
||||
if (!availabilityByClass[seatClassName]) availabilityByClass[seatClassName] = 0;
|
||||
availabilityByClass[seatClassName] += availableSeatsInCoach;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,7 +250,6 @@ export class SearchService {
|
||||
destinationStationId: string,
|
||||
nationality?: string,
|
||||
): Promise<Array<{ seatClassName: string; baseFareMinor: number }>> {
|
||||
// Get unique seat classes from all coaches assigned to this schedule via their coach types
|
||||
const seatClassIds: string[] = Array.from(
|
||||
new Set(
|
||||
schedule.coachAssignments
|
||||
|
||||
Reference in New Issue
Block a user