-
Notifications
You must be signed in to change notification settings - Fork 5
Services
Steven edited this page May 28, 2024
·
12 revisions
./src/services/serviceHelper.ts
The serviceHelper is used in order to decrease redundancy in different pages/components and augment raw requests. We do not want to interfere with the minimalist request functions in the service files themselves to guarantee maximum customization. Therefore often occurring data processing logic, toast displays etc. (redundancy) will be defined inside the serviceHelper
.
Example serviceHelper.checkAdmin()
:
const checkAdmin = async () => {
try {
const res = await user.checkAdmin(); // import and use user service function
if (res.ok) {
const { isAdmin } = await res.json(); // process data
return isAdmin; // change return type
}
} catch (err) {
toast.showToast(ToastType.ERROR, 'Connection error. Try again later.'); // display toast
}
return null; // change return type
};