Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 7x 7x 7x 7x 7x 7x 7x 2x 2x 1x 1x 1x 1x | import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { CountryMapper } from 'ish-core/models/country/country.mapper';
import { Country } from 'ish-core/models/country/country.model';
import { RegionData } from 'ish-core/models/region/region.interface';
import { RegionMapper } from 'ish-core/models/region/region.mapper';
import { Region } from 'ish-core/models/region/region.model';
import { ApiService, unpackEnvelope } from 'ish-core/services/api/api.service';
@Injectable({ providedIn: 'root' })
export class CountryService {
constructor(private apiService: ApiService) {}
private countryHeadersV1 = new HttpHeaders()
.set('content-type', 'application/json')
.set('Accept', 'application/vnd.intershop.country.v1+json');
getCountries(): Observable<Country[]> {
return this.apiService.get(`countries`, { headers: this.countryHeadersV1 }).pipe(
unpackEnvelope('data'),
map(countryItemsData => countryItemsData.map(CountryMapper.fromData))
);
}
getRegionsByCountry(countryCode: string): Observable<Region[]> {
return this.apiService
.get<RegionData>(`countries/${countryCode}/main-divisions`, { headers: this.countryHeadersV1 })
.pipe(
unpackEnvelope<RegionData>('data'),
map(regionData => regionData.map(regionItemData => RegionMapper.fromData(regionItemData, countryCode)))
);
}
}
|