Skip to content

Commit

Permalink
Fix loopvar ptr bug in assessment logic
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Nov 13, 2023
1 parent 6171a10 commit 7947525
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 3 additions & 2 deletions assessment/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type Application struct {
// With updates the Application with the db model and deserializes its assessments.
func (r *Application) With(m *model.Application) {
r.Application = m
for _, a := range m.Assessments {
for i := range m.Assessments {
a := &m.Assessments[i]
assessment := Assessment{}
assessment.With(&a)
assessment.With(a)
r.Assessments = append(r.Assessments, assessment)
}
}
Expand Down
5 changes: 3 additions & 2 deletions assessment/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ type Archetype struct {
// With updates the Archetype with the db model and deserializes its assessments.
func (r *Archetype) With(m *model.Archetype) {
r.Archetype = m
for _, a := range m.Assessments {
for i := range m.Assessments {
a := &m.Assessments[i]
assessment := Assessment{}
assessment.With(&a)
assessment.With(a)
r.Assessments = append(r.Assessments, assessment)
}
}
Expand Down
8 changes: 2 additions & 6 deletions assessment/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ func (r *QuestionnaireResolver) cacheQuestionnaires() (err error) {
// questionnaires.
func (r *QuestionnaireResolver) Assessed(assessments []Assessment) (assessed bool) {
answered := NewSet()
loop:
for _, a := range assessments {
if r.requiredQuestionnaires.Contains(a.QuestionnaireID) {
for _, s := range a.Sections {
if !s.Complete() {
continue loop
}
if a.Complete() {
answered.Add(a.QuestionnaireID)
}
answered.Add(a.QuestionnaireID)
}
}
assessed = answered.Superset(r.requiredQuestionnaires, false)
Expand Down

0 comments on commit 7947525

Please sign in to comment.