Estou tentando usar a partir de uma api externa em nestjs com axios.
@Injectable()
export class PIntegration {
constructor(private httpService: HttpService) { }
API = process.env.API || 'http://localhost:3000';
header = { headers: { 'Content-Type': 'application/json' } };
async getPrestacionById(id: string): Promise<Observable<IPrestacion>>{
return this.httpService.get(`${this.API}/prestacion/${id}`, this.header).pipe(map((res) => res.data));
}
}
E a minha classe de serviço parecido com este:
@Injectable()
export class ProductService{
constructor(private pIntegration: PIntegration){}
async producto(id: string) {
const infoPrestacion = await this.pIntegration.getPrestacionById(id);
console.log({ infoPrestacion })
if (infoPrestacion)
{
if (infoPrestacion.detalles) {
console.log(infoPrestacion.detalles)
console.log("tiene detalles")
}
}
return infoPrestacion;
}
}
No entanto, se eu consola.registrar o valor "infoPrestacion" este é o resultado:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
e ele não chegar ao segundo, pois não está resolvido ainda. É possível aguardar o resultado até que seja resolvido (eu não tenho nenhuma configuração para o HttpModule) ? O retorno realmente é o objeto em si "infoPrestacion" mas eu preciso trabalhar com os valores e não devolver o objeto.