diff --git a/pages/Items/Create.vue b/pages/Items/Create.vue index d714fda..1dec32f 100644 --- a/pages/Items/Create.vue +++ b/pages/Items/Create.vue @@ -84,8 +84,9 @@ const handleSubmit = async () => { price: formData.value.price, }, }); - if (error.value) { + if(error.value) { console.error("Error creating item:", error); + return; } navigateTo("/items"); }; diff --git a/pages/Items/Edit/[id].vue b/pages/Items/Edit/[id].vue index 3d3971c..dc20347 100644 --- a/pages/Items/Edit/[id].vue +++ b/pages/Items/Edit/[id].vue @@ -87,6 +87,7 @@ const handleSubmit = async () => { }); if (error.value) { console.error("Error updating item:", error); + return; } navigateTo("/items"); }; diff --git a/pages/Items/index.vue b/pages/Items/index.vue index 809042a..9da568a 100644 --- a/pages/Items/index.vue +++ b/pages/Items/index.vue @@ -48,11 +48,13 @@ const { data: items, refresh: refreshItems } = await useFetch("/api/Items"); const handleDelete = async (itemId) => { - const {data, error} = await fetch(`/api/Items/${itemId}`, { + const {data, error} = await useFetch(`/api/Items/${itemId}`, { method: "DELETE", }); - if (error.value) { + console.log(error) + if (error && error.value) { console.error("Error deleting item:", error); + return; } // Trigger re-fetch after deletion refreshItems(); diff --git a/pages/Sales/index.vue b/pages/Sales/index.vue index f0f581d..694b77c 100644 --- a/pages/Sales/index.vue +++ b/pages/Sales/index.vue @@ -88,15 +88,15 @@ if (items) { } const handleDelete = async (saleId) => { - try { - await fetch(`/api/Sales/${saleId}`, { + const { data, error } = await fetch(`/api/Sales/${saleId}`, { method: "DELETE", }); + if(error && error.value) { + console.error("Error deleting sale:", error); + return; + } // Trigger re-fetch after deletion refreshSales(); - } catch (error) { - console.error("Error deleting sale:", error); - } }; const calculateRevenueForItem = (item, quantity) => { diff --git a/pages/index.vue b/pages/index.vue index c427f96..f5539ce 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -54,28 +54,8 @@