use fetchWrapper for users routes

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2026-01-30 14:35:07 +01:00
parent a0bba2deb4
commit 79e765dd96
5 changed files with 26 additions and 102 deletions
+7 -28
View File
@@ -1,34 +1,13 @@
import fetchWrapper from "../fetchWrapper.js";
import getXSRFToken from "../getXSRF.js";
export default async function deactivateUser(userId) {
const csrfToken = await getXSRFToken();
try {
const response = await fetch(`${import.meta.env.VITE_API_URL}/api/users/${userId}/deactivate`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': csrfToken,
'Accept': 'application/json'
},
body: JSON.stringify({
id: userId
})
});
const data = await response.json();
if (!response.ok) {
return {
status: response.status,
errors: data.errors || data.message
};
}
return { status: response.status, data };
} catch (error) {
return { status: 500, error };
}
return fetchWrapper(
`/api/users/${userId}/deactivate`,
{ id: userId },
"POST",
{ "X-XSRF-TOKEN": csrfToken }
);
}