Created
March 3, 2018 16:51
-
-
Save jaouadballat/560f1abf131a8eb1fe3838662bf76148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const router = express.Router(); | |
const Category = require('../models/Category'); | |
const Product = require('../models/Product'); | |
router.get('/', function (req, res, next) { | |
Category.find(function (err, categories) { | |
if (err) return console.log(err); | |
res.status(200).json(categories); | |
}); | |
}); | |
//display all products in a specific Category | |
router.get('/:category', function (req, res, next) { | |
Category.findOne({title: req.params.category}, function (err, category) { | |
if (err) return console.log(err); | |
Product.find({category: category.title}, function(err, products) { | |
if(err) return console.log(err); | |
res.status(200).json(products); | |
}); | |
}); | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment