-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (36 loc) · 961 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
29
30
31
32
33
34
35
36
37
const express = require("express");
const bodyParser = require("body-parser");
const store = require("./store");
const app = express();
const Winner = require("./models/Winner");
app.use(express.static("public"));
app.use(bodyParser.json());
app.get("/api/winners", (req, res) => {
Winner.query().then(winners => {
res.json(winners);
});
});
app.get("/api/winners/:a", (req, res) => {
Winner.query().then(winners => {
const results = res.json(winners);
return results;
});
});
app.post("/addWinner", (req, res) => {
store
.addWinner({
city: req.body.city,
edition: req.body.edition,
category: req.body.category,
sport: req.body.sport,
athlete: req.body.athlete,
noc: req.body.noc,
gender: req.body.gender,
event: req.body.event,
medal: req.body.medal
})
.then(() => res.sendStatus(200));
});
app.listen(3000, () => {
console.log(`Server running on localhost:3000`);
});