Timed questions updates db twice

This commit is contained in:
nemunaire 2022-09-02 14:07:39 +02:00
parent 74630139fb
commit 02a232b1fa

View File

@ -303,13 +303,11 @@ func SurveyWSAdmin(c *gin.Context) {
if survey, err := getSurvey(sid); err != nil {
log.Println("Unable to retrieve survey:", err)
} else {
survey.Direct = v.QuestionId
if v.Timer > 0 {
if *survey.Direct != 0 {
var z int64 = 0
survey.Direct = &z
survey.Corrected = false
survey.Update()
}
survey.Corrected = false
survey.Update()
go func(corrected bool) {
time.Sleep(time.Duration(OffsetQuestionTimer+v.Timer) * time.Millisecond)
@ -319,13 +317,16 @@ func SurveyWSAdmin(c *gin.Context) {
survey.WSWriteAll(WSMessage{Action: "new_question", QuestionId: v.QuestionId, Corrected: true, Corrections: getCorrectionString(*v.QuestionId)})
} else {
var z int64 = 0
survey.Direct = &z
survey.Update()
survey.WSWriteAll(WSMessage{Action: "pause"})
WSAdminWriteAll(WSMessage{Action: "pause", SurveyId: &survey.Id})
}
}(v.Corrected)
v.Corrected = false
} else {
survey.Direct = v.QuestionId
survey.Corrected = v.Corrected
if v.Corrected {
v.Corrections = getCorrectionString(*v.QuestionId)