Skip to content

Commit

Permalink
👻 Add required field to assessment to reflect underlying questionnare…
Browse files Browse the repository at this point in the history
… required status

Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Jan 5, 2024
1 parent f09d0b2 commit 54068d7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
15 changes: 13 additions & 2 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,13 @@ func (h ApplicationHandler) AssessmentList(ctx *gin.Context) {
resources := []Assessment{}
for i := range assessments {
r := Assessment{}
r.With(&assessments[i])
questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

r.With(&assessments[i], questionnaires)
resources = append(resources, r)
}

Expand Down Expand Up @@ -1061,8 +1067,13 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) {
if newAssessment {
metrics.AssessmentsInitiated.Inc()
}
questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

r.With(m)
r.With(m, questionnaires)
h.Respond(ctx, http.StatusCreated, r)
}

Expand Down
15 changes: 13 additions & 2 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@ func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) {
resources := []Assessment{}
for i := range m.Assessments {
r := Assessment{}
r.With(&m.Assessments[i])
questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

r.With(&m.Assessments[i], questionnaires)
resources = append(resources, r)
}

Expand Down Expand Up @@ -330,8 +336,13 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
if newAssessment {
metrics.AssessmentsInitiated.Inc()
}
questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

r.With(m)
r.With(m, questionnaires)
h.Respond(ctx, http.StatusCreated, r)
}

Expand Down
23 changes: 20 additions & 3 deletions api/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ func (h AssessmentHandler) Get(ctx *gin.Context) {
_ = ctx.Error(result.Error)
return
}

questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

r := Assessment{}
r.With(m)
r.With(m, questionnaires)

h.Respond(ctx, http.StatusOK, r)
}
Expand All @@ -73,10 +80,16 @@ func (h AssessmentHandler) List(ctx *gin.Context) {
_ = ctx.Error(result.Error)
return
}
questionnaires, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
ctx.Error(err)
return
}

resources := []Assessment{}
for i := range list {
r := Assessment{}
r.With(&list[i])
r.With(&list[i], questionnaires)
resources = append(resources, r)
}

Expand Down Expand Up @@ -164,11 +177,12 @@ type Assessment struct {
Status string `json:"status"`
Thresholds assessment.Thresholds `json:"thresholds"`
RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"`
Required bool `json:"required"`
}

//
// With updates the resource with the model.
func (r *Assessment) With(m *model.Assessment) {
func (r *Assessment) With(m *model.Assessment, resolver *assessment.QuestionnaireResolver) {
r.Resource.With(&m.Model)
r.Questionnaire = r.ref(m.QuestionnaireID, &m.Questionnaire)
r.Archetype = r.refPtr(m.ArchetypeID, m.Archetype)
Expand All @@ -193,6 +207,9 @@ func (r *Assessment) With(m *model.Assessment) {
r.Thresholds = a.Thresholds
r.Sections = a.Sections
r.Status = a.Status()
if resolver != nil {
r.Required = resolver.Required(m.QuestionnaireID)
}
}

//
Expand Down

0 comments on commit 54068d7

Please sign in to comment.