Skip to content

Commit 68b8c72

Browse files
committed
quick fetching api for featured products for added
1 parent b1e856c commit 68b8c72

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Backend/controllers/plantController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
const { Tour } = require('@mui/icons-material');
22
const Plant = require('./../model/plantModel');
33

4+
exports.aliasFeaturedProducts = (req, res, next) => {
5+
req.query.limit = '8';
6+
req.query.sort = '-ratingsAverage,price';
7+
req.query.fields = 'name,price,imageCover';
8+
next();
9+
};
10+
411
exports.getAllPlants = async (req, res) => {
512
try {
613
// console.log(req.query);

Backend/routes/plantRoutes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const plantController = require('./../controllers/plantController');
44

55
// router.param('id', plantController.checkID);
66

7+
router
8+
.route('/featured-products')
9+
.get(plantController.aliasFeaturedProducts, plantController.getAllPlants);
10+
711
router
812
.route('/')
913
.get(plantController.getAllPlants)

0 commit comments

Comments
 (0)