Skip to content

Commit 91aae10

Browse files
committed
Adding feches
1 parent cc90ffa commit 91aae10

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

server/database/app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,34 @@ app.get('/fetchReviews/dealer/:id', async (req, res) => {
5959
// Express route to fetch all dealerships
6060
app.get('/fetchDealers', async (req, res) => {
6161
//Write your code here
62+
try {
63+
const documents = await Dealerships.find();
64+
res.json(documents);
65+
} catch (error) {
66+
res.status(500).json({ error: 'Error fetching documents' });
67+
}
6268
});
6369

6470
// Express route to fetch Dealers by a particular state
6571
app.get('/fetchDealers/:state', async (req, res) => {
6672
//Write your code here
73+
try {
74+
const documents = await Dealerships.find({state: req.params.state});
75+
res.json(documents);
76+
} catch (error) {
77+
res.status(500).json({ error: 'Error fetching documents' });
78+
}
6779
});
6880

6981
// Express route to fetch dealer by a particular id
7082
app.get('/fetchDealer/:id', async (req, res) => {
7183
//Write your code here
84+
try {
85+
const documents = await Dealerships.find({id: req.params.id});
86+
res.json(documents);
87+
} catch (error) {
88+
res.status(500).json({ error: 'Error fetching documents' });
89+
}
7290
});
7391

7492
//Express route to insert review

0 commit comments

Comments
 (0)