import * as fetch from 'node-fetch' ; import { IOCContainer } from '../../common/config/ioc_config' ; import SERVICE_IDENTIFIER from '../../common/constants/identifiers' ; import { timeout } from 'rxjs/operators' ; import IStarwars from '../../api/interfaces/istarwars' ; const container = IOCContainer . getInstance ( ) . getContainer ( ) ; const StarwarsService = container . get < IStarwars > ( SERVICE_IDENTIFIER . STARWARS ) ; param id export const fetchPeopleWithPlanet = id => { return new Promise ( ( resolve , reject ) => { StarwarsService . getPeopleById ( id ) . pipe ( timeout ( + process . env . API_TIME_OUT ) ) . subscribe ( ( r ) => { resolve ( r ) ; } , error => { reject ( error ) ; } ) ; } ) ; } ; param id export const fetchPeople = id => { const URI = `${ process . env . SWAPI_BASE_URL }/people/` + id ; return fetch ( URI ) . then ( res => res . json ( ) ) ; } ; param id export const fetchPlanet = id => { const URI = `${ process . env . SWAPI_BASE_URL }/planets/` + id ; return fetch ( URI ) . then ( res => res . json ( ) ) ; } ; param id export const fetchStarship = id => { const URI = `${ process . env . SWAPI_BASE_URL }/starships/` + id ; return fetch ( URI ) . then ( res => res . json ( ) ) ; } ;