fix fetch

This commit is contained in:
2025-06-24 12:05:43 +02:00
parent 26e7467f7f
commit a000f966eb
14 changed files with 3326 additions and 13451 deletions

View File

@ -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);