From 6ad47be07fa347f59db116d9f34397791ae18445 Mon Sep 17 00:00:00 2001 From: Tim van Oostrom Date: Tue, 17 Dec 2024 10:25:20 +0100 Subject: [PATCH] Update src/server/services/home.ts Lijkt me een verbetering. Co-authored-by: Terry van Walen --- src/server/services/home.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/server/services/home.ts b/src/server/services/home.ts index 1a3d72ddb..373770c33 100644 --- a/src/server/services/home.ts +++ b/src/server/services/home.ts @@ -99,6 +99,35 @@ async function fetchCommercial( export async function fetchMyLocation( requestID: RequestID, authProfileAndToken: AuthProfileAndToken +): Promise> { + + const {content: commercialAddresses} = await fetchCommercial( + requestID, + authProfileAndToken + ); + + if (authProfileAndToken.profile.profileType === 'commercial') { + return apiSuccessResult((commercialAddresses || []).filter((location) => location !== null)) + } + + const {content: privateAddresses} = await fetchPrivate( + requestID, + authProfileAndToken + ); + + const locations: BAGData[] = [ + ...(privateAddresses || []), + ...(commercialAddresses || []), + ].filter((location) => location !== null) + + if (locations.length === 0) { + return apiErrorResult('Could not fetch locations.', null); + } + + return apiSuccessResult(locations) +} + requestID: RequestID, + authProfileAndToken: AuthProfileAndToken ): Promise> { switch (authProfileAndToken.profile.profileType) { case 'commercial':