diff --git a/app/index.js b/app/index.js index 0c790f6..7836400 100644 --- a/app/index.js +++ b/app/index.js @@ -31,10 +31,19 @@ app.route('/item') .put(item.addItem) app.route('/item/:brand') - .get(item.getItemByBrand); + .get(item.getItemByBrand) + +app.route('/item/season/:season') + .get(item.getItemBySeason) + +app.route('/item/color/:color') + .get(item.getItemByColor) app.route('/item/:type') .delete(item.deleteItem) .put(item.updateItem) +app.route('/accessory') + .get(item.getAccessories) + module.exports = app; diff --git a/app/items.js b/app/items.js index c3ec9d5..78e61c3 100644 --- a/app/items.js +++ b/app/items.js @@ -1,4 +1,5 @@ let Item = require('./models/itemSchema') +let Accessory = require('./models/accessorySchema') // Get every single item. HU01 function getItems(req,res){ @@ -22,6 +23,28 @@ async function getItemByBrand(req,res){ } } +//HU06 +async function getItemBySeason(req,res){ + let season = req.params.season + let item = Item.find({season: season}).exec(function(err,item){ + if(!err){ + res.status(200).json(item) + }else{ + res.status(500).send(err) + } + }) +} + +async function getItemByColor(req,res){ + let color = req.params.color + try{ + const items = await Item.find({color: color}) + res.json(items) + }catch(err){ + res.status(500).json({message: err.message }) + } + } + //Delete an item. HU03 function deleteItem(req,res){ let type = req.params.type; @@ -70,6 +93,20 @@ async function updateItem(req,res){ }) } +//Accessory + +//HU05 +function getAccessories(req,res){ + let accessory = Accessory.find({}).exec(function(err,accessory){ + if(!err){ + res.status(200).json(accessory) + }else{ + res.send(err) + } + }) +} + + -module.exports = {getItems,getItemByBrand,addItem,deleteItem,updateItem} +module.exports = {getItems,getItemByBrand,addItem,deleteItem,updateItem, getItemBySeason, getItemByColor,getAccessories}