Don't readd the answer if unchanged
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-03-15 01:39:10 +01:00
parent 8f49a49530
commit cc4b10db42
2 changed files with 23 additions and 1 deletions

View File

@ -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}
}

View File

@ -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) => {