Check that surveys are open before accepting a response
All checks were successful
continuous-integration/drone/push Build is passing

Thanks-To: Kurogor <mahe.charpy@epita.fr>
Thanks-To: Fumesover <albin.parou@epita.fr>
Thanks-To: Sébastien Januszczak <sebastien.januszczak@epita.fr>
Thanks-To: Clément Lanata <clement.lanata@epita.fr>
Thanks-To: Alexandre Delorme <alexandre.delorme@epita.fr>
Thanks-To: Pioupush <justin.puchelle@epita.fr>
This commit is contained in:
nemunaire 2021-11-19 21:41:01 +01:00
parent dfcde910b2
commit 5c53d2eaea

View File

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"strconv"
"time"
@ -15,6 +16,14 @@ func init() {
return APIErrorResponse{err: err}
}
// Check the survey is open
now := time.Now()
if now.Before(s.StartAvailability) {
return APIErrorResponse{err: fmt.Errorf("Le questionnaire n'a pas encore commencé")}
} else if now.After(s.EndAvailability) {
return APIErrorResponse{err: fmt.Errorf("Le questionnaire n'est plus ouvert")}
}
for _, response := range responses {
if len(response.Answer) > 0 {
if _, err := s.NewResponse(response.IdQuestion, u.Id, response.Answer); err != nil {