Implement item delete
This commit is contained in:
parent
61d68714d2
commit
35fcdaae54
4 changed files with 24 additions and 1 deletions
|
@ -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({
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<h1>Items!</h1>
|
||||
<div *ngIf="items.length > 0">
|
||||
<div class="card" *ngFor="let item of itemsUpdate | async">
|
||||
<mat-card>
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue