mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-04 03:31:28 +00:00
refactor: Deplacement du JWT dans le back
This commit is contained in:
128
Front-End/src/app/actions/schoolAction.js
Normal file
128
Front-End/src/app/actions/schoolAction.js
Normal 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)
|
||||
};
|
||||
Reference in New Issue
Block a user