import { Injectable } from '@angular/core'; import { Http, RequestOptions } from '@angular/http'; import { Subject } from 'rxjs'; import { BaseService } from './base.service'; @Injectable() export class MapSelectionService extends BaseService{ private baseUrl : string = 'https://api-staging.bancodebogota.co/vivienda'; private cityByCodeURL = this.baseUrl.concat('/mdm/mdmBasicAdminUnit/getCOAdminUnits'); private officesURL = this.baseUrl.concat('/mdm/mdmBusinessInfo/getBDBOfficesByCity'); constructor(private http: Http) { super(); } public getCityByCode(code) { const observable = new Subject(); const options = new RequestOptions({ headers: this.headers }); this.http.get(`${this.cityByCodeURL}?adminUnitId=` + code, options) .subscribe((response: any) => { observable.next(response.json().response.docs[0]); }, error => { if (error.status === 302) { observable.next(JSON.parse(error._body).response.docs[0]); } else { observable.next([]); } }); return observable; } public getOffices(cityCode): Subject { const observable = new Subject(); const options = new RequestOptions({ headers: this.headers }); this.http.get(`${this.officesURL}?cityCode=` + cityCode, options) .subscribe((response: any) => { observable.next(response.json().response.docs); }, error => { if (error.status === 302) { observable.next(JSON.parse(error._body).response.docs); } else { observable.next([]); } }); return observable; } }