Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/app/models/filter-options.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface FilterOptions {
categories: string[];
countries: string[];
complianceLevels: string[];
}
37 changes: 37 additions & 0 deletions src/app/models/search-organizations-filters.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export interface SearchOrganizationsFilters {
categories: string[];
countries: string[];
complianceLevels: string[];
}

const regionNames = new Intl.DisplayNames(['en'], { type: 'region' });

const codeAliases: Record<string, string> = {
EL: 'GR', // Greece
UK: 'GB', // United Kingdom
};

export function countryName(code: string | null | undefined): string {
if( code?.length !== 2 ) return code ?? '';
if (!code) return '';
const upper = code.toUpperCase();
const normalized = codeAliases?.[upper] ?? upper;
return regionNames.of(normalized) ?? upper;
}

export function complianceLevelsName(code: string | null | undefined): string {
if (!code) return '';

const upper = code.toUpperCase();

const map: Record<string, string> = {
'BL': 'Baseline',
'P': 'Professional',
'P+': 'Professional+',
};

return map[upper] ?? upper;
}



60 changes: 56 additions & 4 deletions src/app/services/provider.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, map, catchError, of } from 'rxjs';
import { Observable, map, catchError, of, forkJoin } from 'rxjs';
import { environment } from '../../environments/environment';
import { FilterOptions } from '../models/filter-options.model';
import { SearchOrganizationsFilters } from '../models/search-organizations-filters.model';

export interface Provider {
id?: string;
Expand All @@ -18,9 +20,7 @@ export interface Provider {
})
export class ProviderService {
private http = inject(HttpClient);
private readonly endpoint = `${environment.BASE_URL}/party/v4/organization`;
//TODO FOR DEV ONLY
//private readonly endpoint = `${environment.BASE_URL}/party/organization`;
private readonly endpoint = `${environment.BASE_URL}/party/organization`;

getProviders(params: { fields?: string; offset?: number; limit?: number } = {}): Observable<Provider[]> {
let httpParams = new HttpParams();
Expand Down Expand Up @@ -85,5 +85,57 @@ export class ProviderService {
})
);
}


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

return this.http.post<any>(url, filters).pipe(
map((response) => {
if (Array.isArray(response)) return response as Provider[];
if (response?.data && Array.isArray(response.data)) return response.data as Provider[];
return [];
}),
catchError((error) => {
console.warn('Providers for tender (new) API failed:', error);
return of([]);
})
);
}

//Methods for the search engine
getFilterOptions(): Observable<FilterOptions> {
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$,
complianceLevels: complianceLevels$,
});
}

}

Loading
Loading