Merge branch 'fix_fetch'
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import { usePB } from "~/composables/usePB";
|
||||
import type {
|
||||
CountryList,
|
||||
Country,
|
||||
Currencies,
|
||||
Currency,
|
||||
FooterListResponse,
|
||||
GenericResponse,
|
||||
GenericResponseItems,
|
||||
MenuListResponse,
|
||||
PBFooterItem,
|
||||
PBMenuItem,
|
||||
@ -10,6 +13,7 @@ import type {
|
||||
} from "~/types";
|
||||
import { useStore } from "./store";
|
||||
import { ref, watch } from "vue";
|
||||
import { useMyFetch } from "#imports";
|
||||
|
||||
function buildTreeRecursive(
|
||||
data: (PBMenuItem | UIMenuItem)[],
|
||||
@ -41,8 +45,8 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
const menuItems = ref<MenuListResponse>();
|
||||
|
||||
const footerItems = ref<FooterListResponse>();
|
||||
const countryList = ref<CountryList[]>();
|
||||
const currencies = ref<Currencies[]>();
|
||||
const countryList = ref<Country[]>();
|
||||
const currencies = ref<Currency[]>();
|
||||
|
||||
// curr/country
|
||||
const selectedCountry = ref();
|
||||
@ -87,8 +91,8 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
|
||||
const getCountryList = async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/country/list`,
|
||||
const {data} = await useMyFetch<GenericResponse<Country[]>>(
|
||||
`/api/public/country/list`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -96,12 +100,12 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
const data = await res.json();
|
||||
countryList.value = data.data
|
||||
// const data = await res.json();
|
||||
countryList.value = data
|
||||
if (countryList.value)
|
||||
selectedPhoneCountry.value = countryList.value[0]
|
||||
|
||||
@ -112,21 +116,25 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
|
||||
const getCurrencies = async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/currencies`,
|
||||
const {data} = await useMyFetch<GenericResponseItems<Currency[]>>(
|
||||
`/api/public/currencies`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
const data = await res.json();
|
||||
currencies.value = data.data.items
|
||||
// const data = await res.json();
|
||||
currencies.value = data.items
|
||||
|
||||
// console.log(data.items, "data");
|
||||
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
|
@ -1,24 +1,31 @@
|
||||
import { NuxtErrorBoundary } from "#components";
|
||||
import { useMyFetch } from "#imports";
|
||||
import type { GenericResponse, GenericResponseItems, UserCart } from "~/types";
|
||||
import type { Product } from "~/types/product";
|
||||
|
||||
export const useProductStore = defineStore("productStore", () => {
|
||||
const productList = ref();
|
||||
const productList = ref<Product>();
|
||||
const modules = ref();
|
||||
|
||||
async function getList(count: number, categoryId = 1) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/products/category/${categoryId}?p=1&elems=${count}`,
|
||||
const { data } = await useMyFetch<GenericResponseItems<Product>>(
|
||||
`/api/public/products/category/${categoryId}?p=1&elems=${count}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: async (_, status) => {
|
||||
// await navigateTo("/error", { replace: true });
|
||||
throw createError({
|
||||
statusCode: status,
|
||||
statusMessage: `HTTP error: ${status}`,
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
@ -49,7 +56,7 @@ export const useProductStore = defineStore("productStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
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`,
|
||||
@ -72,27 +79,30 @@ export const useProductStore = defineStore("productStore", () => {
|
||||
}
|
||||
}
|
||||
|
||||
const cart = ref();
|
||||
// async function getCart() {
|
||||
// try {
|
||||
// const res = await fetch(`http://127.0.0.1:4000/api/public/user/cart`, {
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// });
|
||||
const cart = ref({} as UserCart);
|
||||
async function getCart() {
|
||||
try {
|
||||
const { data } = await useMyFetch<GenericResponse<UserCart>>(
|
||||
`/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}`);
|
||||
// }
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
// const data = await res.json();
|
||||
// console.log(data);
|
||||
|
||||
// cart.value = data;
|
||||
// } catch (error) {
|
||||
// console.error("getList error:", error);
|
||||
// }
|
||||
// }
|
||||
cart.value = data;
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
productList,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { useMyFetch } from "#imports";
|
||||
import { usePB } from "~/composables/usePB";
|
||||
import type { componentsListType, PBPageItem } from "~/types";
|
||||
import type { componentsListType, GenericResponse, PBPageItem, PlanPrediction } from "~/types";
|
||||
// import { useI18n } from "vue-i18n";
|
||||
|
||||
export const useStore = defineStore("store", () => {
|
||||
@ -10,7 +11,7 @@ export const useStore = defineStore("store", () => {
|
||||
// calculator
|
||||
const monthlySavings = ref(137);
|
||||
const storagePeriod = ref(10);
|
||||
const totalInvestment = ref()
|
||||
const totalInvestment:Ref<number> = ref(0)
|
||||
const minValue = ref()
|
||||
|
||||
// login
|
||||
@ -71,21 +72,17 @@ export const useStore = defineStore("store", () => {
|
||||
|
||||
async function getCalculator() {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/plan-prediction/easy/calculate?monthly_deposit=${monthlySavings.value}&years=${storagePeriod.value}`,
|
||||
const {data} = await useMyFetch<GenericResponse<PlanPrediction>>(
|
||||
`/api/public/plan-prediction/easy/calculate?monthly_deposit=${monthlySavings.value}&years=${storagePeriod.value}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
totalInvestment.value = data.data.total_investement_value
|
||||
totalInvestment.value = data.total_investement_value
|
||||
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
@ -94,21 +91,22 @@ export const useStore = defineStore("store", () => {
|
||||
|
||||
async function getMinValue() {
|
||||
try {
|
||||
const res = await fetch(
|
||||
'http://127.0.0.1:4000/api/public/plan-prediction/free/minimum',
|
||||
const {data} = await useMyFetch<GenericResponse<number>>(
|
||||
'/api/public/plan-prediction/free/minimum',
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
const data = await res.json();
|
||||
minValue.value = data.data
|
||||
// const data = await res.json();
|
||||
minValue.value = data
|
||||
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
|
Reference in New Issue
Block a user