Я пытаюсь использовать внешний api в nestjs с 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));
}
}
И мой класс обслуживания выглядит так:
@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;
}
}
Однако, если я утешу.введите значение "infoPrestacion", это результат:
{
infoPrestacion: Observable {
source: Observable { _subscribe: [Function (anonymous)] },
operator: [Function (anonymous)]
}
}
и это не доходит до второго, так как оно еще не решено. Можно ли дождаться результата, пока он не будет разрешен (у меня нет конфигурации для HttpModule) ? Возврат фактически возвращает сам объект "infoPrestacion", но мне нужно работать со значениями, а не возвращать этот объект.