From 89b99b0a0845e5adac6bd2c92db319bcf9c7141a Mon Sep 17 00:00:00 2001 From: Roba Boru Date: Tue, 14 Jul 2026 21:57:34 +0300 Subject: [PATCH] Fix seat label --- .../src/modules/bookings/bookings.service.ts | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts b/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts index 45091a604..70fef6b08 100644 --- a/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts +++ b/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts @@ -1892,20 +1892,32 @@ export class BookingsService { departureAt: returnSegment!.departureAt, arrivalAt: returnSegment!.arrivalAt, } : null, - passengers: (booking as any).seats?.map((bs: any) => ({ - fullName: bs.passengerName, - category: bs.passengerCategory, - leg: bs.leg ?? 1, - fareMinor: bs.fareMinor, - verifaydaVerified: bs.verifaydaVerified, - seat: { - id: bs.seat.id, - number: bs.seat.seatNumber, - coach: bs.seat.coach.number, - coachId: bs.seat.coach.id, - seatClass: bs.seat.coach.coachType?.seatClasses?.[0]?.name ?? null, - }, - })), + passengers: (booking as any).seats?.map((bs: any) => { + // A coach type can have several seat classes (e.g. a VIP Bed coach has separate + // Upper/Lower classes) — seatClasses[0] is whichever was seeded first, so it always + // showed the SAME class for every seat in the coach regardless of that seat's own + // bed position. Match against the seat's actual bedPosition instead (Seat.bedPosition + // is lowercase, SeatClass.bedPosition is uppercase — compare case-insensitively). + // Falls back to [0] for non-bed seats (bedPosition is null, single class per coach). + const classes = bs.seat.coach.coachType?.seatClasses ?? []; + const matchedClass = bs.seat.bedPosition + ? classes.find((sc: any) => sc.bedPosition?.toLowerCase() === bs.seat.bedPosition.toLowerCase()) + : null; + return { + fullName: bs.passengerName, + category: bs.passengerCategory, + leg: bs.leg ?? 1, + fareMinor: bs.fareMinor, + verifaydaVerified: bs.verifaydaVerified, + seat: { + id: bs.seat.id, + number: bs.seat.seatNumber, + coach: bs.seat.coach.number, + coachId: bs.seat.coach.id, + seatClass: (matchedClass ?? classes[0])?.name ?? null, + }, + }; + }), payment: (booking as any).paymentIntent ? { method: (booking as any).paymentIntent.method,