refactor api-simulation for create and fetch

This commit is contained in:
2025-09-06 14:05:29 +05:30
parent 0e8a004f70
commit 3b8bdd3684
6 changed files with 221 additions and 191 deletions

View File

@@ -59,7 +59,8 @@ export const saveSimulationData = async (data: any) => {
}
}
};
export const getSimulationData = async (data: any) => {
export const updateSimulateData = async (data: any) => {
console.log("data: update", data);
try {
const response = await fetch(`${url_Backend_dwinzo}/api/V1/ValidateSimulated`, {
method: "POST",
@@ -76,7 +77,7 @@ export const getSimulationData = async (data: any) => {
localStorage.setItem("token", newAccessToken);
}
if (!response.ok) {
console.error("Failed to add project");
console.error("Failed to update ");
}
const result = await response.json();
@@ -90,4 +91,35 @@ export const getSimulationData = async (data: any) => {
}
}
};
export const clearSimulationData = ({ key, data }: SimulationData) => {};
export const getSimulationData = async (projectId: string, versionId: string, productUuid: string) => {
console.log("called");
try {
const response = await fetch(`${url_Backend_dwinzo}/api/V1/SimulatedDatas/${projectId}/${versionId}?productUuid=${productUuid}`, {
method: "GET",
headers: {
Authorization: "Bearer <access_token>",
"Content-Type": "application/json",
token: localStorage.getItem("token") || "",
refresh_token: localStorage.getItem("refreshToken") || "",
},
});
console.log("response: ", response);
const newAccessToken = response.headers.get("x-access-token");
if (newAccessToken) {
localStorage.setItem("token", newAccessToken);
}
if (!response.ok) {
throw new Error("Failed to fetch simulateData");
}
return await response.json();
} catch (error: any) {
console.error("Failed to get simulation data");
console.log(error.message);
}
};
// export const clearSimulationData = ({ key, data }: SimulationData) => {};