Passenger and seats reports updates

This commit is contained in:
Stephanos A
2026-07-22 07:15:49 +03:00
parent d524f5b7e4
commit 7e670ab5bb
5 changed files with 19 additions and 1089 deletions

View File

@@ -272,13 +272,17 @@ export class ReportsService {
if (!schedule) return null;
// Fetch booking seats directly by scheduleIdavoids deserializing legacy
// BookingSeat rows with null scheduleId that crash Prisma when loaded via relation.
// Fetch booking seats for this schedule — covers:
// • outbound seats (leg=1, scheduleId=scheduleId)
// • return seats (leg=2, booking.returnScheduleId=scheduleId)
// • legacy rows where scheduleId is null but booking.scheduleId matches
const allBookingSeats = await this.prisma.bookingSeat.findMany({
where: {
scheduleId,
leg: 1,
booking: { status: { in: ['CONFIRMED', 'BOARDED'] } },
OR: [
{ scheduleId, booking: { status: { in: ['CONFIRMED', 'BOARDED'] } } },
{ leg: 2, booking: { returnScheduleId: scheduleId, status: { in: ['CONFIRMED', 'BOARDED'] } } },
{ scheduleId: null, leg: 1, booking: { scheduleId, status: { in: ['CONFIRMED', 'BOARDED'] } } },
],
},
select: {
bookingId: true,
@@ -379,9 +383,11 @@ export class ReportsService {
async getPassengerList(scheduleId: string) {
const seats = await this.prisma.bookingSeat.findMany({
where: {
scheduleId,
leg: 1,
booking: { status: { in: ["CONFIRMED", "BOARDED"] } },
OR: [
{ scheduleId, booking: { status: { in: ['CONFIRMED', 'BOARDED'] } } },
{ leg: 2, booking: { returnScheduleId: scheduleId, status: { in: ['CONFIRMED', 'BOARDED'] } } },
{ scheduleId: null, leg: 1, booking: { scheduleId, status: { in: ['CONFIRMED', 'BOARDED'] } } },
],
},
include: {
booking: {
@@ -448,9 +454,11 @@ export class ReportsService {
// Confirmed/boarded seats — exclude dining coaches
const bookingSeats = await this.prisma.bookingSeat.findMany({
where: {
scheduleId,
leg: 1,
booking: { status: { in: ['CONFIRMED', 'BOARDED', 'PENDING_PAYMENT'] } },
OR: [
{ scheduleId, booking: { status: { in: ['CONFIRMED', 'BOARDED', 'PENDING_PAYMENT'] } } },
{ leg: 2, booking: { returnScheduleId: scheduleId, status: { in: ['CONFIRMED', 'BOARDED', 'PENDING_PAYMENT'] } } },
{ scheduleId: null, leg: 1, booking: { scheduleId, status: { in: ['CONFIRMED', 'BOARDED', 'PENDING_PAYMENT'] } } },
],
seat: { coach: { coachType: { type: { not: 'dining' } } } },
},
include: {