delete list
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
PORT=3010
|
||||||
|
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
SESSION_SECRET=MijnSuperGeheimeSleutel123!
|
||||||
|
|
||||||
|
DATABASE=database.sqlite
|
||||||
|
|
||||||
|
OPENAI_API_KEY=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
|
||||||
|
|
||||||
|
OPENAI_MODEL=gpt-5.4-mini
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.env
|
|
||||||
database.sqlite
|
|
||||||
database.sqlite-shm
|
database.sqlite-shm
|
||||||
database.sqlite-wal
|
database.sqlite-wal
|
||||||
tmp-delete-test.sqlite
|
tmp-delete-test.sqlite
|
||||||
|
|||||||
@@ -72,6 +72,17 @@ class ShoppingListController {
|
|||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteList(req, res) {
|
||||||
|
const list = ShoppingListRepository.findById(req.params.id, req.user.household_id);
|
||||||
|
if (!list) return res.status(404).json({ error: "Lijst niet gevonden" });
|
||||||
|
|
||||||
|
const result = ShoppingListRepository.deleteList(list.id);
|
||||||
|
if (result.changes === 0) return res.status(404).json({ error: "Lijst niet gevonden" });
|
||||||
|
|
||||||
|
this.broadcastUpdate(req, list.id);
|
||||||
|
res.json({ success: true });
|
||||||
|
}
|
||||||
|
|
||||||
broadcastUpdate(req, listId) {
|
broadcastUpdate(req, listId) {
|
||||||
if (req.app.locals.io) {
|
if (req.app.locals.io) {
|
||||||
req.app.locals.io.to(`list:${listId}`).emit("list:updated", { listId });
|
req.app.locals.io.to(`list:${listId}`).emit("list:updated", { listId });
|
||||||
|
|||||||
Binary file not shown.
@@ -77,6 +77,14 @@ class ShoppingListRepository {
|
|||||||
DELETE FROM shopping_list_items WHERE id = ? AND list_id = ?
|
DELETE FROM shopping_list_items WHERE id = ? AND list_id = ?
|
||||||
`).run(itemId, listId);
|
`).run(itemId, listId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteList(listId) {
|
||||||
|
db.prepare(`
|
||||||
|
DELETE FROM shopping_list_items WHERE list_id = ?
|
||||||
|
`).run(listId);
|
||||||
|
return db.prepare(`DELETE FROM shopping_lists WHERE id = ?
|
||||||
|
`).run(listId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new ShoppingListRepository();
|
module.exports = new ShoppingListRepository();
|
||||||
|
|||||||
@@ -179,4 +179,11 @@ router.delete(
|
|||||||
ShoppingListController.deleteItem.bind(ShoppingListController)
|
ShoppingListController.deleteItem.bind(ShoppingListController)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.delete(
|
||||||
|
"/lists/:id",
|
||||||
|
auth,
|
||||||
|
ShoppingListController.deleteList.bind(ShoppingListController)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Binary file not shown.
+52
-3
@@ -4,14 +4,18 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="card">
|
|
||||||
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<% if (lists.length === 0) { %>
|
<% if (lists.length === 0) { %>
|
||||||
<p class="text-secondary">Je hebt nog geen boodschappenlijsten.</p>
|
<p class="text-secondary">Je hebt nog geen boodschappenlijsten.</p>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<% lists.forEach(list => { %>
|
<% lists.forEach(list => { %>
|
||||||
<a href="/lists/<%= list.id %>" class="list-group-item list-group-item-action">
|
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
|
||||||
|
<!-- Link + info -->
|
||||||
|
<a href="/lists/<%= list.id %>" class="flex-grow-1 text-decoration-none">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<strong><%= list.name %></strong>
|
<strong><%= list.name %></strong>
|
||||||
<span><%= list.checked_count || 0 %>/<%= list.item_count || 0 %> gedaan</span>
|
<span><%= list.checked_count || 0 %>/<%= list.item_count || 0 %> gedaan</span>
|
||||||
@@ -20,11 +24,25 @@
|
|||||||
Aangemaakt <%= new Date(list.created_at).toLocaleDateString("nl-NL") %>
|
Aangemaakt <%= new Date(list.created_at).toLocaleDateString("nl-NL") %>
|
||||||
</small>
|
</small>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<!-- Delete button -->
|
||||||
|
<button class="btn btn-sm btn-danger ms-3 delete-list-button"
|
||||||
|
type="button"
|
||||||
|
data-list-id="<%= list.id %>"
|
||||||
|
aria-label="Lijst <%= list.name %> verwijderen">
|
||||||
|
🗑️
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -40,3 +58,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll(".delete-list-button").forEach((button) => {
|
||||||
|
button.addEventListener("click", async () => {
|
||||||
|
const listId = button.dataset.listId;
|
||||||
|
const listName = button.closest(".list-group-item")?.querySelector("strong")?.textContent?.trim() || "deze lijst";
|
||||||
|
|
||||||
|
if (!confirm(`"${listName}" verwijderen?`)) return;
|
||||||
|
|
||||||
|
const response = await fetch(`/lists/${listId}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: { Accept: "application/json" }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
window.location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = "Lijst kon niet worden verwijderd.";
|
||||||
|
try {
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.error) message = data.error;
|
||||||
|
} catch (_) {
|
||||||
|
// ignore json parse errors
|
||||||
|
}
|
||||||
|
|
||||||
|
alert(message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user