Add controls snapshots

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-27 09:39:28 +02:00
parent 37fe6f4b00
commit 05b9672a03
27 changed files with 3679 additions and 68 deletions

View File

@@ -1300,6 +1300,14 @@ type Control implements Node {
orderBy: AuditOrder
): AuditConnection! @goField(forceResolver: true)
snapshots(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: SnapshotOrder
): SnapshotConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
}
@@ -1537,6 +1545,16 @@ type Snapshot implements Node {
name: String!
description: String
type: SnapshotsType!
controls(
first: Int
after: CursorKey
last: Int
before: CursorKey
orderBy: ControlOrder
filter: ControlFilter
): ControlConnection! @goField(forceResolver: true)
createdAt: Datetime!
}
@@ -1982,6 +2000,12 @@ type Mutation {
deleteControlAuditMapping(
input: DeleteControlAuditMappingInput!
): DeleteControlAuditMappingPayload!
createControlSnapshotMapping(
input: CreateControlSnapshotMappingInput!
): CreateControlSnapshotMappingPayload!
deleteControlSnapshotMapping(
input: DeleteControlSnapshotMappingInput!
): DeleteControlSnapshotMappingPayload!
# Task mutations
createTask(input: CreateTaskInput!): CreateTaskPayload!
@@ -2396,6 +2420,16 @@ input DeleteControlAuditMappingInput {
auditId: ID!
}
input CreateControlSnapshotMappingInput {
controlId: ID!
snapshotId: ID!
}
input DeleteControlSnapshotMappingInput {
controlId: ID!
snapshotId: ID!
}
input CreateRiskInput {
organizationId: ID!
name: String!
@@ -2865,6 +2899,16 @@ type DeleteControlAuditMappingPayload {
deletedAuditId: ID!
}
type CreateControlSnapshotMappingPayload {
controlEdge: ControlEdge!
snapshotEdge: SnapshotEdge!
}
type DeleteControlSnapshotMappingPayload {
deletedControlId: ID!
deletedSnapshotId: ID!
}
type CreateRiskPayload {
riskEdge: RiskEdge!
}

File diff suppressed because it is too large Load Diff

View File

@@ -178,6 +178,7 @@ type Control struct {
Measures *MeasureConnection `json:"measures"`
Documents *DocumentConnection `json:"documents"`
Audits *AuditConnection `json:"audits"`
Snapshots *SnapshotConnection `json:"snapshots"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
@@ -284,6 +285,16 @@ type CreateControlPayload struct {
ControlEdge *ControlEdge `json:"controlEdge"`
}
type CreateControlSnapshotMappingInput struct {
ControlID gid.GID `json:"controlId"`
SnapshotID gid.GID `json:"snapshotId"`
}
type CreateControlSnapshotMappingPayload struct {
ControlEdge *ControlEdge `json:"controlEdge"`
SnapshotEdge *SnapshotEdge `json:"snapshotEdge"`
}
type CreateDatumInput struct {
OrganizationID gid.GID `json:"organizationId"`
Name string `json:"name"`
@@ -622,6 +633,16 @@ type DeleteControlPayload struct {
DeletedControlID gid.GID `json:"deletedControlId"`
}
type DeleteControlSnapshotMappingInput struct {
ControlID gid.GID `json:"controlId"`
SnapshotID gid.GID `json:"snapshotId"`
}
type DeleteControlSnapshotMappingPayload struct {
DeletedControlID gid.GID `json:"deletedControlId"`
DeletedSnapshotID gid.GID `json:"deletedSnapshotId"`
}
type DeleteDatumInput struct {
DatumID gid.GID `json:"datumId"`
}
@@ -1231,6 +1252,7 @@ type Snapshot struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Type coredata.SnapshotsType `json:"type"`
Controls *ControlConnection `json:"controls"`
CreatedAt time.Time `json:"createdAt"`
}

View File

@@ -389,6 +389,32 @@ func (r *controlResolver) Audits(ctx context.Context, obj *types.Control, first
return types.NewAuditConnection(page, r, obj.ID), nil
}
// Snapshots is the resolver for the snapshots field.
func (r *controlResolver) Snapshots(ctx context.Context, obj *types.Control, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.SnapshotOrderBy) (*types.SnapshotConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.SnapshotOrderField]{
Field: coredata.SnapshotOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.SnapshotOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := prb.Snapshots.ListForControlID(ctx, obj.ID, cursor)
if err != nil {
panic(fmt.Errorf("cannot list control snapshots: %w", err))
}
return types.NewSnapshotConnection(page, r, obj.ID), nil
}
// TotalCount is the resolver for the totalCount field.
func (r *controlConnectionResolver) TotalCount(ctx context.Context, obj *types.ControlConnection) (int, error) {
prb := r.ProboService(ctx, obj.ParentID.TenantID())
@@ -1823,6 +1849,36 @@ func (r *mutationResolver) DeleteControlAuditMapping(ctx context.Context, input
}, nil
}
// CreateControlSnapshotMapping is the resolver for the createControlSnapshotMapping field.
func (r *mutationResolver) CreateControlSnapshotMapping(ctx context.Context, input types.CreateControlSnapshotMappingInput) (*types.CreateControlSnapshotMappingPayload, error) {
prb := r.ProboService(ctx, input.SnapshotID.TenantID())
control, snapshot, err := prb.Controls.CreateSnapshotMapping(ctx, input.ControlID, input.SnapshotID)
if err != nil {
panic(fmt.Errorf("cannot create control snapshot mapping: %w", err))
}
return &types.CreateControlSnapshotMappingPayload{
ControlEdge: types.NewControlEdge(control, coredata.ControlOrderFieldCreatedAt),
SnapshotEdge: types.NewSnapshotEdge(snapshot, coredata.SnapshotOrderFieldCreatedAt),
}, nil
}
// DeleteControlSnapshotMapping is the resolver for the deleteControlSnapshotMapping field.
func (r *mutationResolver) DeleteControlSnapshotMapping(ctx context.Context, input types.DeleteControlSnapshotMappingInput) (*types.DeleteControlSnapshotMappingPayload, error) {
prb := r.ProboService(ctx, input.SnapshotID.TenantID())
control, snapshot, err := prb.Controls.DeleteSnapshotMapping(ctx, input.ControlID, input.SnapshotID)
if err != nil {
panic(fmt.Errorf("cannot delete control snapshot mapping: %w", err))
}
return &types.DeleteControlSnapshotMappingPayload{
DeletedControlID: control.ID,
DeletedSnapshotID: snapshot.ID,
}, nil
}
// CreateTask is the resolver for the createTask field.
func (r *mutationResolver) CreateTask(ctx context.Context, input types.CreateTaskInput) (*types.CreateTaskPayload, error) {
prb := r.ProboService(ctx, input.MeasureID.TenantID())
@@ -3910,6 +3966,36 @@ func (r *snapshotResolver) Organization(ctx context.Context, obj *types.Snapshot
return types.NewOrganization(organization), nil
}
// Controls is the resolver for the controls field.
func (r *snapshotResolver) Controls(ctx context.Context, obj *types.Snapshot, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ControlOrderBy, filter *types.ControlFilter) (*types.ControlConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.ControlOrderField]{
Field: coredata.ControlOrderFieldCreatedAt,
Direction: page.OrderDirectionDesc,
}
if orderBy != nil {
pageOrderBy = page.OrderBy[coredata.ControlOrderField]{
Field: orderBy.Field,
Direction: orderBy.Direction,
}
}
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
var controlFilter = coredata.NewControlFilter(nil)
if filter != nil {
controlFilter = coredata.NewControlFilter(filter.Query)
}
page, err := prb.Controls.ListForSnapshotID(ctx, obj.ID, cursor, controlFilter)
if err != nil {
panic(fmt.Errorf("cannot list snapshot controls: %w", err))
}
return types.NewControlConnection(page, r, obj.ID, controlFilter), nil
}
// TotalCount is the resolver for the totalCount field.
func (r *snapshotConnectionResolver) TotalCount(ctx context.Context, obj *types.SnapshotConnection) (int, error) {
prb := r.ProboService(ctx, obj.ParentID.TenantID())