mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
feat: Gestion du planning [3]
This commit is contained in:
@ -2,12 +2,14 @@ import { BE_PLANNING_PLANNINGS_URL, BE_PLANNING_EVENTS_URL } from '@/utils/Url';
|
||||
|
||||
const requestResponseHandler = async (response) => {
|
||||
const body = response.status !== 204 ? await response?.json() : {};
|
||||
console.log(response);
|
||||
if (response.ok) {
|
||||
return body;
|
||||
}
|
||||
// Throw an error with the JSON body containing the form errors
|
||||
const error = new Error(body?.errorMessage || 'Une erreur est survenue');
|
||||
const error = new Error(
|
||||
body?.errorMessage ||
|
||||
`Une erreur est survenue code de retour : ${response.status}`
|
||||
);
|
||||
error.details = body;
|
||||
throw error;
|
||||
};
|
||||
@ -51,8 +53,15 @@ const removeDatas = (url, csrfToken) => {
|
||||
}).then(requestResponseHandler);
|
||||
};
|
||||
|
||||
export const fetchPlannings = () => {
|
||||
return getData(`${BE_PLANNING_PLANNINGS_URL}`);
|
||||
export const fetchPlannings = (establishment_id=null,planningMode=null) => {
|
||||
let url = `${BE_PLANNING_PLANNINGS_URL}`;
|
||||
if (establishment_id) {
|
||||
url += `?establishment_id=${establishment_id}`;
|
||||
}
|
||||
if (planningMode) {
|
||||
url += `&planning_mode=${planningMode}`;
|
||||
}
|
||||
return getData(url);
|
||||
};
|
||||
|
||||
export const getPlanning = (id) => {
|
||||
@ -71,8 +80,17 @@ export const deletePlanning = (id, csrfToken) => {
|
||||
return removeDatas(`${BE_PLANNING_PLANNINGS_URL}/${id}`, csrfToken);
|
||||
};
|
||||
|
||||
export const fetchEvents = () => {
|
||||
return getData(`${BE_PLANNING_EVENTS_URL}`);
|
||||
export const fetchEvents = (establishment_id=null, planningMode=null) => {
|
||||
let url = `${BE_PLANNING_EVENTS_URL}`;
|
||||
if (establishment_id) {
|
||||
url += `?establishment_id=${establishment_id}`;
|
||||
}
|
||||
if (planningMode) {
|
||||
url += `&planning_mode=${planningMode}`;
|
||||
}
|
||||
|
||||
return getData(url);
|
||||
|
||||
};
|
||||
|
||||
export const getEvent = (id) => {
|
||||
@ -91,6 +109,10 @@ export const deleteEvent = (id, csrfToken) => {
|
||||
return removeDatas(`${BE_PLANNING_EVENTS_URL}/${id}`, csrfToken);
|
||||
};
|
||||
|
||||
export const fetchUpcomingEvents = () => {
|
||||
return getData(`${BE_PLANNING_EVENTS_URL}/upcoming`);
|
||||
export const fetchUpcomingEvents = (establishment_id=null) => {
|
||||
let url = `${BE_PLANNING_EVENTS_URL}/upcoming`;
|
||||
if (establishment_id) {
|
||||
url += `?establishment_id=${establishment_id}`;
|
||||
}
|
||||
return getData(`${url}`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user