Skip to content

Commit 6cd8f41

Browse files
committed
Refactored code and added middlewares
1 parent bbc7bef commit 6cd8f41

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1-
exports.getAllPlants = (req, res) => {};
1+
exports.checkID = (req, res, next, val) => {
2+
console.log('Hello from the param middleware');
3+
next();
4+
};
25

3-
exports.createPlant = (req, res) => {};
6+
exports.checkBody = (req, res, next) => {
7+
console.log('hello from the checkBody middleWare');
8+
next();
9+
};
410

5-
exports.getPlant = (req, res) => {};
11+
exports.getAllPlants = (req, res) => {
12+
res.send('hello');
13+
};
614

7-
exports.updatePlant = (req, res) => {};
8-
exports.deletePlant = (req, res) => {};
15+
exports.createPlant = (req, res) => {
16+
res.send('hello');
17+
};
18+
19+
exports.getPlant = (req, res) => {
20+
res.send('hello');
21+
};
22+
23+
exports.updatePlant = (req, res) => {
24+
res.send('hello');
25+
};
26+
exports.deletePlant = (req, res) => {
27+
res.send('hello');
28+
};

Backend/routes/plantRoutes.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ const express = require('express');
22
const router = express.Router();
33
const plantController = require('./../controllers/plantController');
44

5-
router.param('id', (req, res, next, val) => {
6-
consolelog(`tour id is ${id}`);
7-
next();
8-
});
5+
router.param('id', plantController.checkID);
96

107
router
118
.route('/')
129
.get(plantController.getAllPlants)
13-
.post(plantController.createPlant);
10+
.post(plantController.checkBody, plantController.createPlant);
1411

1512
router
1613
.route('/:id')

0 commit comments

Comments
 (0)