Skip to content

Commit

Permalink
añado funciones para #27 #38
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelfdez99 committed Jan 15, 2021
1 parent f20e0a8 commit 1e8725b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
39 changes: 38 additions & 1 deletion app/items.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let Item = require('./models/itemSchema')
let Accessory = require('./models/accessorySchema')

// Get every single item. HU01
function getItems(req,res){
Expand All @@ -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;
Expand Down Expand Up @@ -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}

0 comments on commit 1e8725b

Please sign in to comment.