Im trying to use from a external api in nestjs with 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));
}
}
And my service class looks like this:
@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;
}
}
However if i console.log the value "infoPrestacion" this is the result:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
and it doesnt get to the second since it's not resolved yet. Is it possible to wait for the result until it's resolved (i don't have any config for the HttpModule) ? The return actually gets the object itself "infoPrestacion" but i need to work with the values and not return that object.