weather.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const axios = require("axios").default;
const getWeather = async (user) => {
if (!user) {
return;
}
try {
const response = await axios.post("http://localhost:8080/api/weather");
const data = response.data;
const formattedData = {
meta: {
country: data.sys.country,
city: data.name,
timezone: data.timezone / 60 / 60,
sunrise: data.sys.sunrise,
sunset: data.sys.sunset,
},
description: data.weather[0].description,
temp: {
realCelcius: (data.main.temp - 273.15).toFixed(2),
feelCelcius: (data.main.feels_like - 273.15).toFixed(2),
realFer: ((data.main.temp - 273.15) * 9) / 5 + 32,
feelFer: ((data.main.feels_like - 273.15) * 9) / 5 + 32,
},
types: {
wind: data.wind.speed,
clouds: data.clouds.all,
rain: data.rain ? data.rain : null,
snow: data.snow ? data.snow : null,
},
};
return formattedData;
} catch (err) {
console.log(err);
}
};
const getForecaset = async () => {
return;
};
const getAirPollution = async () => {
return;
};
const weatherService = {
getWeather,
getForecaset,
getAirPollution,
};
export default weatherService;