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

44.44% Statements 8/18
54.54% Branches 6/11
25% Functions 1/4
43.75% Lines 7/16

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 323x 3x 3x   3x     3x     3x 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();
    Iif (countryCode) {
      params = params.set('countryCode', countryCode);
    }
    Iif (postalCode) {
      params = params.set('postalCode', postalCode);
    }
    Iif (city) {
      params = params.set('city', city);
    }
 
    return this.apiService.get('stores', { params }).pipe(
      unpackEnvelope(),
      map((stores: StoreLocationData[]) => stores.map(store => this.storeLocationMapper.fromData(store)))
    );
  }
}