Display number of items left to correct to admin on surveylist
This commit is contained in:
parent
1532ede587
commit
6a54315626
2 changed files with 59 additions and 4 deletions
29
surveys.go
29
surveys.go
|
|
@ -80,7 +80,34 @@ func declareAPIAuthSurveysRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
s := c.MustGet("survey").(*Survey)
|
||||
|
||||
if (s.Promo == u.Promo && s.Shown) || (u != nil && u.IsAdmin) {
|
||||
if u.IsAdmin {
|
||||
questions, err := s.GetQuestions()
|
||||
if err != nil {
|
||||
log.Println("Unable to getQuestions:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve questions. Please try again later."})
|
||||
return
|
||||
}
|
||||
|
||||
itemCount := 0
|
||||
itemCorrected := 0
|
||||
for _, q := range questions {
|
||||
res, err := q.GetResponses()
|
||||
if err != nil {
|
||||
log.Printf("Unable to GetResponses(qid=%d): %s", q.Id, err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during responses retrieval."})
|
||||
return
|
||||
}
|
||||
|
||||
for _, r := range res {
|
||||
itemCount += 1
|
||||
if r.TimeScored != nil && (r.TimeReported == nil || r.TimeScored.After(*r.TimeReported)) {
|
||||
itemCorrected += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, map[string]int{"count": itemCount, "corrected": itemCorrected})
|
||||
} else if s.Promo == u.Promo && s.Shown {
|
||||
score, err := s.GetScore(u)
|
||||
if err != nil {
|
||||
log.Printf("Unable to GetScore(uid=%d;sid=%d): %s", u.Id, s.Id, err.Error())
|
||||
|
|
|
|||
Reference in a new issue