Reports update

This commit is contained in:
Stephanos A
2026-07-19 09:16:36 +03:00
parent 20718d5b98
commit 856d143874

View File

@@ -266,7 +266,7 @@ export class ReportsService {
where: { status: { in: ["CONFIRMED", "BOARDED"] } },
include: {
seats: {
where: { scheduleId },
where: { leg: 1 },
include: {
seat: { include: { coach: { include: { coachType: true } } } },
},
@@ -432,33 +432,45 @@ export class ReportsService {
async getPassengerList(scheduleId: string) {
const seats = await this.prisma.bookingSeat.findMany({
where: {
scheduleId,
booking: { status: { in: ["CONFIRMED", "BOARDED"] } },
leg: 1,
booking: { scheduleId, status: { in: ["CONFIRMED", "BOARDED"] } },
},
include: {
booking: { select: { bookingRef: true, status: true } },
seat: {
include: {
coach: {
select: { number: true, coachType: { select: { name: true } } },
},
booking: {
select: {
bookingRef: true,
status: true,
originStationId: true,
destinationStationId: true,
},
},
seat: { include: { coach: { select: { number: true } } } },
},
orderBy: [{ seat: { coach: { number: "asc" } } }],
orderBy: [{ seat: { coach: { number: "asc" } } }, { seat: { seatNumber: "asc" } }],
});
const stationIds = [...new Set(
seats.flatMap(bs => [bs.booking.originStationId, bs.booking.destinationStationId]).filter(Boolean) as string[],
)];
const stations = stationIds.length > 0
? await this.prisma.station.findMany({ where: { id: { in: stationIds } }, select: { id: true, name: true } })
: [];
const stationName = new Map(stations.map(s => [s.id, s.name]));
const schedule = await this.prisma.trainSchedule.findUnique({
where: { id: scheduleId },
select: { departureAt: true },
});
return seats.map((bs) => ({
bookingRef: bs.booking.bookingRef,
bookingStatus: bs.booking.status,
passengerName: bs.passengerName,
passengerCategory: bs.passengerCategory,
idDocumentType: bs.idDocumentType,
idDocumentNumber: bs.idDocumentNumber,
passportNumber: bs.passportNumber,
passportCountry: bs.passportCountry,
seatLabel: bs.seatLabelSnapshot,
coachNumber: bs.seat?.coach?.number ?? null,
coachType: (bs.seat?.coach as any)?.coachType?.name ?? null,
coachSeat: bs.seat?.coach?.number && bs.seatLabelSnapshot
? `${bs.seat.coach.number}·${bs.seatLabelSnapshot}`
: (bs.seatLabelSnapshot ?? '—'),
origin: bs.booking.originStationId ? (stationName.get(bs.booking.originStationId) ?? '—') : '—',
destination: bs.booking.destinationStationId ? (stationName.get(bs.booking.destinationStationId) ?? '—') : '—',
departureAt: schedule?.departureAt ?? null,
}));
}