-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 958 Bytes
/
index.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
var app = require('express')();
var srv = require('http').createServer(app);
var api = require('./api');
app.get('/api/districts', (req, res) => {
if (req.query.search) {
let search = req.query.search.replace('_', ' ');
api.districtsBySearch(search, (err, districts) => err ? res.json(err) : res.json(districts));
} else if (req.query.state) {
let state = req.query.state;
api.districtsByState(state, (err, districts) => err ? res.json(err) : res.json(districts));
} else {
api.allDistricts((err, districts) => err ? res.json(err) : res.json(districts));
}
})
app.get('/api/schools', (req, res) => {
if (!req.query.districtId) {
api.allSchools((err, schools) => err ? res.json(err) : res.json(schools))
} else {
let {districtId} = req.query;
api.schoolsBySearch(districtId, (err, schools) => err ? res.json(err) : res.json(schools));
}
})
app.listen(3000, function () {
console.log('Listening on 3000');
});