import {
  Controller,
  UseInterceptors,
  CacheInterceptor,
  Get,
  HttpService,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { AxiosResponse } from 'axios';
import { map, flatMap, catchError } from 'rxjs/operators';
import { ConfigService } from '@nestjs/config';

@Controller('home1')
export class HomeController {
  private readonly URL: string = this.configService.get<string>('URL');

  // URL: string = 'http://dvora.flycommunications.com/wp-json/wp/v2/';
  // staging: string = 'https://cms.dvoralife.com/wp-json/wp/v2/';
  // staging: string = 'http://dvora.flycommunications.com/wp-json/wp/v2/';

  constructor(
    private readonly httpService: HttpService,
    private readonly configService: ConfigService,
  ) {}
  @Get()
  getHome(): Observable<AxiosResponse> {
    const url = `${this.URL}dvora_home_page/?_fields=title,acf`;
    const home = this.httpService.get(url).pipe(map(response => response.data));
    return home;
  }
}
