Ticketing updates

This commit is contained in:
Stephanos A
2026-07-22 14:06:00 +03:00
parent 698dbd47e6
commit 2632e2d50c
2 changed files with 19 additions and 14 deletions

View File

@@ -1916,21 +1916,26 @@ export class BookingsService {
) {
try {
await this.ticketsService.generate(booking.id);
// Re-fetch to include the newly created tickets
const refreshed = await this.prisma.booking.findUnique({
where: { id: booking.id },
include: {
schedule: { include: { originStation: true, destinationStation: true, train: true, stopTimes: { include: { station: true } } } },
returnSchedule: { include: { originStation: true, destinationStation: true, train: true, stopTimes: { include: { station: true } } } },
seats: { include: { seat: { include: { coach: { include: { coachType: { include: { seatClasses: true } } } } } } } },
paymentIntent: true, tickets: true,
priceTier: { select: { priceMinor: true } },
},
});
if (refreshed) Object.assign(booking, refreshed);
} catch (err) {
this.logger.warn(`getByRef: auto-generate tickets failed for booking ${booking.id}: ${err instanceof Error ? err.message : String(err)}`);
this.logger.warn(`getByRef: generate failed for booking ${booking.id}: ${err instanceof Error ? err.message : String(err)}. Trying smart assign.`);
try {
await this.ticketsService.smartAssignAndGenerate(booking.id);
} catch (retryErr) {
this.logger.error(`getByRef: smart assign also failed for booking ${booking.id}: ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`);
}
}
// Re-fetch to include any newly created tickets
const refreshed = await this.prisma.booking.findUnique({
where: { id: booking.id },
include: {
schedule: { include: { originStation: true, destinationStation: true, train: true, stopTimes: { include: { station: true } } } },
returnSchedule: { include: { originStation: true, destinationStation: true, train: true, stopTimes: { include: { station: true } } } },
seats: { include: { seat: { include: { coach: { include: { coachType: { include: { seatClasses: true } } } } } } } },
paymentIntent: true, tickets: true,
priceTier: { select: { priceMinor: true } },
},
});
if (refreshed) Object.assign(booking, refreshed);
}
const outboundSegment = this.resolveSegmentStations(

View File

@@ -360,7 +360,7 @@ export class TicketsService {
// 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' },
where: { seatId: { in: seatIds }, blockedBy: 'SYSTEM' },
});
// Check for seat conflicts — only seats confirmed/boarded by a *different* booking