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

@@ -3,6 +3,7 @@ import {
Logger,
NotFoundException,
BadRequestException,
ConflictException,
} from "@nestjs/common";
import { PrismaService } from "../../common/prisma.service";
import { SeatsService } from "../seats/seats.service";
@@ -897,12 +898,25 @@ export class PaymentsService {
try {
await this.ticketsService.generate(booking.id);
} catch (err) {
this.logger.error(
`Error generating ticket for booking ${booking.id}: ${err instanceof Error ? err.message : String(err)}`,
);
// Re-throw so callers (e.g. force-confirm) know tickets weren't issued.
// Webhook handlers catch this themselves and still return 200 to avoid redelivery.
throw err;
const msg = err instanceof Error ? err.message : String(err);
// Only reassign seats when a *different* booking genuinely holds the seat
// (ConflictException). Any other error (transient DB issue, etc.) is logged
// and swallowed — the passenger keeps their original seat and the ticket can
// be retried via "Generate Missing" in the backoffice.
if (err instanceof ConflictException) {
this.logger.warn(
`Seat conflict for booking ${booking.id}: ${msg}. Attempting smart seat reassignment.`,
);
try {
await this.ticketsService.smartAssignAndGenerate(booking.id);
} catch (retryErr) {
this.logger.error(
`Smart assign also failed for booking ${booking.id}: ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`,
);
}
} else {
this.logger.error(`Error generating ticket for booking ${booking.id}: ${msg}`);
}
}
try {