fix: utilize WEATHER_API_URL in WeatherService for dynamic API endpoint

This commit is contained in:
faris Aljohari
2025-06-04 01:32:01 -06:00
parent ea021ad228
commit 43dfaaa90d
2 changed files with 6 additions and 2 deletions
+5 -2
View File
@@ -9,10 +9,13 @@ import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
@Injectable()
export class WeatherService {
private readonly weatherApiUrl: string;
constructor(
private readonly configService: ConfigService,
private readonly httpService: HttpService,
) {}
) {
this.weatherApiUrl = this.configService.get<string>('WEATHER_API_URL');
}
async fetchWeatherDetails(
query: GetWeatherDetailsDto,
@@ -22,7 +25,7 @@ export class WeatherService {
const weatherApiKey = this.configService.get<string>(
'OPEN_WEATHER_MAP_API_KEY',
);
const url = `http://api.weatherapi.com/v1/current.json?key=${weatherApiKey}&q=${lat},${lon}&aqi=yes`;
const url = `${this.weatherApiUrl}/current.json?key=${weatherApiKey}&q=${lat},${lon}&aqi=yes`;
const response = await firstValueFrom(this.httpService.get(url));
const pm2_5 = response.data.current.air_quality.pm2_5; // Raw PM2.5 (µg/m³)