mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 15:29:36 +02:00
fixes #151
This commit is contained in:
parent
17498121a3
commit
06df5d370d
1 changed files with 20 additions and 2 deletions
|
@ -279,6 +279,9 @@ export const actions: Actions = {
|
|||
formDataToSend.append('latitude', latitude || '');
|
||||
formDataToSend.append('longitude', longitude || '');
|
||||
formDataToSend.append('is_public', is_public.toString());
|
||||
|
||||
let csrfToken = await fetchCSRFToken();
|
||||
|
||||
if (activity_types) {
|
||||
// Filter out empty and duplicate activity types, then trim each activity type
|
||||
const cleanedActivityTypes = Array.from(
|
||||
|
@ -293,6 +296,23 @@ export const actions: Actions = {
|
|||
cleanedActivityTypes.forEach((activity_type) => {
|
||||
formDataToSend.append('activity_types', activity_type);
|
||||
});
|
||||
} else {
|
||||
let res = await fetch(`${serverEndpoint}/api/adventures/${adventureId}/`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Cookie: `${event.cookies.get('auth')}`,
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ activity_types: [] })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const errorBody = await res.json();
|
||||
return {
|
||||
status: res.status,
|
||||
body: { error: errorBody }
|
||||
};
|
||||
}
|
||||
}
|
||||
formDataToSend.append('rating', rating ? rating.toString() : '');
|
||||
formDataToSend.append('link', link || '');
|
||||
|
@ -335,8 +355,6 @@ export const actions: Actions = {
|
|||
};
|
||||
}
|
||||
|
||||
const csrfToken = await fetchCSRFToken();
|
||||
|
||||
if (!csrfToken) {
|
||||
return {
|
||||
status: 500,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue