Files
n3wt-school/Front-End/src/app/lib/schoolAction.js
2025-01-21 20:39:36 +01:00

56 lines
1.4 KiB
JavaScript

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
} 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 fetchDiscounts = () => {
return fetch(`${BE_SCHOOL_DISCOUNTS_URL}`)
.then(requestResponseHandler)
};
export const fetchRegistrationFees = () => {
return fetch(`${BE_SCHOOL_FEES_URL}/registration`)
.then(requestResponseHandler)
};
export const fetchTuitionFees = () => {
return fetch(`${BE_SCHOOL_FEES_URL}/tuition`)
.then(requestResponseHandler)
};