-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-api.js
More file actions
29 lines (25 loc) · 778 Bytes
/
Copy pathserver-api.js
File metadata and controls
29 lines (25 loc) · 778 Bytes
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
module.exports = function(app) {
const Spot = require("./models/Spot");
app.get("/api/spots", (req, res) => {
Spot.find()
.then(spots => res.json(spots))
.catch(err => res.json(err));
});
app.post("/api/spots", (req, res) => {
Spot.create(req.body)
.then(spots => res.json(spots))
.catch(err => res.json(err));
});
app.delete("/api/spots/:id", (req, res) => {
const { id } = req.params;
Spot.findByIdAndRemove(id)
.then(spots => res.json({ success: true }))
.catch(err => res.json(err));
});
app.patch("/api/spots/:id", (req, res) => {
const { id } = req.params;
Spot.findByIdAndUpdate(id, req.body, { new: true })
.then(spots => res.json(spots))
.catch(err => res.json(err));
});
};