Im snaží používat z externího rozhraní api v nestjs s 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));
}
}
A moje služby třídy vypadá takto:
@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;
}
}
Nicméně, pokud mám konzoli.protokolu hodnota "infoPrestacion" toto je výsledek:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
a to doesnt dostat na druhý, protože to není vyřešen dosud. Je možné čekat na výsledek, dokud není vyřešen (nemám config pro Modul) ? Návrat skutečně dostane samotný objekt "infoPrestacion" ale musím pracovat s hodnotami a ne vrátit objektu.