add edit items

This commit is contained in:
np.w
2020-12-11 18:21:48 -06:00
parent a5dff80d8d
commit f45230b970
4 changed files with 95 additions and 56 deletions
+10 -2
View File
@@ -80,14 +80,22 @@ app.post('/box/:id/item', async (request, response) => {
const updatedBox = await getBox(id);
response.send(updatedBox);
});
//edit item
app.put('/box/:boxId/item/:itemId', async (request, response) => {
const boxID = request.params.boxId;
const itemID = request.params.itemId;
await Box.updateOne({ 'item._id': itemID }, {
$set: { item: request.body }
})
const updatedBox = await getBox(boxID);
response.send(updatedBox);
});
//delete item
app.delete('/box/:boxId/item/:itemId', async (request, response) => {
const boxID = request.params.boxId;
const itemID = request.params.itemId;
await Box.update({ _id: boxID }, { $pull: { item: { _id: itemID } } });
const box = await getBox(boxID);
console.log(box);
response.send(box);
});