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 <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-04-14 18:09:01 +02:00
parent 58c2415275
commit 808fdffc9b
2 changed files with 14 additions and 2 deletions

View File

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

View File

@@ -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(