Add risk proba and impact

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-31 09:49:35 +02:00
parent 835bab3113
commit 7d38882e1f
15 changed files with 421 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<a98cd84786da5d6229cb66bc24ad92d0>>
* @generated SignedSource<<cfd9a630fcbe359cd0b4db0e940dd564>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -19,7 +19,6 @@ export type MitigationListViewQuery$data = {
readonly organization: {
readonly id: string;
readonly mitigations?: {
readonly __id: string;
readonly edges: ReadonlyArray<{
readonly node: {
readonly category: string;
@@ -177,18 +176,6 @@ v5 = [
}
],
"storageKey": null
},
{
"kind": "ClientExtension",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__id",
"storageKey": null
}
]
}
],
v6 = [
@@ -314,6 +301,6 @@ return {
};
})();
(node as any).hash = "c2da6b42a986dd18cd18603c5f5809ad";
(node as any).hash = "6b2de4417fd7175dd9ccd34549e097b7";
export default node;

View File

@@ -14,6 +14,13 @@ import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import { useToast } from "@/hooks/use-toast";
import { PageTemplate } from "@/components/PageTemplate";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
const createRiskMutation = graphql`
mutation NewRiskViewCreateRiskMutation(
@@ -26,6 +33,8 @@ const createRiskMutation = graphql`
id
name
description
probability
impact
createdAt
updatedAt
}
@@ -39,11 +48,48 @@ export default function NewRiskView() {
const { organizationId } = useParams<{ organizationId: string }>();
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [probability, setProbability] = useState<string>("MEDIUM");
const [impact, setImpact] = useState<string>("MEDIUM");
const [isSubmitting, setIsSubmitting] = useState(false);
const { toast } = useToast();
const [commitMutation, isInFlight] = useMutation(createRiskMutation);
// Map string values to float values
const probabilityToFloat = (value: string): number => {
switch (value) {
case "VERY_LOW":
return 0.1;
case "LOW":
return 0.3;
case "MEDIUM":
return 0.5;
case "HIGH":
return 0.7;
case "VERY_HIGH":
return 0.9;
default:
return 0.5;
}
};
const impactToFloat = (value: string): number => {
switch (value) {
case "VERY_LOW":
return 0.1;
case "LOW":
return 0.3;
case "MEDIUM":
return 0.5;
case "HIGH":
return 0.7;
case "VERY_HIGH":
return 0.9;
default:
return 0.5;
}
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
@@ -62,6 +108,8 @@ export default function NewRiskView() {
organizationId: organizationId!,
name,
description,
probability: probabilityToFloat(probability),
impact: impactToFloat(impact),
};
commitMutation({
@@ -141,6 +189,40 @@ export default function NewRiskView() {
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="probability">Probability</Label>
<Select value={probability} onValueChange={setProbability}>
<SelectTrigger id="probability">
<SelectValue placeholder="Select probability" />
</SelectTrigger>
<SelectContent>
<SelectItem value="VERY_LOW">Very Low</SelectItem>
<SelectItem value="LOW">Low</SelectItem>
<SelectItem value="MEDIUM">Medium</SelectItem>
<SelectItem value="HIGH">High</SelectItem>
<SelectItem value="VERY_HIGH">Very High</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="impact">Impact</Label>
<Select value={impact} onValueChange={setImpact}>
<SelectTrigger id="impact">
<SelectValue placeholder="Select impact" />
</SelectTrigger>
<SelectContent>
<SelectItem value="VERY_LOW">Very Low</SelectItem>
<SelectItem value="LOW">Low</SelectItem>
<SelectItem value="MEDIUM">Medium</SelectItem>
<SelectItem value="HIGH">High</SelectItem>
<SelectItem value="VERY_HIGH">Very High</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="flex justify-end gap-3">
<Button
type="button"

View File

@@ -71,6 +71,8 @@ const riskListFragment = graphql`
node {
id
name
probability
impact
description
createdAt
updatedAt
@@ -275,6 +277,12 @@ function RiskListViewContent({
<th className="h-12 px-4 text-left align-middle font-medium text-muted-foreground">
Description
</th>
<th className="h-12 px-4 text-left align-middle font-medium text-muted-foreground">
Probability
</th>
<th className="h-12 px-4 text-left align-middle font-medium text-muted-foreground">
Impact %
</th>
<th className="h-12 px-4 text-left align-middle font-medium text-muted-foreground">
Actions
</th>
@@ -284,7 +292,7 @@ function RiskListViewContent({
{risks.length === 0 ? (
<tr className="border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted">
<td
colSpan={3}
colSpan={5}
className="text-center p-4 align-middle text-muted-foreground"
>
No risks found. Create a new risk to get started.
@@ -300,6 +308,12 @@ function RiskListViewContent({
{risk.name}
</td>
<td className="p-4 align-middle">{risk.description}</td>
<td className="p-4 align-middle">
{(risk.probability * 100).toFixed(0)}%
</td>
<td className="p-4 align-middle">
{(risk.impact * 100).toFixed(0)}%
</td>
<td className="p-4 align-middle">
<Button
variant="ghost"

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<c3a526641ca53f4ef760eacadc5c3685>>
* @generated SignedSource<<6488a6430dca9def82544e0ac0ca0db8>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -11,8 +11,10 @@
import { ConcreteRequest } from 'relay-runtime';
export type CreateRiskInput = {
description: string;
impact: number;
name: string;
organizationId: string;
probability: number;
};
export type NewRiskViewCreateRiskMutation$variables = {
connections: ReadonlyArray<string>;
@@ -25,7 +27,9 @@ export type NewRiskViewCreateRiskMutation$data = {
readonly createdAt: string;
readonly description: string;
readonly id: string;
readonly impact: number;
readonly name: string;
readonly probability: number;
readonly updatedAt: string;
};
};
@@ -91,6 +95,20 @@ v3 = {
"name": "description",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "probability",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "impact",
"storageKey": null
},
{
"alias": null,
"args": null,
@@ -177,16 +195,16 @@ return {
]
},
"params": {
"cacheID": "ce3ac503734a6f0eb26f88813ed02858",
"cacheID": "345bb376e4168b3b964b8a7ffa4ccbb9",
"id": null,
"metadata": {},
"name": "NewRiskViewCreateRiskMutation",
"operationKind": "mutation",
"text": "mutation NewRiskViewCreateRiskMutation(\n $input: CreateRiskInput!\n) {\n createRisk(input: $input) {\n riskEdge {\n node {\n id\n name\n description\n createdAt\n updatedAt\n }\n }\n }\n}\n"
"text": "mutation NewRiskViewCreateRiskMutation(\n $input: CreateRiskInput!\n) {\n createRisk(input: $input) {\n riskEdge {\n node {\n id\n name\n description\n probability\n impact\n createdAt\n updatedAt\n }\n }\n }\n}\n"
}
};
})();
(node as any).hash = "c0d8d1f046ed41c7a429c54b32358d3f";
(node as any).hash = "3cf30aab7c80cc9308343c6ec1577c5a";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<56b70bbecd785111cec0e7ff6ec2c226>>
* @generated SignedSource<<e9f2db8dc7c26cc332a75299317684b7>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -186,6 +186,20 @@ return {
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "probability",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "impact",
"storageKey": null
},
{
"alias": null,
"args": null,
@@ -294,16 +308,16 @@ return {
]
},
"params": {
"cacheID": "ea3c50c98dea1cce588bbb0e8705cbc4",
"cacheID": "33b15ec024ff6f9963d539be971aef7b",
"id": null,
"metadata": {},
"name": "RiskListViewPaginationQuery",
"operationKind": "query",
"text": "query RiskListViewPaginationQuery(\n $after: CursorKey\n $before: CursorKey\n $first: Int\n $last: Int\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...RiskListView_risks_pbnwq\n id\n }\n}\n\nfragment RiskListView_risks_pbnwq on Organization {\n risks(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n description\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n id\n}\n"
"text": "query RiskListViewPaginationQuery(\n $after: CursorKey\n $before: CursorKey\n $first: Int\n $last: Int\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...RiskListView_risks_pbnwq\n id\n }\n}\n\nfragment RiskListView_risks_pbnwq on Organization {\n risks(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n probability\n impact\n description\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n id\n}\n"
}
};
})();
(node as any).hash = "4a665835c97d7b93725e8bbe708d7cfb";
(node as any).hash = "59f58f0b1c17242dea5e762b6337bf98";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<2812fb6e9c5db33d4c616daf9a11b012>>
* @generated SignedSource<<f8cd1d0374c4a6de2b577c7fcb35c984>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -188,6 +188,20 @@ return {
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "probability",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "impact",
"storageKey": null
},
{
"alias": null,
"args": null,
@@ -296,12 +310,12 @@ return {
]
},
"params": {
"cacheID": "7b0cab0d71217df4a49ea2245b2705a8",
"cacheID": "78d7871004210dec73a83511b147856f",
"id": null,
"metadata": {},
"name": "RiskListViewQuery",
"operationKind": "query",
"text": "query RiskListViewQuery(\n $organizationId: ID!\n $first: Int\n $after: CursorKey\n $last: Int\n $before: CursorKey\n) {\n organization: node(id: $organizationId) {\n __typename\n id\n ...RiskListView_risks_pbnwq\n }\n}\n\nfragment RiskListView_risks_pbnwq on Organization {\n risks(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n description\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n id\n}\n"
"text": "query RiskListViewQuery(\n $organizationId: ID!\n $first: Int\n $after: CursorKey\n $last: Int\n $before: CursorKey\n) {\n organization: node(id: $organizationId) {\n __typename\n id\n ...RiskListView_risks_pbnwq\n }\n}\n\nfragment RiskListView_risks_pbnwq on Organization {\n risks(first: $first, after: $after, last: $last, before: $before) {\n edges {\n node {\n id\n name\n probability\n impact\n description\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n id\n}\n"
}
};
})();

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<5cb8bd63e484e9c8d842ddf05618d475>>
* @generated SignedSource<<1d60fbe24f12a69953d5ade8fb94ec1e>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -19,7 +19,9 @@ export type RiskListView_risks$data = {
readonly createdAt: string;
readonly description: string;
readonly id: string;
readonly impact: number;
readonly name: string;
readonly probability: number;
readonly updatedAt: string;
};
}>;
@@ -137,6 +139,20 @@ return {
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "probability",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "impact",
"storageKey": null
},
{
"alias": null,
"args": null,
@@ -239,6 +255,6 @@ return {
};
})();
(node as any).hash = "4a665835c97d7b93725e8bbe708d7cfb";
(node as any).hash = "59f58f0b1c17242dea5e762b6337bf98";
export default node;

View File

@@ -0,0 +1,7 @@
ALTER TABLE risks
ADD COLUMN probability REAL NOT NULL DEFAULT 0.0,
ADD COLUMN impact REAL NOT NULL DEFAULT 0.0;
ALTER TABLE risks
ALTER COLUMN probability DROP DEFAULT,
ALTER COLUMN impact DROP DEFAULT;

View File

@@ -32,6 +32,8 @@ type (
OrganizationID gid.GID
Name string
Description string
Probability float64
Impact float64
CreatedAt time.Time
UpdatedAt time.Time
}
@@ -61,6 +63,8 @@ SELECT
organization_id,
name,
description,
probability,
impact,
created_at,
updated_at
FROM risks
@@ -100,6 +104,8 @@ SELECT
organization_id,
name,
description,
probability,
impact,
created_at,
updated_at
FROM risks
@@ -133,8 +139,8 @@ func (r *Risk) Insert(
scope Scoper,
) error {
q := `
INSERT INTO risks (id, tenant_id, organization_id, name, description, created_at, updated_at)
VALUES (@id, @tenant_id, @organization_id, @name, @description, @created_at, @updated_at)
INSERT INTO risks (id, tenant_id, organization_id, name, description, probability, impact, created_at, updated_at)
VALUES (@id, @tenant_id, @organization_id, @name, @description, @probability, @impact, @created_at, @updated_at)
`
args := pgx.StrictNamedArgs{
@@ -143,6 +149,8 @@ VALUES (@id, @tenant_id, @organization_id, @name, @description, @created_at, @up
"organization_id": r.OrganizationID,
"name": r.Name,
"description": r.Description,
"probability": r.Probability,
"impact": r.Impact,
"created_at": r.CreatedAt,
"updated_at": r.UpdatedAt,
}
@@ -161,6 +169,8 @@ UPDATE risks
SET
name = @name,
description = @description,
probability = @probability,
impact = @impact,
updated_at = @updated_at
WHERE %s
AND tenant_id = @tenant_id
@@ -170,6 +180,8 @@ WHERE %s
args := pgx.StrictNamedArgs{
"name": r.Name,
"description": r.Description,
"probability": r.Probability,
"impact": r.Impact,
"updated_at": r.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())

View File

@@ -34,12 +34,16 @@ type (
OrganizationID gid.GID
Name string
Description string
Probability float64
Impact float64
}
UpdateRiskRequest struct {
ID gid.GID
Name *string
Description *string
Probability *float64
Impact *float64
}
)
@@ -58,6 +62,8 @@ func (s RiskService) Create(
OrganizationID: req.OrganizationID,
Name: req.Name,
Description: req.Description,
Probability: req.Probability,
Impact: req.Impact,
CreatedAt: now,
UpdatedAt: now,
}
@@ -117,6 +123,16 @@ func (s RiskService) Update(
risk.Description = *req.Description
}
if req.Probability != nil {
risk.Probability = *req.Probability
}
if req.Impact != nil {
risk.Impact = *req.Impact
}
risk.UpdatedAt = time.Now()
if err := risk.Update(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot update risk: %w", err)
}

View File

@@ -515,6 +515,8 @@ type Risk implements Node {
id: ID!
name: String!
description: String!
probability: Float!
impact: Float!
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -855,12 +857,16 @@ input CreateRiskInput {
organizationId: ID!
name: String!
description: String!
probability: Float!
impact: Float!
}
input UpdateRiskInput {
id: ID!
name: String
description: String
probability: Float
impact: Float
}
input DeleteRiskInput {

View File

@@ -346,7 +346,9 @@ type ComplexityRoot struct {
CreatedAt func(childComplexity int) int
Description func(childComplexity int) int
ID func(childComplexity int) int
Impact func(childComplexity int) int
Name func(childComplexity int) int
Probability func(childComplexity int) int
UpdatedAt func(childComplexity int) int
}
@@ -1824,6 +1826,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Risk.ID(childComplexity), true
case "Risk.impact":
if e.complexity.Risk.Impact == nil {
break
}
return e.complexity.Risk.Impact(childComplexity), true
case "Risk.name":
if e.complexity.Risk.Name == nil {
break
@@ -1831,6 +1840,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Risk.Name(childComplexity), true
case "Risk.probability":
if e.complexity.Risk.Probability == nil {
break
}
return e.complexity.Risk.Probability(childComplexity), true
case "Risk.updatedAt":
if e.complexity.Risk.UpdatedAt == nil {
break
@@ -2912,6 +2928,8 @@ type Risk implements Node {
id: ID!
name: String!
description: String!
probability: Float!
impact: Float!
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -3252,12 +3270,16 @@ input CreateRiskInput {
organizationId: ID!
name: String!
description: String!
probability: Float!
impact: Float!
}
input UpdateRiskInput {
id: ID!
name: String
description: String
probability: Float
impact: Float
}
input DeleteRiskInput {
@@ -13082,6 +13104,94 @@ func (ec *executionContext) fieldContext_Risk_description(_ context.Context, fie
return fc, nil
}
func (ec *executionContext) _Risk_probability(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_probability(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return obj.Probability, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(float64)
fc.Result = res
return ec.marshalNFloat2float64(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Risk_probability(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Risk",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Float does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Risk_impact(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_impact(ctx, field)
if err != nil {
return graphql.Null
}
ctx = graphql.WithFieldContext(ctx, fc)
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return obj.Impact, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.(float64)
fc.Result = res
return ec.marshalNFloat2float64(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Risk_impact(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Risk",
Field: field,
IsMethod: false,
IsResolver: false,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
return nil, errors.New("field of type Float does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Risk_createdAt(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_createdAt(ctx, field)
if err != nil {
@@ -13363,6 +13473,10 @@ func (ec *executionContext) fieldContext_RiskEdge_node(_ context.Context, field
return ec.fieldContext_Risk_name(ctx, field)
case "description":
return ec.fieldContext_Risk_description(ctx, field)
case "probability":
return ec.fieldContext_Risk_probability(ctx, field)
case "impact":
return ec.fieldContext_Risk_impact(ctx, field)
case "createdAt":
return ec.fieldContext_Risk_createdAt(ctx, field)
case "updatedAt":
@@ -14520,6 +14634,10 @@ func (ec *executionContext) fieldContext_UpdateRiskPayload_risk(_ context.Contex
return ec.fieldContext_Risk_name(ctx, field)
case "description":
return ec.fieldContext_Risk_description(ctx, field)
case "probability":
return ec.fieldContext_Risk_probability(ctx, field)
case "impact":
return ec.fieldContext_Risk_impact(ctx, field)
case "createdAt":
return ec.fieldContext_Risk_createdAt(ctx, field)
case "updatedAt":
@@ -18327,7 +18445,7 @@ func (ec *executionContext) unmarshalInputCreateRiskInput(ctx context.Context, o
asMap[k] = v
}
fieldsInOrder := [...]string{"organizationId", "name", "description"}
fieldsInOrder := [...]string{"organizationId", "name", "description", "probability", "impact"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -18355,6 +18473,20 @@ func (ec *executionContext) unmarshalInputCreateRiskInput(ctx context.Context, o
return it, err
}
it.Description = data
case "probability":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("probability"))
data, err := ec.unmarshalNFloat2float64(ctx, v)
if err != nil {
return it, err
}
it.Probability = data
case "impact":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("impact"))
data, err := ec.unmarshalNFloat2float64(ctx, v)
if err != nil {
return it, err
}
it.Impact = data
}
}
@@ -19432,7 +19564,7 @@ func (ec *executionContext) unmarshalInputUpdateRiskInput(ctx context.Context, o
asMap[k] = v
}
fieldsInOrder := [...]string{"id", "name", "description"}
fieldsInOrder := [...]string{"id", "name", "description", "probability", "impact"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -19460,6 +19592,20 @@ func (ec *executionContext) unmarshalInputUpdateRiskInput(ctx context.Context, o
return it, err
}
it.Description = data
case "probability":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("probability"))
data, err := ec.unmarshalOFloat2ᚖfloat64(ctx, v)
if err != nil {
return it, err
}
it.Probability = data
case "impact":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("impact"))
data, err := ec.unmarshalOFloat2ᚖfloat64(ctx, v)
if err != nil {
return it, err
}
it.Impact = data
}
}
@@ -22636,6 +22782,16 @@ func (ec *executionContext) _Risk(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "probability":
out.Values[i] = ec._Risk_probability(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "impact":
out.Values[i] = ec._Risk_impact(ctx, field, obj)
if out.Values[i] == graphql.Null {
out.Invalids++
}
case "createdAt":
out.Values[i] = ec._Risk_createdAt(ctx, field, obj)
if out.Values[i] == graphql.Null {
@@ -24786,6 +24942,21 @@ var (
}
)
func (ec *executionContext) unmarshalNFloat2float64(ctx context.Context, v any) (float64, error) {
res, err := graphql.UnmarshalFloatContext(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler {
res := graphql.MarshalFloatContext(v)
if res == graphql.Null {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
}
return graphql.WrapContextMarshaler(ctx, res)
}
func (ec *executionContext) marshalNFramework2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐFramework(ctx context.Context, sel ast.SelectionSet, v *types.Framework) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
@@ -26640,6 +26811,22 @@ func (ec *executionContext) unmarshalOEvidenceOrder2ᚖgithubᚗcomᚋgetprobo
return &res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) unmarshalOFloat2ᚖfloat64(ctx context.Context, v any) (*float64, error) {
if v == nil {
return nil, nil
}
res, err := graphql.UnmarshalFloatContext(ctx, v)
return &res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalOFloat2ᚖfloat64(ctx context.Context, sel ast.SelectionSet, v *float64) graphql.Marshaler {
if v == nil {
return graphql.Null
}
res := graphql.MarshalFloatContext(*v)
return graphql.WrapContextMarshaler(ctx, res)
}
func (ec *executionContext) unmarshalOFrameworkOrder2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐFrameworkOrderBy(ctx context.Context, v any) (*types.FrameworkOrderBy, error) {
if v == nil {
return nil, nil

View File

@@ -48,6 +48,8 @@ func NewRisk(r *coredata.Risk) *Risk {
ID: r.ID,
Name: r.Name,
Description: r.Description,
Probability: r.Probability,
Impact: r.Impact,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
}

View File

@@ -117,6 +117,8 @@ type CreateRiskInput struct {
OrganizationID gid.GID `json:"organizationId"`
Name string `json:"name"`
Description string `json:"description"`
Probability float64 `json:"probability"`
Impact float64 `json:"impact"`
}
type CreateRiskPayload struct {
@@ -424,6 +426,8 @@ type Risk struct {
ID gid.GID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Probability float64 `json:"probability"`
Impact float64 `json:"impact"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -538,9 +542,11 @@ type UpdatePolicyPayload struct {
}
type UpdateRiskInput struct {
ID gid.GID `json:"id"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
ID gid.GID `json:"id"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Probability *float64 `json:"probability,omitempty"`
Impact *float64 `json:"impact,omitempty"`
}
type UpdateRiskPayload struct {

View File

@@ -537,6 +537,8 @@ func (r *mutationResolver) CreateRisk(ctx context.Context, input types.CreateRis
OrganizationID: input.OrganizationID,
Name: input.Name,
Description: input.Description,
Probability: input.Probability,
Impact: input.Impact,
},
)
if err != nil {
@@ -558,6 +560,8 @@ func (r *mutationResolver) UpdateRisk(ctx context.Context, input types.UpdateRis
ID: input.ID,
Name: input.Name,
Description: input.Description,
Probability: input.Probability,
Impact: input.Impact,
},
)
if err != nil {