Add noncompliance snapshots
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
15
pkg/coredata/migrations/20250828T142256Z.sql
Normal file
15
pkg/coredata/migrations/20250828T142256Z.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
ALTER TABLE nonconformity_registries ADD COLUMN snapshot_id TEXT;
|
||||
ALTER TABLE nonconformity_registries ADD COLUMN source_id TEXT;
|
||||
|
||||
ALTER TABLE nonconformity_registries DROP CONSTRAINT IF EXISTS nonconformity_registries_audit_id_fkey;
|
||||
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_audit_id_fkey
|
||||
FOREIGN KEY (audit_id) REFERENCES audits(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_snapshot_id_fkey
|
||||
FOREIGN KEY (snapshot_id)
|
||||
REFERENCES snapshots(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_source_id_snapshot_id_key
|
||||
UNIQUE (source_id, snapshot_id);
|
||||
@@ -30,6 +30,8 @@ type (
|
||||
NonconformityRegistry struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
SnapshotID *gid.GID `db:"snapshot_id"`
|
||||
SourceID *gid.GID `db:"source_id"`
|
||||
ReferenceID string `db:"reference_id"`
|
||||
Description *string `db:"description"`
|
||||
AuditID gid.GID `db:"audit_id"`
|
||||
@@ -74,6 +76,8 @@ func (nr *NonconformityRegistry) LoadByID(
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
snapshot_id,
|
||||
source_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
@@ -119,6 +123,7 @@ func (nrs *NonconformityRegistries) CountByOrganizationID(
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
filter *NonconformityRegistryFilter,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
@@ -128,12 +133,14 @@ FROM
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
@@ -152,11 +159,14 @@ func (nrs *NonconformityRegistries) LoadByOrganizationID(
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[NonconformityRegistryOrderField],
|
||||
filter *NonconformityRegistryFilter,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
snapshot_id,
|
||||
source_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
@@ -175,12 +185,14 @@ WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, filter.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
@@ -287,6 +299,7 @@ SET
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
AND snapshot_id IS NULL
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
@@ -324,7 +337,7 @@ func (nr *NonconformityRegistry) Delete(
|
||||
DELETE FROM nonconformity_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
AND id = @id AND snapshot_id IS NULL
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
@@ -339,3 +352,64 @@ WHERE
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nrs NonconformityRegistries) Snapshot(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error {
|
||||
query := `
|
||||
INSERT INTO nonconformity_registries (
|
||||
id,
|
||||
tenant_id,
|
||||
snapshot_id,
|
||||
source_id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
date_identified,
|
||||
root_cause,
|
||||
corrective_action,
|
||||
owner_id,
|
||||
due_date,
|
||||
status,
|
||||
effectiveness_check,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
SELECT
|
||||
generate_gid(decode_base64_unpadded(@tenant_id), @nonconformity_registry_entity_type),
|
||||
@tenant_id,
|
||||
@snapshot_id,
|
||||
r.id,
|
||||
r.organization_id,
|
||||
r.reference_id,
|
||||
r.description,
|
||||
r.audit_id,
|
||||
r.date_identified,
|
||||
r.root_cause,
|
||||
r.corrective_action,
|
||||
r.owner_id,
|
||||
r.due_date,
|
||||
r.status,
|
||||
r.effectiveness_check,
|
||||
r.created_at,
|
||||
r.updated_at
|
||||
FROM nonconformity_registries r
|
||||
WHERE %s AND r.organization_id = @organization_id AND r.snapshot_id IS NULL
|
||||
`
|
||||
|
||||
query = fmt.Sprintf(query, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"snapshot_id": snapshotID,
|
||||
"organization_id": organizationID,
|
||||
"nonconformity_registry_entity_type": NonconformityRegistryEntityType,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, query, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert data snapshots: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
60
pkg/coredata/nonconformity_registry_filter.go
Normal file
60
pkg/coredata/nonconformity_registry_filter.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type (
|
||||
NonconformityRegistryFilter struct {
|
||||
snapshotID **gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func NewNonconformityRegistryFilter() *NonconformityRegistryFilter {
|
||||
return &NonconformityRegistryFilter{
|
||||
snapshotID: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNonconformityRegistryFilterBySnapshotID(snapshotID **gid.GID) *NonconformityRegistryFilter {
|
||||
return &NonconformityRegistryFilter{
|
||||
snapshotID: snapshotID,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *NonconformityRegistryFilter) SQLArguments() pgx.NamedArgs {
|
||||
args := pgx.NamedArgs{}
|
||||
|
||||
if f.snapshotID != nil && *f.snapshotID != nil {
|
||||
args["filter_snapshot_id"] = **f.snapshotID
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func (f *NonconformityRegistryFilter) SQLFragment() string {
|
||||
if f.snapshotID == nil {
|
||||
return "TRUE"
|
||||
}
|
||||
|
||||
if *f.snapshotID == nil {
|
||||
return "snapshot_id IS NULL"
|
||||
} else {
|
||||
return "snapshot_id = @filter_snapshot_id"
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ func GetSnapshottable(snapshotType SnapshotsType) (Snapshottable, error) {
|
||||
switch snapshotType {
|
||||
case SnapshotsTypeData:
|
||||
return Data{}, nil
|
||||
case SnapshotsTypeNonConformityRegistries:
|
||||
return NonconformityRegistries{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported snapshot type: %s", snapshotType)
|
||||
}
|
||||
|
||||
@@ -221,13 +221,14 @@ func (s NonconformityRegistryService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.NonconformityRegistryOrderField],
|
||||
filter *coredata.NonconformityRegistryFilter,
|
||||
) (*page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField], error) {
|
||||
var registries coredata.NonconformityRegistries
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
|
||||
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor, filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load nonconformity registries: %w", err)
|
||||
}
|
||||
@@ -246,6 +247,7 @@ func (s NonconformityRegistryService) ListForOrganizationID(
|
||||
func (s NonconformityRegistryService) CountForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
filter *coredata.NonconformityRegistryFilter,
|
||||
) (int, error) {
|
||||
var count int
|
||||
|
||||
@@ -253,7 +255,7 @@ func (s NonconformityRegistryService) CountForOrganizationID(
|
||||
ctx,
|
||||
func(conn pg.Conn) (err error) {
|
||||
registries := coredata.NonconformityRegistries{}
|
||||
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID, filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
@@ -1106,6 +1106,10 @@ input DatumFilter {
|
||||
snapshotId: ID
|
||||
}
|
||||
|
||||
input NonconformityRegistryFilter {
|
||||
snapshotId: ID
|
||||
}
|
||||
|
||||
# Core Types
|
||||
type TrustCenter implements Node {
|
||||
id: ID!
|
||||
@@ -1245,6 +1249,7 @@ type Organization implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: NonconformityRegistryOrder
|
||||
filter: NonconformityRegistryFilter
|
||||
): NonconformityRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
complianceRegistries(
|
||||
|
||||
@@ -881,7 +881,7 @@ type ComplexityRoot struct {
|
||||
LogoURL func(childComplexity int) int
|
||||
Measures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MeasureOrderBy, filter *types.MeasureFilter) int
|
||||
Name func(childComplexity int) int
|
||||
NonconformityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) int
|
||||
NonconformityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) int
|
||||
Peoples func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy, filter *types.PeopleFilter) int
|
||||
ProcessingActivityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ProcessingActivityRegistryOrderBy) int
|
||||
Risks func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy, filter *types.RiskFilter) int
|
||||
@@ -1666,7 +1666,7 @@ type OrganizationResolver interface {
|
||||
Assets(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AssetOrderBy) (*types.AssetConnection, error)
|
||||
Data(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DatumOrderBy, filter *types.DatumFilter) (*types.DatumConnection, error)
|
||||
Audits(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AuditOrderBy) (*types.AuditConnection, error)
|
||||
NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) (*types.NonconformityRegistryConnection, error)
|
||||
NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) (*types.NonconformityRegistryConnection, error)
|
||||
ComplianceRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ComplianceRegistryOrderBy) (*types.ComplianceRegistryConnection, error)
|
||||
ContinualImprovementRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ContinualImprovementRegistriesOrderBy) (*types.ContinualImprovementRegistryConnection, error)
|
||||
ProcessingActivityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ProcessingActivityRegistryOrderBy) (*types.ProcessingActivityRegistryConnection, error)
|
||||
@@ -5478,7 +5478,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return e.complexity.Organization.NonconformityRegistries(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.NonconformityRegistryOrderBy)), true
|
||||
return e.complexity.Organization.NonconformityRegistries(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.NonconformityRegistryOrderBy), args["filter"].(*types.NonconformityRegistryFilter)), true
|
||||
|
||||
case "Organization.peoples":
|
||||
if e.complexity.Organization.Peoples == nil {
|
||||
@@ -7724,6 +7724,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
|
||||
ec.unmarshalInputInviteUserInput,
|
||||
ec.unmarshalInputMeasureFilter,
|
||||
ec.unmarshalInputMeasureOrder,
|
||||
ec.unmarshalInputNonconformityRegistryFilter,
|
||||
ec.unmarshalInputNonconformityRegistryOrder,
|
||||
ec.unmarshalInputOrganizationFilter,
|
||||
ec.unmarshalInputOrganizationOrder,
|
||||
@@ -8981,6 +8982,10 @@ input DatumFilter {
|
||||
snapshotId: ID
|
||||
}
|
||||
|
||||
input NonconformityRegistryFilter {
|
||||
snapshotId: ID
|
||||
}
|
||||
|
||||
# Core Types
|
||||
type TrustCenter implements Node {
|
||||
id: ID!
|
||||
@@ -9120,6 +9125,7 @@ type Organization implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: NonconformityRegistryOrder
|
||||
filter: NonconformityRegistryFilter
|
||||
): NonconformityRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
complianceRegistries(
|
||||
@@ -16801,6 +16807,11 @@ func (ec *executionContext) field_Organization_nonconformityRegistries_args(ctx
|
||||
return nil, err
|
||||
}
|
||||
args["orderBy"] = arg4
|
||||
arg5, err := ec.field_Organization_nonconformityRegistries_argsFilter(ctx, rawArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args["filter"] = arg5
|
||||
return args, nil
|
||||
}
|
||||
func (ec *executionContext) field_Organization_nonconformityRegistries_argsFirst(
|
||||
@@ -16868,6 +16879,19 @@ func (ec *executionContext) field_Organization_nonconformityRegistries_argsOrder
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Organization_nonconformityRegistries_argsFilter(
|
||||
ctx context.Context,
|
||||
rawArgs map[string]any,
|
||||
) (*types.NonconformityRegistryFilter, error) {
|
||||
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
|
||||
if tmp, ok := rawArgs["filter"]; ok {
|
||||
return ec.unmarshalONonconformityRegistryFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryFilter(ctx, tmp)
|
||||
}
|
||||
|
||||
var zeroVal *types.NonconformityRegistryFilter
|
||||
return zeroVal, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) field_Organization_peoples_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
|
||||
var err error
|
||||
args := map[string]any{}
|
||||
@@ -41754,7 +41778,7 @@ func (ec *executionContext) _Organization_nonconformityRegistries(ctx context.Co
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return ec.resolvers.Organization().NonconformityRegistries(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.NonconformityRegistryOrderBy))
|
||||
return ec.resolvers.Organization().NonconformityRegistries(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.NonconformityRegistryOrderBy), fc.Args["filter"].(*types.NonconformityRegistryFilter))
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
@@ -62770,6 +62794,33 @@ func (ec *executionContext) unmarshalInputMeasureOrder(ctx context.Context, obj
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputNonconformityRegistryFilter(ctx context.Context, obj any) (types.NonconformityRegistryFilter, error) {
|
||||
var it types.NonconformityRegistryFilter
|
||||
asMap := map[string]any{}
|
||||
for k, v := range obj.(map[string]any) {
|
||||
asMap[k] = v
|
||||
}
|
||||
|
||||
fieldsInOrder := [...]string{"snapshotId"}
|
||||
for _, k := range fieldsInOrder {
|
||||
v, ok := asMap[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "snapshotId":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("snapshotId"))
|
||||
data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.SnapshotID = data
|
||||
}
|
||||
}
|
||||
|
||||
return it, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalInputNonconformityRegistryOrder(ctx context.Context, obj any) (types.NonconformityRegistryOrderBy, error) {
|
||||
var it types.NonconformityRegistryOrderBy
|
||||
asMap := map[string]any{}
|
||||
@@ -87078,6 +87129,14 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func (ec *executionContext) unmarshalONonconformityRegistryFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryFilter(ctx context.Context, v any) (*types.NonconformityRegistryFilter, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
res, err := ec.unmarshalInputNonconformityRegistryFilter(ctx, v)
|
||||
return &res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalONonconformityRegistryOrder2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryOrderBy(ctx context.Context, v any) (*types.NonconformityRegistryOrderBy, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -30,6 +30,7 @@ type (
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
Filter *NonconformityRegistryFilter
|
||||
}
|
||||
)
|
||||
|
||||
@@ -37,6 +38,7 @@ func NewNonconformityRegistryConnection(
|
||||
p *page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
filter *NonconformityRegistryFilter,
|
||||
) *NonconformityRegistryConnection {
|
||||
edges := make([]*NonconformityRegistryEdge, len(p.Data))
|
||||
for i, registry := range p.Data {
|
||||
@@ -49,6 +51,7 @@ func NewNonconformityRegistryConnection(
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
Filter: filter,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,6 +1138,10 @@ type NonconformityRegistryEdge struct {
|
||||
Node *NonconformityRegistry `json:"node"`
|
||||
}
|
||||
|
||||
type NonconformityRegistryFilter struct {
|
||||
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -3313,7 +3313,12 @@ func (r *nonconformityRegistryConnectionResolver) TotalCount(ctx context.Context
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.NonconformityRegistries.CountForOrganizationID(ctx, obj.ParentID)
|
||||
nonconformityRegistryFilter := coredata.NewNonconformityRegistryFilterBySnapshotID(nil)
|
||||
if obj.Filter != nil {
|
||||
nonconformityRegistryFilter = coredata.NewNonconformityRegistryFilterBySnapshotID(&obj.Filter.SnapshotID)
|
||||
}
|
||||
|
||||
count, err := prb.NonconformityRegistries.CountForOrganizationID(ctx, obj.ParentID, nonconformityRegistryFilter)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count nonconformity registries: %w", err)
|
||||
}
|
||||
@@ -3686,7 +3691,7 @@ func (r *organizationResolver) Audits(ctx context.Context, obj *types.Organizati
|
||||
}
|
||||
|
||||
// NonconformityRegistries is the resolver for the nonconformityRegistries field.
|
||||
func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) (*types.NonconformityRegistryConnection, error) {
|
||||
func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) (*types.NonconformityRegistryConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.NonconformityRegistryOrderField]{
|
||||
@@ -3702,12 +3707,17 @@ func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.NonconformityRegistries.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
nonconformityRegistryFilter := coredata.NewNonconformityRegistryFilterBySnapshotID(nil)
|
||||
if filter != nil {
|
||||
nonconformityRegistryFilter = coredata.NewNonconformityRegistryFilterBySnapshotID(&filter.SnapshotID)
|
||||
}
|
||||
|
||||
page, err := prb.NonconformityRegistries.ListForOrganizationID(ctx, obj.ID, cursor, nonconformityRegistryFilter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list organization nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
return types.NewNonconformityRegistryConnection(page, r, obj.ID), nil
|
||||
return types.NewNonconformityRegistryConnection(page, r, obj.ID, filter), nil
|
||||
}
|
||||
|
||||
// ComplianceRegistries is the resolver for the complianceRegistries field.
|
||||
|
||||
Reference in New Issue
Block a user