mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
fix: utilize WEATHER_API_URL in WeatherService for dynamic API endpoint
This commit is contained in:
@ -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,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -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³)
|
||||||
|
Reference in New Issue
Block a user