Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/app/services/provider.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<Provider[]>(url).pipe(
map(response => {
return Array.isArray(response) ? response : [];
Expand All @@ -49,11 +49,11 @@ export class ProviderService {

getProviderById(id: string): Observable<Provider> {
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<any>(url).pipe(
map(response => {
// Parse CORS proxy response if used
Expand All @@ -68,11 +68,11 @@ export class ProviderService {

getProvidersForTender(): Observable<Provider[]> {
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<any>(url).pipe(
map(response => {
// Parse CORS proxy response if used
Expand All @@ -86,7 +86,7 @@ export class ProviderService {
);
}


getProvidersForTenderNew(filters: SearchOrganizationsFilters): Observable<Provider[]> {
const url = environment.searchOrganizationsEndpoint;

Expand All @@ -102,32 +102,33 @@ export class ProviderService {
}

//Methods for the search engine
//TODO: Check if this is still necessary after we change the main endpoint
getFilterOptions(): Observable<FilterOptions> {
const base = environment.searchOrganizationsEndpoint.replace(/\/searchOrganizations$/, '');
const base = environment.searchOrganizationsEndpoint.replace(/\/searchOrganizations.*$/, '');
const categories$ = this.http.get<any>(`${base}/categories`).pipe(
map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])),
catchError(err => {
console.warn('Categories API failed:', err);
return of<string[]>([]);
})
);

const countries$ = this.http.get<any>(`${base}/countries`).pipe(
map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])),
catchError(err => {
console.warn('Countries API failed:', err);
return of<string[]>([]);
})
);

const complianceLevels$ = this.http.get<any>(`${base}/complianceLevels`).pipe(
map(res => (Array.isArray(res) ? res : Array.isArray(res?.data) ? res.data : [])),
catchError(err => {
console.warn('ComplianceLevels API failed:', err);
return of<string[]>([]);
})
);

return forkJoin({
categories: categories$,
countries: countries$,
Expand Down
Loading