Add note to risk

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-04-24 17:47:39 -07:00
parent 60cdc8f19f
commit cece072619
17 changed files with 254 additions and 66 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE risks ADD COLUMN comments TEXT DEFAULT '';
ALTER TABLE risks ALTER COLUMN comments DROP DEFAULT;

View File

@@ -0,0 +1 @@
ALTER TABLE risks RENAME COLUMN comments TO note;

View File

@@ -34,6 +34,7 @@ type (
Description string `db:"description"`
Category string `db:"category"`
Treatment RiskTreatment `db:"treatment"`
Note string `db:"note"`
OwnerID *gid.GID `db:"owner_id"`
InherentLikelihood int `db:"inherent_likelihood"`
InherentImpact int `db:"inherent_impact"`
@@ -80,6 +81,7 @@ WITH rsks AS (
r.category,
r.owner_id,
r.treatment,
r.note,
r.inherent_likelihood,
r.inherent_impact,
r.residual_likelihood,
@@ -101,6 +103,7 @@ SELECT
category,
owner_id,
treatment,
note,
inherent_likelihood,
inherent_impact,
residual_likelihood,
@@ -147,6 +150,7 @@ SELECT
description,
owner_id,
treatment,
note,
inherent_likelihood,
inherent_impact,
residual_likelihood,
@@ -194,6 +198,7 @@ SELECT
category,
owner_id,
treatment,
note,
inherent_likelihood,
inherent_impact,
residual_likelihood,
@@ -231,8 +236,8 @@ func (r *Risk) Insert(
scope Scoper,
) error {
q := `
INSERT INTO risks (id, tenant_id, organization_id, name, description, category, owner_id, treatment, inherent_likelihood, inherent_impact, residual_likelihood, residual_impact, created_at, updated_at)
VALUES (@id, @tenant_id, @organization_id, @name, @description, @category, @owner_id, @treatment, @inherent_likelihood, @inherent_impact, @residual_likelihood, @residual_impact, @created_at, @updated_at)
INSERT INTO risks (id, tenant_id, organization_id, name, description, category, owner_id, treatment, note, inherent_likelihood, inherent_impact, residual_likelihood, residual_impact, created_at, updated_at)
VALUES (@id, @tenant_id, @organization_id, @name, @description, @category, @owner_id, @treatment, @note, @inherent_likelihood, @inherent_impact, @residual_likelihood, @residual_impact, @created_at, @updated_at)
`
args := pgx.StrictNamedArgs{
@@ -244,6 +249,7 @@ VALUES (@id, @tenant_id, @organization_id, @name, @description, @category, @owne
"category": r.Category,
"owner_id": r.OwnerID,
"treatment": r.Treatment,
"note": r.Note,
"inherent_likelihood": r.InherentLikelihood,
"inherent_impact": r.InherentImpact,
"residual_likelihood": r.ResidualLikelihood,
@@ -273,6 +279,7 @@ SET
residual_likelihood = @residual_likelihood,
residual_impact = @residual_impact,
category = @category,
note = @note,
updated_at = @updated_at
WHERE %s
AND id = @risk_id
@@ -286,6 +293,7 @@ WHERE %s
"category": r.Category,
"owner_id": r.OwnerID,
"treatment": r.Treatment,
"note": r.Note,
"inherent_likelihood": r.InherentLikelihood,
"inherent_impact": r.InherentImpact,
"residual_likelihood": r.ResidualLikelihood,

View File

@@ -41,6 +41,7 @@ type (
InherentImpact int
ResidualLikelihood *int
ResidualImpact *int
Note *string
}
UpdateRiskRequest struct {
@@ -54,6 +55,7 @@ type (
InherentImpact *int
ResidualLikelihood *int
ResidualImpact *int
Note *string
}
)
@@ -184,6 +186,10 @@ func (s RiskService) Create(
UpdatedAt: now,
}
if req.Note != nil {
risk.Note = *req.Note
}
if req.ResidualLikelihood != nil {
risk.ResidualLikelihood = *req.ResidualLikelihood
}
@@ -275,6 +281,10 @@ func (s RiskService) Update(
risk.Category = *req.Category
}
if req.Note != nil {
risk.Note = *req.Note
}
risk.UpdatedAt = time.Now()
if err := risk.Update(ctx, conn, s.svc.scope); err != nil {

View File

@@ -678,6 +678,7 @@ type Risk implements Node {
residualLikelihood: Int!
residualImpact: Int!
residualSeverity: Int!
note: String!
owner: People @goField(forceResolver: true)
@@ -1159,6 +1160,7 @@ input CreateRiskInput {
inherentImpact: Int!
residualLikelihood: Int
residualImpact: Int
note: String
}
input UpdateRiskInput {
@@ -1172,6 +1174,7 @@ input UpdateRiskInput {
inherentImpact: Int
residualLikelihood: Int
residualImpact: Int
note: String
}
input DeleteRiskInput {

View File

@@ -448,6 +448,7 @@ type ComplexityRoot struct {
InherentSeverity func(childComplexity int) int
Mesures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MesureOrderBy) int
Name func(childComplexity int) int
Note func(childComplexity int) int
Owner func(childComplexity int) int
Policies func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PolicyOrderBy) int
ResidualImpact func(childComplexity int) int
@@ -2474,6 +2475,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Risk.Name(childComplexity), true
case "Risk.note":
if e.complexity.Risk.Note == nil {
break
}
return e.complexity.Risk.Note(childComplexity), true
case "Risk.owner":
if e.complexity.Risk.Owner == nil {
break
@@ -4062,6 +4070,7 @@ type Risk implements Node {
residualLikelihood: Int!
residualImpact: Int!
residualSeverity: Int!
note: String!
owner: People @goField(forceResolver: true)
@@ -4543,6 +4552,7 @@ input CreateRiskInput {
inherentImpact: Int!
residualLikelihood: Int
residualImpact: Int
note: String
}
input UpdateRiskInput {
@@ -4556,6 +4566,7 @@ input UpdateRiskInput {
inherentImpact: Int
residualLikelihood: Int
residualImpact: Int
note: String
}
input DeleteRiskInput {
@@ -18405,6 +18416,50 @@ func (ec *executionContext) fieldContext_Risk_residualSeverity(_ context.Context
return fc, nil
}
func (ec *executionContext) _Risk_note(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_note(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.Note, 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.(string)
fc.Result = res
return ec.marshalNString2string(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Risk_note(_ 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 String does not have child fields")
},
}
return fc, nil
}
func (ec *executionContext) _Risk_owner(ctx context.Context, field graphql.CollectedField, obj *types.Risk) (ret graphql.Marshaler) {
fc, err := ec.fieldContext_Risk_owner(ctx, field)
if err != nil {
@@ -18942,6 +18997,8 @@ func (ec *executionContext) fieldContext_RiskEdge_node(_ context.Context, field
return ec.fieldContext_Risk_residualImpact(ctx, field)
case "residualSeverity":
return ec.fieldContext_Risk_residualSeverity(ctx, field)
case "note":
return ec.fieldContext_Risk_note(ctx, field)
case "owner":
return ec.fieldContext_Risk_owner(ctx, field)
case "mesures":
@@ -20131,6 +20188,8 @@ func (ec *executionContext) fieldContext_UpdateRiskPayload_risk(_ context.Contex
return ec.fieldContext_Risk_residualImpact(ctx, field)
case "residualSeverity":
return ec.fieldContext_Risk_residualSeverity(ctx, field)
case "note":
return ec.fieldContext_Risk_note(ctx, field)
case "owner":
return ec.fieldContext_Risk_owner(ctx, field)
case "mesures":
@@ -26062,7 +26121,7 @@ func (ec *executionContext) unmarshalInputCreateRiskInput(ctx context.Context, o
asMap[k] = v
}
fieldsInOrder := [...]string{"organizationId", "name", "description", "category", "ownerId", "treatment", "inherentLikelihood", "inherentImpact", "residualLikelihood", "residualImpact"}
fieldsInOrder := [...]string{"organizationId", "name", "description", "category", "ownerId", "treatment", "inherentLikelihood", "inherentImpact", "residualLikelihood", "residualImpact", "note"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -26139,6 +26198,13 @@ func (ec *executionContext) unmarshalInputCreateRiskInput(ctx context.Context, o
return it, err
}
it.ResidualImpact = data
case "note":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("note"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Note = data
}
}
@@ -27668,7 +27734,7 @@ func (ec *executionContext) unmarshalInputUpdateRiskInput(ctx context.Context, o
asMap[k] = v
}
fieldsInOrder := [...]string{"id", "name", "description", "category", "ownerId", "treatment", "inherentLikelihood", "inherentImpact", "residualLikelihood", "residualImpact"}
fieldsInOrder := [...]string{"id", "name", "description", "category", "ownerId", "treatment", "inherentLikelihood", "inherentImpact", "residualLikelihood", "residualImpact", "note"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
@@ -27745,6 +27811,13 @@ func (ec *executionContext) unmarshalInputUpdateRiskInput(ctx context.Context, o
return it, err
}
it.ResidualImpact = data
case "note":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("note"))
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
it.Note = data
}
}
@@ -32067,6 +32140,11 @@ func (ec *executionContext) _Risk(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
}
case "note":
out.Values[i] = ec._Risk_note(ctx, field, obj)
if out.Values[i] == graphql.Null {
atomic.AddUint32(&out.Invalids, 1)
}
case "owner":
field := field

View File

@@ -58,5 +58,6 @@ func NewRisk(r *coredata.Risk) *Risk {
Category: r.Category,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
Note: r.Note,
}
}

View File

@@ -183,6 +183,7 @@ type CreateRiskInput struct {
InherentImpact int `json:"inherentImpact"`
ResidualLikelihood *int `json:"residualLikelihood,omitempty"`
ResidualImpact *int `json:"residualImpact,omitempty"`
Note *string `json:"note,omitempty"`
}
type CreateRiskMesureMappingInput struct {
@@ -608,6 +609,7 @@ type Risk struct {
ResidualLikelihood int `json:"residualLikelihood"`
ResidualImpact int `json:"residualImpact"`
ResidualSeverity int `json:"residualSeverity"`
Note string `json:"note"`
Owner *People `json:"owner,omitempty"`
Mesures *MesureConnection `json:"mesures"`
Policies *PolicyConnection `json:"policies"`
@@ -736,6 +738,7 @@ type UpdateRiskInput struct {
InherentImpact *int `json:"inherentImpact,omitempty"`
ResidualLikelihood *int `json:"residualLikelihood,omitempty"`
ResidualImpact *int `json:"residualImpact,omitempty"`
Note *string `json:"note,omitempty"`
}
type UpdateRiskPayload struct {

View File

@@ -749,6 +749,7 @@ func (r *mutationResolver) CreateRisk(ctx context.Context, input types.CreateRis
InherentImpact: input.InherentImpact,
ResidualLikelihood: input.ResidualLikelihood,
ResidualImpact: input.ResidualImpact,
Note: input.Note,
},
)
if err != nil {
@@ -777,6 +778,7 @@ func (r *mutationResolver) UpdateRisk(ctx context.Context, input types.UpdateRis
InherentImpact: input.InherentImpact,
ResidualLikelihood: input.ResidualLikelihood,
ResidualImpact: input.ResidualImpact,
Note: input.Note,
},
)
if err != nil {