mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 07:51:02 +00:00
Seat block issue resolution
This commit is contained in:
@@ -224,16 +224,27 @@ export class SeatsService {
|
||||
}
|
||||
}
|
||||
|
||||
const availability = await this.segmentsService.getSeatAvailabilityMap(
|
||||
scheduleId, seatIds, stopTimes, reqFrom, reqTo, journeyDirection || JourneyDirection.ONE_WAY,
|
||||
);
|
||||
const [availability, persistedSeats] = await Promise.all([
|
||||
this.segmentsService.getSeatAvailabilityMap(
|
||||
scheduleId, seatIds, stopTimes, reqFrom, reqTo, journeyDirection || JourneyDirection.ONE_WAY,
|
||||
),
|
||||
this.prisma.seat.findMany({
|
||||
where: { id: { in: seatIds } },
|
||||
select: { id: true, status: true },
|
||||
}),
|
||||
]);
|
||||
|
||||
const persistedStatus = new Map(persistedSeats.map(s => [s.id, s.status]));
|
||||
|
||||
// Every requested seat defaults to AVAILABLE — this also guards against a stale
|
||||
// persisted Seat.status column (e.g. a leftover 'BOOKED'/'BLOCKED' value) bleeding
|
||||
// through getSeatMap's own fallback, since that fallback only triggers when this
|
||||
// map has no entry at all for a given seat.
|
||||
for (const seatId of seatIds) {
|
||||
statusMap.set(seatId, availability.get(seatId) ?? 'AVAILABLE');
|
||||
const persisted = persistedStatus.get(seatId);
|
||||
// BLOCKED and UNDER_MAINTENANCE are cross-schedule flags set by admins —
|
||||
// always honour them regardless of hold/booking state.
|
||||
if ((persisted as string) === 'BLOCKED' || (persisted as string) === 'UNDER_MAINTENANCE') {
|
||||
statusMap.set(seatId, persisted!);
|
||||
} else {
|
||||
statusMap.set(seatId, availability.get(seatId) ?? 'AVAILABLE');
|
||||
}
|
||||
}
|
||||
|
||||
return statusMap;
|
||||
|
||||
Reference in New Issue
Block a user