From 808fdffc9b9a0870bc33880ec8c7f1490aaa1275 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Tue, 14 Apr 2026 18:09:01 +0200 Subject: [PATCH] Return computed risk scores after update Add inherentRiskScore and residualRiskScore to the mutation fragment so the Relay store gets updated scores. On the backend, use RETURNING to get the recomputed values from the database generated columns. Signed-off-by: Sacha Al Himdani --- apps/console/src/hooks/forms/useRiskForm.tsx | 4 ++++ pkg/coredata/risk.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/console/src/hooks/forms/useRiskForm.tsx b/apps/console/src/hooks/forms/useRiskForm.tsx index 3018db957..144f4de99 100644 --- a/apps/console/src/hooks/forms/useRiskForm.tsx +++ b/apps/console/src/hooks/forms/useRiskForm.tsx @@ -42,6 +42,10 @@ const RiskFragment = graphql` # eslint-disable-next-line relay/unused-fields residualImpact # eslint-disable-next-line relay/unused-fields + inherentRiskScore + # eslint-disable-next-line relay/unused-fields + residualRiskScore + # eslint-disable-next-line relay/unused-fields note owner { id diff --git a/pkg/coredata/risk.go b/pkg/coredata/risk.go index 6e7ad792c..e9391c185 100644 --- a/pkg/coredata/risk.go +++ b/pkg/coredata/risk.go @@ -506,6 +506,7 @@ SET WHERE %s AND id = @risk_id AND snapshot_id IS NULL +RETURNING inherent_risk_score, residual_risk_score ` q = fmt.Sprintf(q, scope.SQLFragment()) @@ -525,8 +526,15 @@ WHERE %s } maps.Copy(args, scope.SQLArguments()) - _, err := conn.Exec(ctx, q, args) - return err + err := conn.QueryRow(ctx, q, args).Scan( + &r.InherentRiskScore, + &r.ResidualRiskScore, + ) + if err != nil { + return fmt.Errorf("cannot update risk: %w", err) + } + + return nil } func (r *Risk) Delete(