Seat block issue resolution

This commit is contained in:
Stephanos A
2026-07-15 21:11:23 +03:00
parent 8bda06b226
commit 2d2fcfbda9
2 changed files with 35 additions and 17 deletions

View File

@@ -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;