diff --git a/opentech/static_src/src/app/src/api/notes.js b/opentech/static_src/src/app/src/api/notes.js index 20dda85cb27d097e1dd90759b1098c3ea44bf1ee..ec431cf28874a8b7baed6976de7a1988a751c5ab 100644 --- a/opentech/static_src/src/app/src/api/notes.js +++ b/opentech/static_src/src/app/src/api/notes.js @@ -14,7 +14,7 @@ export function createNoteForSubmission(submissionID, note) { path: `/apply/api/submissions/${submissionID}/comments/`, method: 'POST', options: { - body: JSON.stringify(note), + body: note, } }; } diff --git a/opentech/static_src/src/app/src/api/utils.js b/opentech/static_src/src/app/src/api/utils.js index 5894f783e5f0697821779212266ac8fa9af1e0cc..ac316ae6a3a5379f4bdf0c4f3f7fffa8ab87fd53 100644 --- a/opentech/static_src/src/app/src/api/utils.js +++ b/opentech/static_src/src/app/src/api/utils.js @@ -1,10 +1,11 @@ +import { decamelizeKeys } from 'humps'; import Cookies from 'js-cookie'; const getBaseUrl = () => { 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()); url.pathname = path; @@ -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, { ...options, headers: { diff --git a/opentech/static_src/src/app/src/redux/middleware/api.js b/opentech/static_src/src/app/src/redux/middleware/api.js index 0d61e341c96d902e89c96da9be7559be6ee61437..04a4de9ab0750dd17894d5a01aadb67026213d72 100644 --- a/opentech/static_src/src/app/src/redux/middleware/api.js +++ b/opentech/static_src/src/app/src/redux/middleware/api.js @@ -9,8 +9,7 @@ const callApi = (endpoint) => { if (!response.ok) { return Promise.reject({message: json.error}) } - const camelizedJson = camelizeKeys(json) - return camelizedJson + return camelizeKeys(json) }) ) }