diff --git a/src/app/services/provider.service.ts b/src/app/services/provider.service.ts index e3554269..bc9f0d1e 100644 --- a/src/app/services/provider.service.ts +++ b/src/app/services/provider.service.ts @@ -1,6 +1,6 @@ -import { Injectable, inject } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; -import { Observable, map, catchError, of, forkJoin } from 'rxjs'; +import { Injectable, inject } from '@angular/core'; +import { Observable, catchError, forkJoin, map, of } from 'rxjs'; import { environment } from '../../environments/environment'; import { FilterOptions } from '../models/filter-options.model'; import { SearchOrganizationsFilters } from '../models/search-organizations-filters.model'; @@ -33,9 +33,9 @@ export class ProviderService { if (params.limit !== undefined) { httpParams = httpParams.set('limit', params.limit.toString()); } - + const url = `${this.endpoint}${httpParams.toString() ? '?' + httpParams.toString() : ''}`; - + return this.http.get(url).pipe( map(response => { return Array.isArray(response) ? response : []; @@ -49,11 +49,11 @@ export class ProviderService { getProviderById(id: string): Observable { const targetUrl = `${this.endpoint}/${id}`; - + // Use CORS proxy if calling external DOME API directly const isExternalUrl = targetUrl.startsWith('https://'); const url = isExternalUrl ? `https://api.allorigins.win/get?url=${encodeURIComponent(targetUrl)}` : targetUrl; - + return this.http.get(url).pipe( map(response => { // Parse CORS proxy response if used @@ -68,11 +68,11 @@ export class ProviderService { getProvidersForTender(): Observable { const targetUrl = this.endpoint; - + // Use CORS proxy if calling external DOME API directly const isExternalUrl = targetUrl.startsWith('https://'); const url = isExternalUrl ? `https://api.allorigins.win/get?url=${encodeURIComponent(targetUrl)}` : targetUrl; - + return this.http.get(url).pipe( map(response => { // Parse CORS proxy response if used @@ -86,7 +86,7 @@ export class ProviderService { ); } - + getProvidersForTenderNew(filters: SearchOrganizationsFilters): Observable { const url = environment.searchOrganizationsEndpoint; @@ -102,8 +102,9 @@ export class ProviderService { } //Methods for the search engine + //TODO: Check if this is still necessary after we change the main endpoint getFilterOptions(): Observable { - const base = environment.searchOrganizationsEndpoint.replace(/\/searchOrganizations$/, ''); + const base = environment.searchOrganizationsEndpoint.replace(/\/searchOrganizations.*$/, ''); const categories$ = this.http.get(`${base}/categories`).pipe( map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])), catchError(err => { @@ -111,7 +112,7 @@ export class ProviderService { return of([]); }) ); - + const countries$ = this.http.get(`${base}/countries`).pipe( map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])), catchError(err => { @@ -119,7 +120,7 @@ export class ProviderService { return of([]); }) ); - + const complianceLevels$ = this.http.get(`${base}/complianceLevels`).pipe( map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])), catchError(err => { @@ -127,7 +128,7 @@ export class ProviderService { return of([]); }) ); - + return forkJoin({ categories: categories$, countries: countries$,