Skip to content

Commit

Permalink
fixed item controller creating items instead of editing
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefkarim committed Sep 19, 2023
1 parent 34d4116 commit e6f57a4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions controllers/itemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.edit_get_api = asyncHandler(async(req,res,next)=>{
const collections = await collectionModel.find({})
if(req.params.id){
let item = await itemModel.findById({_id: req.params.id});
res.send({title:'item',item:item,collections:collections,})
return res.send({title:'item',item:item,collections:collections})
}
res.send({title:'item',collections:collections,})

Expand Down Expand Up @@ -179,7 +179,7 @@ exports.edit_post_api = [

} else{

if (!req.body.id) {
if (!req.params.id) {
// setting collection
let categoryId=await collectionModel.find({name:req.body.category},{_id:1})
categoryId=categoryId[0]['_id']
Expand All @@ -195,8 +195,7 @@ exports.edit_post_api = [
category:categoryId,
src:src});
await item.save()

res.send({url:item.url})
return res.send({url:item.url})
}
const itemExists = await itemModel.find({name: req.body.name}).exec()

Expand All @@ -218,7 +217,7 @@ exports.edit_post_api = [
src:src},
{ new: true } // This option returns the modified document
).exec();
res.send({url:item.url})
return res.send({url:item.url})
}
}

Expand Down
Binary file added uploads/2014-09-04_Addis_Look_11_35.webp
Binary file not shown.
Binary file added uploads/h7jduwfvblnmj0ktavuz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6f57a4

Please sign in to comment.