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:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user