From 008e003207f718108626aa4b3e17d3efd91ca1c5 Mon Sep 17 00:00:00 2001 From: Mohamed Maoulainine Maoulainine Date: Tue, 29 Apr 2025 00:32:03 +0200 Subject: [PATCH] fix: conflict on Apis --- .../src/services/Apis/Admin.ts | 2 +- .../src/services/Apis/Entrepreneurs.ts | 37 +++---------------- .../src/services/Apis/Shared.ts | 2 +- .../src/services/Apis/Unauth.ts | 2 +- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/front/MyINPulse-front/src/services/Apis/Admin.ts b/front/MyINPulse-front/src/services/Apis/Admin.ts index d08df72..bf1fa1d 100644 --- a/front/MyINPulse-front/src/services/Apis/Admin.ts +++ b/front/MyINPulse-front/src/services/Apis/Admin.ts @@ -3,7 +3,7 @@ import Project from "@/ApiClasses/Project"; import Report from "@/ApiClasses/Repport"; import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" -// Admin API +// Admin API function getPendingAccounts( onSuccessHandler?: (response: AxiosResponse) => void, onErrorHandler?: (error: AxiosError) => void diff --git a/front/MyINPulse-front/src/services/Apis/Entrepreneurs.ts b/front/MyINPulse-front/src/services/Apis/Entrepreneurs.ts index c9c4ff6..06440c2 100644 --- a/front/MyINPulse-front/src/services/Apis/Entrepreneurs.ts +++ b/front/MyINPulse-front/src/services/Apis/Entrepreneurs.ts @@ -1,38 +1,11 @@ +import { type AxiosError, type AxiosResponse } from "axios"; import Project from "@/ApiClasses/Project"; import SectionCell from "@/ApiClasses/SectionCell"; import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" -axiosInstance.interceptors.response.use( - (response) => response, // Directly return successful responses. - async (error) => { - const originalRequest = error.config; - if ( - ((error.response && error.response.status === 401) || - error.code == "ERR_NETWORK") && - !originalRequest._retry && - store.authenticated - ) { - originalRequest._retry = true; // Mark the request as retried to avoid infinite loops. - try { - await store.refreshUserToken(); - // Update the authorization header with the new access token. - axiosInstance.defaults.headers.common["Authorization"] = - `Bearer ${store.user.token}`; - return axiosInstance(originalRequest); // Retry the original request with the new access token. - } catch (refreshError) { - // Handle refresh token errors by clearing stored tokens and redirecting to the login page. - console.error("Token refresh failed:", refreshError); - localStorage.removeItem("accessToken"); - localStorage.removeItem("refreshToken"); - router.push("/login"); - return Promise.reject(refreshError); - } - } - return Promise.reject(error); // For all other errors, return the error as is. - } -); -// Entrepreneurs API + +// Entrepreneurs API function requestProjectCreation( projectDetails: Project, // Replace 'any' with a proper type for project details if available onSuccessHandler?: (response: AxiosResponse) => void, @@ -57,12 +30,12 @@ function requestProjectCreation( } function addSectionCell( - sectionCellDetails: SectionCell, + sectionCellDetails: SectionCell, // Replace 'any' with a proper type for section cell details if available onSuccessHandler?: (response: AxiosResponse) => void, onErrorHandler?: (error: AxiosError) => void ): void { axiosInstance - .post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici + .post("/entrepreneur/sectionCells", sectionCellDetails) .then((response) => { if (onSuccessHandler) { onSuccessHandler(response); diff --git a/front/MyINPulse-front/src/services/Apis/Shared.ts b/front/MyINPulse-front/src/services/Apis/Shared.ts index 6693527..ec9a52c 100644 --- a/front/MyINPulse-front/src/services/Apis/Shared.ts +++ b/front/MyINPulse-front/src/services/Apis/Shared.ts @@ -3,7 +3,7 @@ import Appointment from "@/ApiClasses/Appointment"; import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" -// Shared API +// Shared API function getSectionCellsByDate( projectId: number, sectionId: number, diff --git a/front/MyINPulse-front/src/services/Apis/Unauth.ts b/front/MyINPulse-front/src/services/Apis/Unauth.ts index d4e4f64..c944938 100644 --- a/front/MyINPulse-front/src/services/Apis/Unauth.ts +++ b/front/MyINPulse-front/src/services/Apis/Unauth.ts @@ -3,7 +3,7 @@ import { type AxiosError, type AxiosResponse } from "axios"; import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" -// Unauth API +// Unauth API function finalizeAccount( onSuccessHandler?: (response: AxiosResponse) => void, onErrorHandler?: (error: AxiosError) => void