diff --git a/responses.go b/responses.go index d76368e..384f1cd 100644 --- a/responses.go +++ b/responses.go @@ -28,6 +28,15 @@ func init() { if !s.Shown && (s.Direct == nil || *s.Direct != response.IdQuestion) { return APIErrorResponse{err: fmt.Errorf("Cette question n'est pas disponible")} } else if len(response.Answer) > 0 { + // Check if the response has changed + if response.Id != 0 { + if res, err := s.GetResponse(int(response.Id)); err == nil { + if res.IdUser == u.Id && res.Answer == response.Answer { + continue + } + } + } + if _, err := s.NewResponse(response.IdQuestion, u.Id, response.Answer); err != nil { return APIErrorResponse{err: err} } @@ -50,6 +59,15 @@ func init() { for _, response := range responses { if len(response.Answer) > 0 { + // Check if the response has changed + if response.Id != 0 { + if res, err := s.GetResponse(int(response.Id)); err == nil { + if res.IdUser == u.Id && res.Answer == response.Answer { + continue + } + } + } + if _, err := s.NewResponse(response.IdQuestion, u.Id, response.Answer); err != nil { return APIErrorResponse{err: err} } diff --git a/ui/src/components/SurveyQuestions.svelte b/ui/src/components/SurveyQuestions.svelte index 1051e60..9384e39 100644 --- a/ui/src/components/SurveyQuestions.svelte +++ b/ui/src/components/SurveyQuestions.svelte @@ -15,7 +15,11 @@ const res = []; for (const r in responses) { - res.push({"id_question": responses[r].id_question, "value": String(responses[r].value)}) + res.push({ + "id": responses[r].id, + "id_question": responses[r].id_question, + "value": String(responses[r].value) + }) } survey.submitAnswers(res, id_user).then((response) => {