Estoy tratando de uso de una api externa en nestjs con 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));
}
}
Y mi clase de servicio se parece a esto:
@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;
}
}
Sin embargo, si yo consola.registrar el valor de "infoPrestacion" este es el resultado:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
y no llegar a la segunda, ya que no se ha resuelto todavía. Es posible esperar el resultado hasta que sea resuelto (yo no tengo ningún tipo de configuración para el HttpModule) ? El retorno de hecho se pone el objeto en sí mismo "infoPrestacion" pero necesito trabajar con los valores y no volver a ese objeto.