Mohamed Maoulainine Maoulainine be73815861
Some checks failed
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 39s
CI / build (push) Failing after 9s
Format / formatting (pull_request) Successful in 6s
fix: separating the apis
2025-04-28 22:35:56 +02:00

155 lines
4.5 KiB
TypeScript

import { type AxiosError, type AxiosResponse } from "axios";
import Appointment from "@/ApiClasses/Appointment";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
// Shared API
function getSectionCellsByDate(
projectId: number,
sectionId: number,
date: string, // Use string for date in 'YYYY-MM-DD HH:mm' format
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.get(`/shared/projects/sectionCells/${projectId}/${sectionId}/${date}`)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
function getProjectEntrepreneurs(
projectId: number,
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.get(`/shared/projects/entrepreneurs/${projectId}`)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
function getProjectAdmin(
projectId: number,
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.get(`/shared/projects/admin/${projectId}`)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
function getProjectAppointments(
projectId: number,
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.get(`/shared/projects/appointments/${projectId}`)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
function getAppointmentReport(
appointmentId: number,
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.get(`/shared/appointments/report/${appointmentId}`)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
function requestAppointment(
appointmentDetails: Appointment, // Replace 'any' with a proper type for appointment details if available
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.post("/shared/appointments/request", appointmentDetails)
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);
} else {
defaultApiSuccessHandler(response);
}
})
.catch((error: AxiosError) => {
if (onErrorHandler) {
onErrorHandler(error);
} else {
defaultApiErrorHandler(error);
}
});
}
export {
getSectionCellsByDate,
getProjectEntrepreneurs,
getProjectAdmin,
getProjectAppointments,
getAppointmentReport,
requestAppointment,
};