@@ -167,7 +168,7 @@
diff --git a/stores/productStore.ts b/stores/productStore.ts
index b8c5e9a..6b9df6f 100644
--- a/stores/productStore.ts
+++ b/stores/productStore.ts
@@ -1,30 +1,31 @@
import { NuxtErrorBoundary } from "#components";
import { useMyFetch } from "#imports";
-import type { GenericResponse, UserCart } from "~/types";
+import type { GenericResponse, GenericResponseItems, UserCart } from "~/types";
+import type { Product } from "~/types/product";
export const useProductStore = defineStore("productStore", () => {
- const productList = ref();
+ const productList = ref
();
const modules = ref();
async function getList(count: number, categoryId = 1) {
try {
- const {data} = await useMyFetch>(
+ const { data } = await useMyFetch>(
`/api/public/products/category/${categoryId}?p=1&elems=${count}`,
{
headers: {
"Content-Type": "application/json",
},
- onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
+ onErrorOccured: async (_, status) => {
+ // await navigateTo("/error", { replace: true });
+ throw createError({
+ statusCode: status,
+ statusMessage: `HTTP error: ${status}`,
+ });
+ },
}
);
-console.log(data);
- // if (!res.ok) {
- // throw new Error(`HTTP error: ${res.status}`);
- // }
-
- // const data = await res.json();
- // productList.value = data.data.items;
+ productList.value = data.items;
} catch (error) {
console.error("getList error:", error);
}
@@ -55,7 +56,7 @@ console.log(data);
}
}
- async function addToCart(product) {
+ async function addToCart(product: Product) {
try {
const res = await fetch(
`http://127.0.0.1:4000/api/public/user/cart/item/add/${product.id}/1`,
@@ -81,12 +82,17 @@ console.log(data);
const cart = ref({} as UserCart);
async function getCart() {
try {
- const {data} = await useMyFetch>(`/api/public/user/cart`, {
- headers: {
- "Content-Type": "application/json",
- },
- onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
- });
+ const { data } = await useMyFetch>(
+ `/api/public/user/cart`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ },
+ onErrorOccured: (_, status) => {
+ throw new Error(`HTTP error: ${status}`);
+ },
+ }
+ );
// if (!res.ok) {
// throw new Error(`HTTP error: ${res.status}`);
diff --git a/types/index.ts b/types/index.ts
index 67e8c37..f834108 100644
--- a/types/index.ts
+++ b/types/index.ts
@@ -44,7 +44,7 @@ export interface PBFooterItem {
}>;
data: Array<{
title: string;
- items: Array
+ items: Array;
}>;
company_info: Array<{
data: string;
@@ -71,7 +71,6 @@ export interface PBPageItem {
section_name: string;
}
-
export interface SectionLangData {
title: string;
description: string;
@@ -111,13 +110,13 @@ export type Countries = {
currency_iso_code: string;
iso_code: string;
name: string;
-}
+};
export type PartnersList = {
country_iso: string;
country_name: string;
total: number;
-}
+};
export type Currencies = {
iso_code: string;
@@ -128,78 +127,88 @@ export type Currencies = {
sign: string;
active: boolean;
suffix: boolean;
-}
+};
export type FeatureValue = {
- parent: number,
- products_with_value: number,
- value: string,
- value_id: number,
-}
+ parent: number;
+ products_with_value: number;
+ value: string;
+ value_id: number;
+};
export type Feature = {
- feature: string,
- feature_id: number,
- feature_values: FeatureValue[],
- products_with_feature: number,
-}
+ feature: string;
+ feature_id: number;
+ feature_values: FeatureValue[];
+ products_with_feature: number;
+};
export type ProductType = {
- applied_tax_rate: number,
- cover_picture_uuid: string,
- description: string,
- formatted_price: string,
- id: number,
- in_stock: number,
- is_sale_active: boolean,
- link_rewrite: string,
- name: string,
- price: number,
- tax_name: string,
- cart_item_id?: number
- product_id?: number
-}
-
+ applied_tax_rate: number;
+ cover_picture_uuid: string;
+ description: string;
+ formatted_price: string;
+ id: number;
+ in_stock: number;
+ is_sale_active: boolean;
+ link_rewrite: string;
+ name: string;
+ price: number;
+ tax_name: string;
+ cart_item_id?: number;
+ product_id?: number;
+};
export interface Country {
- iso_code: string
- currency_iso_code: string
- call_prefix: string
- need_postcode: boolean
- postcode_format: string
- is_default: boolean
- active: boolean
- name: string
+ iso_code: string;
+ currency_iso_code: string;
+ call_prefix: string;
+ need_postcode: boolean;
+ postcode_format: string;
+ is_default: boolean;
+ active: boolean;
+ name: string;
}
export interface Currency {
- iso_code: string
- name: string
- UpdatedAt: string
- iso_code_num: number
- precision: number
- sign: string
- active: boolean
- suffix: boolean
+ iso_code: string;
+ name: string;
+ UpdatedAt: string;
+ iso_code_num: number;
+ precision: number;
+ sign: string;
+ active: boolean;
+ suffix: boolean;
}
export interface UserCart {
- id: number
- checkout_in_progress: boolean
- total_value: number
- currency_iso: string
+ id: number;
+ checkout_in_progress: boolean;
+ total_value: number;
+ currency_iso: string;
}
export interface GenericResponse {
- data: Data
- message?: string
- status: number
+ data: Data;
+ message?: string;
+ status: number;
}
export interface GenericResponseItems {
- data: { items: Data , items_count: number }
- message?: string
- status: number
+ data: { items: Data; items_count: number };
+ message?: string;
+ status: number;
}
-export type { InvestmentPiece, PlanPrediction, PeriodToFirstPiece} from './PlanPrediction'
\ No newline at end of file
+export interface GenericResponseChildren {
+ data: { children: Data; items_count: number };
+ message?: string;
+ status: number;
+}
+
+export type {
+ InvestmentPiece,
+ PlanPrediction,
+ PeriodToFirstPiece,
+} from "./planPrediction";
+export type { Product } from "./product";
diff --git a/types/PlanPrediction.ts b/types/planPrediction.ts
similarity index 100%
rename from types/PlanPrediction.ts
rename to types/planPrediction.ts
diff --git a/types/product.ts b/types/product.ts
new file mode 100644
index 0000000..2c362be
--- /dev/null
+++ b/types/product.ts
@@ -0,0 +1,13 @@
+export interface Product {
+ id: number;
+ link_rewrite: string;
+ name: string;
+ cover_picture_uuid: string;
+ description: string;
+ price: number;
+ formatted_price: string;
+ in_stock: number;
+ is_sale_active: boolean;
+ applied_tax_rate: number;
+ tax_name: string;
+}