ga-wdi-boston / team-project

Other
2 stars 39 forks source link

PATCH 500 Internal Server Error but console logging update #334

Closed JLisaW closed 7 years ago

JLisaW commented 7 years ago

For the update question function, I am getting a PATCH 500 error in the browser but in the console.logs i put in i can see the update was made. In the console it always says data is undefined but I'm not sure why. In the terminal I am getting a 200 ok and I can see the update in the DB.

image

ui.js

const editQuestionSuccess = (data) => {
    api.surveyQuestions()
      .then(surveyQuestionsSuccess)
      .catch(surveyQuestionsFailure)
    resetSurveyFormFields()
}

const editQuestionFailure = () => {
resetSurveyFormFields()
  $('.alert').text('Failed to Update Question')
}

api.js

const editQuestion = (questionId, data) => {
  console.log('api.js edit one question function fired this is questionId', questionId)
  console.log('edit question data', data)
  return $.ajax({
    url: config.apiOrigin + '/questions/' + questionId,
    method: 'PATCH',
    headers: {
      Authorization: 'Token token=' + store.user.token
    },
    data: {
      'question': {
        'prompt': data
      }
    }
  })
}

event.js

const onEditQuestion = function (event) {
  event.preventDefault()
  console.log('on edit question fired')
  const questionId = $(event.target).attr('questionId')
  const data = getFormFields(event.target)
    api.editQuestion(questionId, data)
      .then(ui.editQuestionSuccess)
      .catch(ui.editQuestionFailure)
}
benjimelito commented 7 years ago

What is the format your API expects the data to be in?