ALAMI Adnane 351727f3d5
All checks were successful
Format / formatting (push) Successful in 5s
Build / build (push) Successful in 40s
CI / build (push) Successful in 12s
Format / formatting (pull_request) Successful in 6s
fix: prettier
2025-04-29 00:42:59 +02:00

158 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,
};