All files / src/app/extensions/store-locator/services/stores stores.service.ts

47.36% Statements 9/19
0% Branches 0/6
25% Functions 1/4
47.05% Lines 8/17

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 353x 3x 3x   3x     3x     3x   1x 1x                                          
import { HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
 
import { ApiService, unpackEnvelope } from 'ish-core/services/api/api.service';
 
import { StoreLocationData } from '../../models/store-location/store-location.interface';
import { StoreLocationMapper } from '../../models/store-location/store-location.mapper';
 
@Injectable({ providedIn: 'root' })
export class StoresService {
  constructor(
    private apiService: ApiService,
    private storeLocationMapper: StoreLocationMapper
  ) {}
 
  getStores(countryCode?: string, postalCode?: string, city?: string) {
    let params = new HttpParams();
    if (countryCode) {
      params = params.set('countryCode', countryCode);
    }
    if (postalCode) {
      params = params.set('postalCode', postalCode);
    }
    if (city) {
      params = params.set('city', city);
    }
 
    return this.apiService.get('stores', { params }).pipe(
      unpackEnvelope(),
      map((stores: StoreLocationData[]) => stores.map(store => this.storeLocationMapper.fromData(store)))
    );
  }
}