mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 11:08:12 +00:00
refactor: ( bookings ) unify authenticated booking flow with guest service
This commit is contained in:
@@ -261,10 +261,26 @@ export class PassengerAuthService {
|
||||
|
||||
if (!passenger) throw new Error('Passenger not found');
|
||||
const iam = iamRows[0];
|
||||
const meta = iam?.metadata ?? {};
|
||||
const faydaVerified = iam?.verified_by === 'fayda';
|
||||
const nationality = iam?.metadata?.nationality ?? null;
|
||||
// A Fayda-verified holder is an Ethiopian national ID holder, so default nationality to
|
||||
// Ethiopian when the metadata doesn't carry it explicitly.
|
||||
const nationality = meta.nationality ?? (faydaVerified ? 'ETHIOPIAN' : null);
|
||||
// Fayda stores gender as { am, en }; tolerate a legacy plain string too.
|
||||
const gender =
|
||||
meta.gender && typeof meta.gender === 'object'
|
||||
? (meta.gender.en ?? meta.gender.am ?? null)
|
||||
: (meta.gender ?? null);
|
||||
// birthdate is persisted as ISO by the Fayda upsert; tolerate a "/"-separated legacy value.
|
||||
const rawDob = meta.dateOfBirth ?? meta.birthdate ?? null;
|
||||
const dateOfBirth = rawDob ? String(rawDob).replace(/\//g, '-') : null;
|
||||
|
||||
return {
|
||||
// The web User object keys on `id` (the IAM user id) — the login response returns it, so
|
||||
// this profile refresh MUST too, otherwise fetchProfile() overwrites the logged-in user
|
||||
// with an id-less object and everything guarded on `user.id` (passenger-form prefill,
|
||||
// save-details userId) silently breaks.
|
||||
id: iamUserId,
|
||||
iamUserId,
|
||||
// Top-level passengerId keeps the profile shape consistent with the login
|
||||
// response so the web User object always carries it (the JWT does not).
|
||||
@@ -272,8 +288,11 @@ export class PassengerAuthService {
|
||||
email: iam?.email ?? null,
|
||||
phone: iam?.phone_number ?? null,
|
||||
fullName: iam?.name?.en ?? iam?.name?.am ?? null,
|
||||
gender,
|
||||
dateOfBirth,
|
||||
nationality,
|
||||
faydaVerified,
|
||||
faydaSub: meta.sub ?? null,
|
||||
preferredCurrency: resolvePreferredCurrency(nationality, faydaVerified),
|
||||
createdAt: passenger.createdAt,
|
||||
passenger: {
|
||||
|
||||
Reference in New Issue
Block a user