Implement item delete

This commit is contained in:
Rene Vergara 2021-10-26 13:34:52 -05:00
parent 61d68714d2
commit 35fcdaae54
4 changed files with 24 additions and 1 deletions

View file

@ -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) => { app.get('/api/price', (req, res, next) => {
console.log('Get /api/price'); console.log('Get /api/price');
CoinGeckoClient.simple.price({ CoinGeckoClient.simple.price({

View file

@ -1,4 +1,3 @@
<h1>Items!</h1>
<div *ngIf="items.length > 0"> <div *ngIf="items.length > 0">
<div class="card" *ngFor="let item of itemsUpdate | async"> <div class="card" *ngFor="let item of itemsUpdate | async">
<mat-card> <mat-card>

View file

@ -110,6 +110,7 @@ export class ItemListComponent implements OnInit{
dialogRef.afterClosed().subscribe((val) => { dialogRef.afterClosed().subscribe((val) => {
if (val != null) { if (val != null) {
console.log('Deleting', val); console.log('Deleting', val);
this.itemService.deleteItem(val);
} }
this.itemService.getItems(this.owner.address); this.itemService.getItems(this.owner.address);
}); });

View file

@ -39,4 +39,14 @@ export class ItemService{
return obs; 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;
}
} }