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

View File

@ -4,5 +4,6 @@ export default registerAs(
'openweather-config', 'openweather-config',
(): Record<string, any> => ({ (): Record<string, any> => ({
OPEN_WEATHER_MAP_API_KEY: process.env.OPEN_WEATHER_MAP_API_KEY, OPEN_WEATHER_MAP_API_KEY: process.env.OPEN_WEATHER_MAP_API_KEY,
WEATHER_API_URL: process.env.WEATHER_API_URL,
}), }),
); );

View File

@ -9,10 +9,13 @@ import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
@Injectable() @Injectable()
export class WeatherService { export class WeatherService {
private readonly weatherApiUrl: string;
constructor( constructor(
private readonly configService: ConfigService, private readonly configService: ConfigService,
private readonly httpService: HttpService, private readonly httpService: HttpService,
) {} ) {
this.weatherApiUrl = this.configService.get<string>('WEATHER_API_URL');
}
async fetchWeatherDetails( async fetchWeatherDetails(
query: GetWeatherDetailsDto, query: GetWeatherDetailsDto,
@ -22,7 +25,7 @@ export class WeatherService {
const weatherApiKey = this.configService.get<string>( const weatherApiKey = this.configService.get<string>(
'OPEN_WEATHER_MAP_API_KEY', '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 response = await firstValueFrom(this.httpService.get(url));
const pm2_5 = response.data.current.air_quality.pm2_5; // Raw PM2.5 (µg/m³) const pm2_5 = response.data.current.air_quality.pm2_5; // Raw PM2.5 (µg/m³)