Ticket generation updates

This commit is contained in:
Stephanos A
2026-07-22 13:43:38 +03:00
parent 44b4779ca6
commit 698dbd47e6
3 changed files with 42 additions and 10 deletions

View File

@@ -352,8 +352,20 @@ export class TicketsService {
}
}
// Check for seat conflicts before deleting existing tickets or issuing new ones
await this.prisma.ticket.deleteMany({ where: { bookingId } });
// Remove any SeatBlock rows left over from a previous generate() run for this
// booking — they reference the old ticket IDs which are now deleted, and would
// otherwise cause the conflict check below to see this booking's own seats as
// blocked by another booking.
const seatIds = (booking as any).seats.map((bs: any) => bs.seatId);
await this.prisma.seatBlock.deleteMany({
where: { seatId: { in: seatIds }, blockedBy: 'SYSTEM', approvedBy: 'SYSTEM' },
});
// Check for seat conflicts — only seats confirmed/boarded by a *different* booking
// on the same schedule are a real conflict. SeatBlock rows created by a previous
// generate() run for this booking are NOT a conflict; they are cleaned up above.
const conflictingSeats = await this.prisma.bookingSeat.findMany({
where: {
seatId: { in: seatIds },
@@ -371,8 +383,6 @@ export class TicketsService {
);
}
await this.prisma.ticket.deleteMany({ where: { bookingId } });
// Generate one ticket per passenger per leg.
// Round-trip / transit bookings have seats on multiple legs — each leg needs its own
// ticket so the voucher can match by (passengerName, leg) and gate scanners can