Skip to content

Commit

Permalink
Update src/server/services/home.ts
Browse files Browse the repository at this point in the history
Lijkt me een verbetering.

Co-authored-by: Terry van Walen <[email protected]>
  • Loading branch information
timvanoostrom and TerryvanWalen committed Dec 17, 2024
1 parent 9a05314 commit 6ad47be
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/server/services/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,35 @@ async function fetchCommercial(
export async function fetchMyLocation(
requestID: RequestID,
authProfileAndToken: AuthProfileAndToken
): Promise<ApiResponse<BAGData[] | null>> {

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<ApiResponse<(BAGData | null)[] | null>> {
switch (authProfileAndToken.profile.profileType) {
case 'commercial':
Expand Down

0 comments on commit 6ad47be

Please sign in to comment.