Skip to content
Snippets Groups Projects
Unverified Commit 5547016d authored by Tomasz Knapik's avatar Tomasz Knapik
Browse files

Decamelize JSON body on fetch

parent 766750b3
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ export function createNoteForSubmission(submissionID, note) { ...@@ -14,7 +14,7 @@ export function createNoteForSubmission(submissionID, note) {
path: `/apply/api/submissions/${submissionID}/comments/`, path: `/apply/api/submissions/${submissionID}/comments/`,
method: 'POST', method: 'POST',
options: { options: {
body: JSON.stringify(note), body: note,
} }
}; };
} }
import { decamelizeKeys } from 'humps';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
const getBaseUrl = () => { const getBaseUrl = () => {
return process.env.API_BASE_URL; return process.env.API_BASE_URL;
}; };
export async function apiFetch({path, method = 'GET', params = {}, options = {}}) { export function apiFetch({path, method = 'GET', params = {}, options = {}, decamelizeJSON = true}) {
const url = new URL(getBaseUrl()); const url = new URL(getBaseUrl());
url.pathname = path; url.pathname = path;
...@@ -22,6 +23,13 @@ export async function apiFetch({path, method = 'GET', params = {}, options = {}} ...@@ -22,6 +23,13 @@ export async function apiFetch({path, method = 'GET', params = {}, options = {}}
}; };
} }
if (decamelizeJSON === true && options.body !== undefined) {
options = {
...options,
body: JSON.stringify(decamelizeKeys(options.body))
}
}
return fetch(url, { return fetch(url, {
...options, ...options,
headers: { headers: {
......
...@@ -9,8 +9,7 @@ const callApi = (endpoint) => { ...@@ -9,8 +9,7 @@ const callApi = (endpoint) => {
if (!response.ok) { if (!response.ok) {
return Promise.reject({message: json.error}) return Promise.reject({message: json.error})
} }
const camelizedJson = camelizeKeys(json) return camelizeKeys(json)
return camelizedJson
}) })
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment