From 54068d74cc627884f8169e8c13624c71377d378a Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Thu, 4 Jan 2024 21:53:47 -0500 Subject: [PATCH] :ghost: Add required field to assessment to reflect underlying questionnare required status Signed-off-by: ibolton336 --- api/application.go | 15 +++++++++++++-- api/archetype.go | 15 +++++++++++++-- api/assessment.go | 23 ++++++++++++++++++++--- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/api/application.go b/api/application.go index 5de64271c..f6aa792fb 100644 --- a/api/application.go +++ b/api/application.go @@ -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) } @@ -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) } diff --git a/api/archetype.go b/api/archetype.go index c1c6dea91..ca03e0fda 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -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) } @@ -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) } diff --git a/api/assessment.go b/api/assessment.go index 4f34de7d9..89dd53e1c 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -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) } @@ -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) } @@ -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) @@ -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) + } } //