From 31121db07b7337d17c28f8e0469ac9b7c25ad23a Mon Sep 17 00:00:00 2001 From: Abubeker Yasin Date: Mon, 31 Aug 2026 14:24:59 +0300 Subject: [PATCH] Update bookings.service.ts --- .../src/modules/bookings/bookings.service.ts | 42 ++----------------- 1 file changed, 4 insertions(+), 38 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 a3931ef1f..004aca024 100644 --- a/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts +++ b/apps/edr-passenger-api/src/modules/bookings/bookings.service.ts @@ -99,8 +99,8 @@ export class BookingsService { * findByIamUserId (the portal's own history) so the two can never disagree about * what a phone number owns. * - * Each sub-lookup is independently catch-and-warn: a phone match is a best-effort - * widening, and one unavailable source must not fail the whole listing. + * The IAM lookup is catch-and-warn: a phone match is a best-effort widening, and an + * unavailable IAM must not fail the whole listing. */ private async buildPhoneOwnershipClauses( variants: string[], @@ -126,47 +126,13 @@ export class BookingsService { })).map(p => p.id) : []; - // Guest bookings store phone in TravelerProfile.notes JSON (created for every guest - // booking). Catches cases where contactPhone was null but the profile recorded it. - const travelerRows = await this.dataSource - .query<{ passengerId: string }[]>( - `SELECT DISTINCT passenger_id AS "passengerId" - FROM passenger.traveler_profiles - WHERE notes IS NOT NULL - AND (notes::jsonb->>'phone') = ANY($1::text[])`, - [variants], - ) - .catch((err: unknown) => { - this.logger.warn(`TravelerProfile phone lookup failed: ${err instanceof Error ? err.message : String(err)}`); - return [] as { passengerId: string }[]; - }); - - // Guests who saved their profile (savePassengerDetails:true) have a - // SavedPassengerProfile row with phone + deviceId; guest bookings stash that - // deviceId in Booking.userAgent. - const savedProfileRows = await this.dataSource - .query<{ deviceId: string }[]>( - `SELECT DISTINCT device_id AS "deviceId" - FROM passenger.saved_passenger_profiles - WHERE phone = ANY($1::text[]) AND device_id IS NOT NULL`, - [variants], - ) - .catch((err: unknown) => { - this.logger.warn(`SavedPassengerProfile phone lookup failed: ${err instanceof Error ? err.message : String(err)}`); - return [] as { deviceId: string }[]; - }); - - const allPassengerIds = [...new Set([...iamPassengerIds, ...travelerRows.map(r => r.passengerId)])]; - const guestDeviceIds = savedProfileRows.map(r => r.deviceId); - return { clauses: [ { contactPhone: { in: variants } }, { passenger: { user: { phone: { in: variants } } } }, - ...(allPassengerIds.length > 0 ? [{ passengerId: { in: allPassengerIds } }] : []), - ...(guestDeviceIds.length > 0 ? [{ userAgent: { in: guestDeviceIds } }] : []), + ...(iamPassengerIds.length > 0 ? [{ passengerId: { in: iamPassengerIds } }] : []), ], - passengerIds: allPassengerIds, + passengerIds: iamPassengerIds, }; }