fix(risk-control): fix null safety and magic numbers in aggregates
This commit is contained in:
parent
0721965af4
commit
22d0427df9
@ -53,8 +53,8 @@ public class RiskRule : Entity<long>, IAggregateRoot
|
||||
UpdatedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public T GetConfig<T>() where T : class
|
||||
public T? GetConfig<T>() where T : class
|
||||
{
|
||||
return System.Text.Json.JsonSerializer.Deserialize<T>(ConfigJson)!;
|
||||
return System.Text.Json.JsonSerializer.Deserialize<T>(ConfigJson);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,11 +43,14 @@ public class RiskScore : Entity<long>, IAggregateRoot
|
||||
RiskLevel = RiskLevel.Low;
|
||||
}
|
||||
|
||||
private static readonly int HIGH_THRESHOLD = 70;
|
||||
private static readonly int MEDIUM_THRESHOLD = 30;
|
||||
|
||||
private void RecalculateScore()
|
||||
{
|
||||
TotalScore = _factors.Sum(f => f.Points);
|
||||
RiskLevel = TotalScore >= 70 ? RiskLevel.High :
|
||||
TotalScore >= 30 ? RiskLevel.Medium :
|
||||
RiskLevel = TotalScore >= HIGH_THRESHOLD ? RiskLevel.High :
|
||||
TotalScore >= MEDIUM_THRESHOLD ? RiskLevel.Medium :
|
||||
RiskLevel.Low;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user