7
pkg/coredata/migrations/20250331T093100Z.sql
Normal file
7
pkg/coredata/migrations/20250331T093100Z.sql
Normal 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;
|
||||
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user