From 35fcdaae54c92c62e8e39cd4dca70667209558b1 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 26 Oct 2021 13:34:52 -0500 Subject: [PATCH] Implement item delete --- backend/app.js | 13 +++++++++++++ src/app/items/item-list/item-list.component.html | 1 - src/app/items/item-list/item-list.component.ts | 1 + src/app/items/items.service.ts | 10 ++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/backend/app.js b/backend/app.js index 542816d..50ac325 100644 --- a/backend/app.js +++ b/backend/app.js @@ -229,6 +229,19 @@ app.post('/api/item', (req, res, next) => { } }); +app.delete('/api/item/:id', (req, res, next) => { + console.log('delete endpoint', req.params.id); + itemmodel.findByIdAndDelete(req.params.id, function (err, docs) { + if (err) { + console.log(err); + } else { + res.status(200).json({ + message: 'Item deleted' + }); + } + }); +}); + app.get('/api/price', (req, res, next) => { console.log('Get /api/price'); CoinGeckoClient.simple.price({ diff --git a/src/app/items/item-list/item-list.component.html b/src/app/items/item-list/item-list.component.html index 41d79ed..905af38 100644 --- a/src/app/items/item-list/item-list.component.html +++ b/src/app/items/item-list/item-list.component.html @@ -1,4 +1,3 @@ -

Items!

diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index 869983c..2320f35 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -110,6 +110,7 @@ export class ItemListComponent implements OnInit{ dialogRef.afterClosed().subscribe((val) => { if (val != null) { console.log('Deleting', val); + this.itemService.deleteItem(val); } this.itemService.getItems(this.owner.address); }); diff --git a/src/app/items/items.service.ts b/src/app/items/items.service.ts index f1e3ee8..744cdea 100644 --- a/src/app/items/items.service.ts +++ b/src/app/items/items.service.ts @@ -39,4 +39,14 @@ export class ItemService{ return obs; } + + deleteItem(id: string) { + let obs = this.http.delete<{message: string}>('http://localhost:3000/api/item/'+id); + + obs.subscribe((ItemResponse) => { + console.log('Item deleted'); + }); + + return obs; + } }