import { HttpService , Injectable } from '@nestjs/common' ; import { CityDTO } from '../dto/city.dto' ; @ Injectable ( ) export class CityService { constructor ( private http ) { } public async getCitiesByUf ( uf ) { const response = await this . http . get ( `http://educacao.dadosabertosbr.com/api/cidades/${ uf . toLowerCase ( ) }` ) . toPromise ( ) ; const body = response . data ; let mappedBody = [ ] ; for ( const city of body ) { const [ id , name ] = city . split ( ':' ) ; mappedBody = [ ... mappedBody , { id , name } ] ; } return mappedBody ; } }