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]>

Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Jan 12, 2024
1 parent f09d0b2 commit a3bbd88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 7 additions & 1 deletion api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ func (h ApplicationHandler) StakeholdersUpdate(ctx *gin.Context) {
func (h ApplicationHandler) AssessmentList(ctx *gin.Context) {
m := &model.Application{}
id := h.pk(ctx)
db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups")
db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire")
db = db.Omit("Analyses")
result := db.First(m, id)
if result.Error != nil {
Expand Down Expand Up @@ -994,6 +994,12 @@ func (h ApplicationHandler) AssessmentList(ctx *gin.Context) {
for i := range assessments {
r := Assessment{}
r.With(&assessments[i])
if assessments[i].Questionnaire.ID != 0 {
r.QuestionnaireRequired = assessments[i].Questionnaire.Required
} else {
r.QuestionnaireRequired = false
}

resources = append(resources, r)
}

Expand Down
8 changes: 7 additions & 1 deletion api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (h ArchetypeHandler) Update(ctx *gin.Context) {
func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) {
m := &model.Archetype{}
id := h.pk(ctx)
db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups")
db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire")
result := db.First(m, id)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand All @@ -264,6 +264,12 @@ func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) {
resources := []Assessment{}
for i := range m.Assessments {
r := Assessment{}
if m.Assessments[i].Questionnaire.ID != 0 {
r.QuestionnaireRequired = m.Assessments[i].Questionnaire.Required
} else {
r.QuestionnaireRequired = false
}

r.With(&m.Assessments[i])
resources = append(resources, r)
}
Expand Down
14 changes: 9 additions & 5 deletions api/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (h AssessmentHandler) Get(ctx *gin.Context) {
return
}
r := Assessment{}

r.QuestionnaireRequired = m.Questionnaire.Required

r.With(m)

h.Respond(ctx, http.StatusOK, r)
Expand Down Expand Up @@ -159,11 +162,12 @@ type Assessment struct {
Stakeholders []Ref `json:"stakeholders"`
StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
// read only
Risk string `json:"risk"`
Confidence int `json:"confidence"`
Status string `json:"status"`
Thresholds assessment.Thresholds `json:"thresholds"`
RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"`
Risk string `json:"risk"`
Confidence int `json:"confidence"`
Status string `json:"status"`
Thresholds assessment.Thresholds `json:"thresholds"`
RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"`
QuestionnaireRequired bool `json:"questionnaireRequired"`
}

//
Expand Down

0 comments on commit a3bbd88

Please sign in to comment.