From 6b352c8adb85e810afb6cfd742307404727a45da Mon Sep 17 00:00:00 2001
From: Lucas Schoenfelder <les17@inf.ufpr.br>
Date: Thu, 4 Feb 2021 11:46:05 -0300
Subject: [PATCH] fix post/put error 500

---
 src/Components/HelperFunctions/getAxiosConfig.js | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/Components/HelperFunctions/getAxiosConfig.js b/src/Components/HelperFunctions/getAxiosConfig.js
index 000ffb6b..c59bb1a7 100644
--- a/src/Components/HelperFunctions/getAxiosConfig.js
+++ b/src/Components/HelperFunctions/getAxiosConfig.js
@@ -33,6 +33,7 @@ function fetchHeaders () {
 
     if (auth_headers) {
         const myHeaders = new Headers(auth_headers)
+        myHeaders.append('Content-Type', 'application/json')
         return myHeaders
     }
     else {
@@ -119,15 +120,10 @@ export const axiosDeleteRequest = (url, onSuccess, onError) => {
 }
 
 export const axiosPutRequest = (url, payload, onSuccess, onError) => {
-    let formData = new FormData()
-    for (const [key, value] of Object.entries(payload)) {
-        formData.append(`${key}`,value);
-    }
-
     fetch((`${apiUrl}${url}`), {
         method : 'PUT',
         headers : fetchHeaders(),
-        body: formData
+        body: JSON.stringify(payload)
     })
         .then(response => {
             if (response.headers.has('access-token')) {
@@ -145,15 +141,10 @@ export const axiosPutRequest = (url, payload, onSuccess, onError) => {
 }
 
 export const axiosPostRequest = (url, payload, onSuccess, onError) => {
-    let formData = new FormData()
-    for (const [key, value] of Object.entries(payload)) {
-        formData.append(`${key}`,value);
-    }
-
     fetch((`${apiUrl}${url}`), {
         method : 'POST',
         headers : fetchHeaders(),
-        body: formData
+        body: JSON.stringify(payload)
     })
         .then(response => {
             if (response.headers.has('access-token')) {
@@ -213,7 +204,6 @@ export const authentication = (url, payload, onSuccess, onError) => {
 
     fetch((`${apiUrl}${url}`), {
         method : 'POST',
-        headers : fetchHeaders(),
         body: formData
     })
         .then(response => {
-- 
GitLab