add edit items
This commit is contained in:
+10
-2
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user