-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 895 Bytes
/
server.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 app = express()
const config = require('./config')
const PetrolStation = require('./models/PetrolStation')
app.use(express.static('public'))
app.get('/api/stations/all', (req, res) => {
PetrolStation.getAllStation().then((data) => {
res.status(200).json(data)
})
})
app.get('/api/stations/random', (req, res) => {
PetrolStation.getOneByRandom().then((data) => {
res.status(200).json(data)
})
})
app.get('/api/stats', (req, res) => {
PetrolStation.getStats().then(({ count, totalStations }) => {
res.status(200).json({ totalByOwner: count, total: totalStations })
})
})
app.get('/api/stations/nearest', (req, res) => {
const { lat, lng, radius } = req.query
PetrolStation.getNearestStation(lat, lng, radius).then((data) => {
res.status(200).json(data)
})
})
app.listen(config.port)