-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.js
executable file
·33 lines (26 loc) · 1017 Bytes
/
weather.js
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
const express = require("express");
const bodyParser = require('body-parser');
const router = express.Router();
const connection = require("../config/database")
const {getWeatherFromId, getWeathers, getLastWeatherMean, getDayWeatherMean, createWeather} = require("../services/weatherService");
router.get("/", async (req, res, next) => {
router.use(express.json());
res.json(await getWeathers());
})
router.get("/lastMean", async (req, res) => {
router.use(express.json());
res.json(await getLastWeatherMean());
})
router.get("/dayMean/:dayMinus", async (req, res) => {
router.use(express.json());
res.json(await getDayWeatherMean(req.params.dayMinus));
})
router.get("/:id", async (req, res) => {
router.use(express.json());
res.json(await getWeatherFromId(req.params.id));
})
router.post("/", async (req, res) => {
const newWeather = req.body;
res.json(await createWeather(newWeather.temp, newWeather.humidity, newWeather.station_id));
})
module.exports = router;