refactor: Deplacement du JWT dans le back

This commit is contained in:
Luc SORIGNET
2025-02-21 19:22:33 +01:00
parent 214fb186fa
commit eb89a324ab
27 changed files with 145 additions and 156 deletions

View File

@ -0,0 +1,128 @@
import {
BE_SCHOOL_SPECIALITIES_URL,
BE_SCHOOL_TEACHERS_URL,
BE_SCHOOL_SCHOOLCLASSES_URL,
BE_SCHOOL_PLANNINGS_URL,
BE_SCHOOL_FEES_URL,
BE_SCHOOL_DISCOUNTS_URL,
BE_SCHOOL_PAYMENT_PLANS_URL,
BE_SCHOOL_PAYMENT_MODES_URL,
BE_SCHOOL_ESTABLISHMENT_URL,
ESTABLISHMENT_ID
} from '@/utils/Url';
const requestResponseHandler = async (response) => {
const body = await response.json();
if (response.ok) {
return body;
}
// Throw an error with the JSON body containing the form errors
const error = new Error('Form submission error');
error.details = body;
throw error;
}
export const fetchSpecialities = () => {
return fetch(`${BE_SCHOOL_SPECIALITIES_URL}`)
.then(requestResponseHandler)
};
export const fetchTeachers = () => {
return fetch(`${BE_SCHOOL_TEACHERS_URL}`)
.then(requestResponseHandler)
};
export const fetchClasses = () => {
return fetch(`${BE_SCHOOL_SCHOOLCLASSES_URL}`)
.then(requestResponseHandler)
};
export const fetchSchedules = () => {
return fetch(`${BE_SCHOOL_PLANNINGS_URL}`)
.then(requestResponseHandler)
};
export const fetchRegistrationDiscounts = () => {
return fetch(`${BE_SCHOOL_DISCOUNTS_URL}?filter=registration`)
.then(requestResponseHandler)
};
export const fetchTuitionDiscounts = () => {
return fetch(`${BE_SCHOOL_DISCOUNTS_URL}?filter=tuition`)
.then(requestResponseHandler)
};
export const fetchRegistrationFees = () => {
return fetch(`${BE_SCHOOL_FEES_URL}?filter=registration`)
.then(requestResponseHandler)
};
export const fetchTuitionFees = () => {
return fetch(`${BE_SCHOOL_FEES_URL}?filter=tuition`)
.then(requestResponseHandler)
};
export const fetchRegistrationPaymentPlans = () => {
return fetch(`${BE_SCHOOL_PAYMENT_PLANS_URL}?filter=registration`)
.then(requestResponseHandler)
}
export const fetchTuitionPaymentPlans = () => {
return fetch(`${BE_SCHOOL_PAYMENT_PLANS_URL}?filter=tuition`)
.then(requestResponseHandler)
}
export const fetchRegistrationPaymentModes = () => {
return fetch(`${BE_SCHOOL_PAYMENT_MODES_URL}?filter=registration`)
.then(requestResponseHandler)
}
export const fetchTuitionPaymentModes = () => {
return fetch(`${BE_SCHOOL_PAYMENT_MODES_URL}?filter=tuition`)
.then(requestResponseHandler)
}
export const fetchEstablishment = () => {
return fetch(`${BE_SCHOOL_ESTABLISHMENT_URL}/${ESTABLISHMENT_ID}`)
.then(requestResponseHandler)
}
export const createDatas = (url, newData, csrfToken) => {
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify(newData),
credentials: 'include'
})
.then(requestResponseHandler)
};
export const updateDatas = (url, id, updatedData, csrfToken) => {
return fetch(`${url}/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify(updatedData),
credentials: 'include'
})
.then(requestResponseHandler)
};
export const removeDatas = (url, id, csrfToken) => {
return fetch(`${url}/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
credentials: 'include'
})
.then(requestResponseHandler)
};