translations

This commit is contained in:
2025-06-25 13:53:36 +02:00
parent 9407253e69
commit 4fc12ff9bf
12 changed files with 218 additions and 132 deletions

View File

@ -1,6 +1,7 @@
import { NuxtErrorBoundary } from "#components";
import { useMyFetch } from "#imports";
import type {
CartItem,
GenericResponse,
GenericResponseChildren,
GenericResponseItems,
@ -59,10 +60,10 @@ export const useProductStore = defineStore("productStore", () => {
}
}
async function addToCart(product: Product) {
async function incrementCartItem(id: number) {
try {
const { data } = await useMyFetch<GenericResponse<UserCart>>(
`/api/public/user/cart/item/add/${product.id}/1`,
await useMyFetch(
`/api/public/user/cart/item/add/${id}/1`,
{
method: "PUT",
headers: {
@ -73,11 +74,55 @@ export const useProductStore = defineStore("productStore", () => {
},
}
);
getCart();
} catch (error) {
console.error("getList error:", error);
}
}
async function decrementCartItem(id: number) {
try {
await useMyFetch(
`/api/public/user/cart/item/subtract/${id}/1`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
},
}
);
getCart();
} catch (error) {
console.error("removeFromCart error:", error);
}
}
async function deleteCartItem(id: number) {
try {
await useMyFetch(
`/api/public/user/cart/item/${id}`,
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
onErrorOccured: (_, status) => {
throw new Error(`HTTP error: ${status}`);
},
}
);
getCart();
} catch (error) {
console.error("removeFromCart error:", error);
}
}
const cart = ref({} as UserCart);
async function getCart() {
try {
@ -93,10 +138,6 @@ export const useProductStore = defineStore("productStore", () => {
}
);
// if (!res.ok) {
// throw new Error(`HTTP error: ${res.status}`);
// }
cart.value = data;
} catch (error) {
console.error("getList error:", error);
@ -106,9 +147,12 @@ export const useProductStore = defineStore("productStore", () => {
return {
productList,
modules,
cart,
getList,
getModules,
addToCart,
// getCart,
incrementCartItem,
decrementCartItem,
deleteCartItem,
getCart,
};
});