use fetchWrapper for deleteEvent.js
This commit is contained in:
@@ -1,38 +1,13 @@
|
|||||||
|
import fetchWrapper from "../fetchWrapper.js";
|
||||||
import getXSRFToken from "../getXSRF.js";
|
import getXSRFToken from "../getXSRF.js";
|
||||||
|
|
||||||
export default async function deleteEvent(eventId) {
|
export default async function deleteEvent(eventId) {
|
||||||
const csrfToken = await getXSRFToken();
|
const csrfToken = await getXSRFToken();
|
||||||
|
|
||||||
try {
|
return fetchWrapper(
|
||||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/api/events/${eventId}`, {
|
`/api/events/${eventId}`,
|
||||||
method: 'DELETE',
|
{id: eventId},
|
||||||
credentials: 'include',
|
"DELETE",
|
||||||
headers: {
|
{"X-XSRF-TOKEN": csrfToken}
|
||||||
'Content-Type': 'application/json',
|
);
|
||||||
'X-XSRF-TOKEN': csrfToken,
|
|
||||||
'Accept': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
id: eventId,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
if (response.status === 422) {
|
|
||||||
return {
|
|
||||||
status: 422,
|
|
||||||
errors: data.errors
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Erreur HTTP ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { status: response.status, data };
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
return { status: "error", error };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user