Skip to content

Commit 85ee72e

Browse files
committed
GET /expenses
1 parent 42e30dc commit 85ee72e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tripcost/server.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ app.get('/trips', (req, res) => {
5252
app.post('/expense', (req, res) => {
5353

5454
expenses.insertOne(
55-
5655
{ trip: req.body.trip,
5756
date: req.body.date,
5857
amount: req.body.amount,
@@ -65,12 +64,21 @@ app.post('/expense', (req, res) => {
6564
res.status(500).json({ err: err });
6665
return;
6766
}
68-
6967
res.status(200).json({ ok: true });
7068
});
7169
});
7270

73-
app.get('/expenses', (req, res) => { /* */ });
71+
app.get('/expenses', (req, res) => {
72+
73+
expenses.find({trip: req.body.trip}).toArray( (err, items) => {
74+
if (err) {
75+
console.error(err);
76+
res.status(500).json({ err: err });
77+
return;
78+
}
79+
res.status(200).json({ trips: items });
80+
});
81+
});
7482

7583
///////////////////////////////////
7684

0 commit comments

Comments
 (0)