Add compliance registries
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
348
pkg/coredata/compliance_registry.go
Normal file
348
pkg/coredata/compliance_registry.go
Normal file
@@ -0,0 +1,348 @@
|
||||
// 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 (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
ComplianceRegistry struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
ReferenceID string `db:"reference_id"`
|
||||
Area *string `db:"area"`
|
||||
Source *string `db:"source"`
|
||||
AuditID gid.GID `db:"audit_id"`
|
||||
Requirement *string `db:"requirement"`
|
||||
ActionsToBeImplemented *string `db:"actions_to_be_implemented"`
|
||||
Regulator *string `db:"regulator"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
LastReviewDate *time.Time `db:"last_review_date"`
|
||||
DueDate *time.Time `db:"due_date"`
|
||||
Status ComplianceRegistryStatus `db:"status"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
ComplianceRegistries []*ComplianceRegistry
|
||||
)
|
||||
|
||||
func (cr *ComplianceRegistry) CursorKey(field ComplianceRegistryOrderField) page.CursorKey {
|
||||
switch field {
|
||||
case ComplianceRegistryOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(cr.ID, cr.CreatedAt)
|
||||
case ComplianceRegistryOrderFieldLastReviewDate:
|
||||
return page.NewCursorKey(cr.ID, cr.LastReviewDate)
|
||||
case ComplianceRegistryOrderFieldDueDate:
|
||||
return page.NewCursorKey(cr.ID, cr.DueDate)
|
||||
case ComplianceRegistryOrderFieldStatus:
|
||||
return page.NewCursorKey(cr.ID, cr.Status)
|
||||
case ComplianceRegistryOrderFieldReferenceId:
|
||||
return page.NewCursorKey(cr.ID, cr.ReferenceID)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", field))
|
||||
}
|
||||
|
||||
func (cr *ComplianceRegistry) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
complianceRegistryID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
area,
|
||||
source,
|
||||
audit_id,
|
||||
requirement,
|
||||
actions_to_be_implemented,
|
||||
regulator,
|
||||
owner_id,
|
||||
last_review_date,
|
||||
due_date,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
compliance_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @compliance_registry_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"compliance_registry_id": complianceRegistryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query compliance registry: %w", err)
|
||||
}
|
||||
|
||||
registry, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ComplianceRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect compliance registry: %w", err)
|
||||
}
|
||||
|
||||
*cr = registry
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (crs *ComplianceRegistries) CountByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
compliance_registries
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
row := conn.QueryRow(ctx, q, args)
|
||||
|
||||
var count int
|
||||
err := row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count compliance registries: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (crs *ComplianceRegistries) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[ComplianceRegistryOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
area,
|
||||
source,
|
||||
audit_id,
|
||||
requirement,
|
||||
actions_to_be_implemented,
|
||||
regulator,
|
||||
owner_id,
|
||||
last_review_date,
|
||||
due_date,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
compliance_registries
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query compliance registries: %w", err)
|
||||
}
|
||||
|
||||
registries, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ComplianceRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect compliance registries: %w", err)
|
||||
}
|
||||
|
||||
*crs = registries
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *ComplianceRegistry) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO compliance_registries (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
area,
|
||||
source,
|
||||
audit_id,
|
||||
requirement,
|
||||
actions_to_be_implemented,
|
||||
regulator,
|
||||
owner_id,
|
||||
last_review_date,
|
||||
due_date,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@reference_id,
|
||||
@area,
|
||||
@source,
|
||||
@audit_id,
|
||||
@requirement,
|
||||
@actions_to_be_implemented,
|
||||
@regulator,
|
||||
@owner_id,
|
||||
@last_review_date,
|
||||
@due_date,
|
||||
@status,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cr.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"organization_id": cr.OrganizationID,
|
||||
"reference_id": cr.ReferenceID,
|
||||
"area": cr.Area,
|
||||
"source": cr.Source,
|
||||
"audit_id": cr.AuditID,
|
||||
"requirement": cr.Requirement,
|
||||
"actions_to_be_implemented": cr.ActionsToBeImplemented,
|
||||
"regulator": cr.Regulator,
|
||||
"owner_id": cr.OwnerID,
|
||||
"last_review_date": cr.LastReviewDate,
|
||||
"due_date": cr.DueDate,
|
||||
"status": cr.Status,
|
||||
"created_at": cr.CreatedAt,
|
||||
"updated_at": cr.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *ComplianceRegistry) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE compliance_registries SET
|
||||
reference_id = @reference_id,
|
||||
area = @area,
|
||||
source = @source,
|
||||
audit_id = @audit_id,
|
||||
requirement = @requirement,
|
||||
actions_to_be_implemented = @actions_to_be_implemented,
|
||||
regulator = @regulator,
|
||||
owner_id = @owner_id,
|
||||
last_review_date = @last_review_date,
|
||||
due_date = @due_date,
|
||||
status = @status,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cr.ID,
|
||||
"reference_id": cr.ReferenceID,
|
||||
"area": cr.Area,
|
||||
"source": cr.Source,
|
||||
"audit_id": cr.AuditID,
|
||||
"requirement": cr.Requirement,
|
||||
"actions_to_be_implemented": cr.ActionsToBeImplemented,
|
||||
"regulator": cr.Regulator,
|
||||
"owner_id": cr.OwnerID,
|
||||
"last_review_date": cr.LastReviewDate,
|
||||
"due_date": cr.DueDate,
|
||||
"status": cr.Status,
|
||||
"updated_at": cr.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *ComplianceRegistry) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM compliance_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": cr.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
55
pkg/coredata/compliance_registry_order_field.go
Normal file
55
pkg/coredata/compliance_registry_order_field.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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 (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ComplianceRegistryOrderField string
|
||||
|
||||
const (
|
||||
ComplianceRegistryOrderFieldCreatedAt ComplianceRegistryOrderField = "CREATED_AT"
|
||||
ComplianceRegistryOrderFieldLastReviewDate ComplianceRegistryOrderField = "LAST_REVIEW_DATE"
|
||||
ComplianceRegistryOrderFieldDueDate ComplianceRegistryOrderField = "DUE_DATE"
|
||||
ComplianceRegistryOrderFieldStatus ComplianceRegistryOrderField = "STATUS"
|
||||
ComplianceRegistryOrderFieldReferenceId ComplianceRegistryOrderField = "REFERENCE_ID"
|
||||
)
|
||||
|
||||
func (p ComplianceRegistryOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ComplianceRegistryOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ComplianceRegistryOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *ComplianceRegistryOrderField) UnmarshalText(text []byte) error {
|
||||
val := string(text)
|
||||
switch val {
|
||||
case string(ComplianceRegistryOrderFieldCreatedAt),
|
||||
string(ComplianceRegistryOrderFieldLastReviewDate),
|
||||
string(ComplianceRegistryOrderFieldDueDate),
|
||||
string(ComplianceRegistryOrderFieldStatus),
|
||||
string(ComplianceRegistryOrderFieldReferenceId):
|
||||
*p = ComplianceRegistryOrderField(val)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid ComplianceRegistryOrderField value: %q", val)
|
||||
}
|
||||
60
pkg/coredata/compliance_registry_status.go
Normal file
60
pkg/coredata/compliance_registry_status.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 (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ComplianceRegistryStatus string
|
||||
|
||||
const (
|
||||
ComplianceRegistryStatusOpen ComplianceRegistryStatus = "OPEN"
|
||||
ComplianceRegistryStatusInProgress ComplianceRegistryStatus = "IN_PROGRESS"
|
||||
ComplianceRegistryStatusClosed ComplianceRegistryStatus = "CLOSED"
|
||||
)
|
||||
|
||||
func (crs ComplianceRegistryStatus) String() string {
|
||||
return string(crs)
|
||||
}
|
||||
|
||||
func (crs *ComplianceRegistryStatus) Scan(value any) error {
|
||||
var s string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
case []byte:
|
||||
s = string(v)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for ComplianceRegistryStatus: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "OPEN":
|
||||
*crs = ComplianceRegistryStatusOpen
|
||||
case "IN_PROGRESS":
|
||||
*crs = ComplianceRegistryStatusInProgress
|
||||
case "CLOSED":
|
||||
*crs = ComplianceRegistryStatusClosed
|
||||
default:
|
||||
return fmt.Errorf("invalid ComplianceRegistryStatus value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (crs ComplianceRegistryStatus) Value() (driver.Value, error) {
|
||||
return crs.String(), nil
|
||||
}
|
||||
@@ -44,4 +44,5 @@ const (
|
||||
VendorContactEntityType
|
||||
VendorDataPrivacyAgreementEntityType
|
||||
NonconformityRegistryEntityType
|
||||
ComplianceRegistryEntityType
|
||||
)
|
||||
|
||||
42
pkg/coredata/migrations/20250818T094916Z.sql
Normal file
42
pkg/coredata/migrations/20250818T094916Z.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
CREATE TYPE compliance_registries_status AS ENUM (
|
||||
'OPEN',
|
||||
'IN_PROGRESS',
|
||||
'CLOSED'
|
||||
);
|
||||
|
||||
CREATE TABLE compliance_registries (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id TEXT NOT NULL,
|
||||
organization_id TEXT NOT NULL,
|
||||
reference_id TEXT NOT NULL,
|
||||
area TEXT,
|
||||
source TEXT,
|
||||
audit_id TEXT NOT NULL,
|
||||
requirement TEXT,
|
||||
actions_to_be_implemented TEXT,
|
||||
regulator TEXT,
|
||||
owner_id TEXT NOT NULL,
|
||||
last_review_date DATE,
|
||||
due_date DATE,
|
||||
status compliance_registries_status NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
|
||||
CONSTRAINT compliance_registries_organization_id_fkey
|
||||
FOREIGN KEY (organization_id)
|
||||
REFERENCES organizations(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT compliance_registries_owner_id_fkey
|
||||
FOREIGN KEY (owner_id)
|
||||
REFERENCES peoples(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
|
||||
CONSTRAINT compliance_registries_audit_id_fkey
|
||||
FOREIGN KEY (audit_id)
|
||||
REFERENCES audits(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
300
pkg/probo/compliance_registry_service.go
Normal file
300
pkg/probo/compliance_registry_service.go
Normal file
@@ -0,0 +1,300 @@
|
||||
// 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 probo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type ComplianceRegistryService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
type (
|
||||
CreateComplianceRegistryRequest struct {
|
||||
OrganizationID gid.GID
|
||||
ReferenceID string
|
||||
Area *string
|
||||
Source *string
|
||||
AuditID gid.GID
|
||||
Requirement *string
|
||||
ActionsToBeImplemented *string
|
||||
Regulator *string
|
||||
OwnerID gid.GID
|
||||
LastReviewDate *time.Time
|
||||
DueDate *time.Time
|
||||
Status *coredata.ComplianceRegistryStatus
|
||||
}
|
||||
|
||||
UpdateComplianceRegistryRequest struct {
|
||||
ID gid.GID
|
||||
ReferenceID *string
|
||||
Area **string
|
||||
Source **string
|
||||
AuditID *gid.GID
|
||||
Requirement **string
|
||||
ActionsToBeImplemented **string
|
||||
Regulator **string
|
||||
OwnerID *gid.GID
|
||||
LastReviewDate **time.Time
|
||||
DueDate **time.Time
|
||||
Status *coredata.ComplianceRegistryStatus
|
||||
}
|
||||
)
|
||||
|
||||
func (s ComplianceRegistryService) Get(
|
||||
ctx context.Context,
|
||||
complianceRegistryID gid.GID,
|
||||
) (*coredata.ComplianceRegistry, error) {
|
||||
registry := &coredata.ComplianceRegistry{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := registry.LoadByID(ctx, conn, s.svc.scope, complianceRegistryID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ComplianceRegistryService) Create(
|
||||
ctx context.Context,
|
||||
req *CreateComplianceRegistryRequest,
|
||||
) (*coredata.ComplianceRegistry, error) {
|
||||
now := time.Now()
|
||||
|
||||
registry := &coredata.ComplianceRegistry{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.ComplianceRegistryEntityType),
|
||||
OrganizationID: req.OrganizationID,
|
||||
ReferenceID: req.ReferenceID,
|
||||
Area: req.Area,
|
||||
Source: req.Source,
|
||||
AuditID: req.AuditID,
|
||||
Requirement: req.Requirement,
|
||||
ActionsToBeImplemented: req.ActionsToBeImplemented,
|
||||
Regulator: req.Regulator,
|
||||
OwnerID: req.OwnerID,
|
||||
LastReviewDate: req.LastReviewDate,
|
||||
DueDate: req.DueDate,
|
||||
Status: *req.Status,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
organization := &coredata.Organization{}
|
||||
if err := organization.LoadByID(ctx, conn, s.svc.scope, req.OrganizationID); err != nil {
|
||||
return fmt.Errorf("cannot load organization: %w", err)
|
||||
}
|
||||
|
||||
audit := &coredata.Audit{}
|
||||
if err := audit.LoadByID(ctx, conn, s.svc.scope, req.AuditID); err != nil {
|
||||
return fmt.Errorf("cannot load audit: %w", err)
|
||||
}
|
||||
|
||||
owner := &coredata.People{}
|
||||
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
|
||||
return fmt.Errorf("cannot load owner: %w", err)
|
||||
}
|
||||
|
||||
if err := registry.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ComplianceRegistryService) Update(
|
||||
ctx context.Context,
|
||||
req *UpdateComplianceRegistryRequest,
|
||||
) (*coredata.ComplianceRegistry, error) {
|
||||
registry := &coredata.ComplianceRegistry{}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := registry.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance registry: %w", err)
|
||||
}
|
||||
|
||||
if req.ReferenceID != nil {
|
||||
registry.ReferenceID = *req.ReferenceID
|
||||
}
|
||||
|
||||
if req.Area != nil {
|
||||
registry.Area = *req.Area
|
||||
}
|
||||
|
||||
if req.Source != nil {
|
||||
registry.Source = *req.Source
|
||||
}
|
||||
|
||||
if req.AuditID != nil {
|
||||
audit := &coredata.Audit{}
|
||||
if err := audit.LoadByID(ctx, conn, s.svc.scope, *req.AuditID); err != nil {
|
||||
return fmt.Errorf("cannot load audit: %w", err)
|
||||
}
|
||||
registry.AuditID = *req.AuditID
|
||||
}
|
||||
|
||||
if req.Requirement != nil {
|
||||
registry.Requirement = *req.Requirement
|
||||
}
|
||||
|
||||
if req.ActionsToBeImplemented != nil {
|
||||
registry.ActionsToBeImplemented = *req.ActionsToBeImplemented
|
||||
}
|
||||
|
||||
if req.Regulator != nil {
|
||||
registry.Regulator = *req.Regulator
|
||||
}
|
||||
|
||||
if req.OwnerID != nil {
|
||||
owner := &coredata.People{}
|
||||
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
|
||||
return fmt.Errorf("cannot load owner: %w", err)
|
||||
}
|
||||
registry.OwnerID = *req.OwnerID
|
||||
}
|
||||
|
||||
if req.LastReviewDate != nil {
|
||||
registry.LastReviewDate = *req.LastReviewDate
|
||||
}
|
||||
|
||||
if req.DueDate != nil {
|
||||
registry.DueDate = *req.DueDate
|
||||
}
|
||||
|
||||
if req.Status != nil {
|
||||
registry.Status = *req.Status
|
||||
}
|
||||
|
||||
registry.UpdatedAt = time.Now()
|
||||
|
||||
if err := registry.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ComplianceRegistryService) Delete(
|
||||
ctx context.Context,
|
||||
complianceRegistryID gid.GID,
|
||||
) error {
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
registry := &coredata.ComplianceRegistry{}
|
||||
if err := registry.LoadByID(ctx, conn, s.svc.scope, complianceRegistryID); err != nil {
|
||||
return fmt.Errorf("cannot load compliance registry: %w", err)
|
||||
}
|
||||
|
||||
if err := registry.Delete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete compliance registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s ComplianceRegistryService) CountByOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
var count int
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) (err error) {
|
||||
registries := coredata.ComplianceRegistries{}
|
||||
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count compliance registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s ComplianceRegistryService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.ComplianceRegistryOrderField],
|
||||
) (*page.Page[*coredata.ComplianceRegistry, coredata.ComplianceRegistryOrderField], error) {
|
||||
var registries coredata.ComplianceRegistries
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load compliance registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(registries, cursor), nil
|
||||
}
|
||||
@@ -82,6 +82,7 @@ type (
|
||||
TrustCenters *TrustCenterService
|
||||
TrustCenterAccesses *TrustCenterAccessService
|
||||
NonconformityRegistries *NonconformityRegistryService
|
||||
ComplianceRegistries *ComplianceRegistryService
|
||||
}
|
||||
)
|
||||
|
||||
@@ -175,5 +176,6 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
usrmgr: s.usrmgr,
|
||||
}
|
||||
tenantService.NonconformityRegistries = &NonconformityRegistryService{svc: tenantService}
|
||||
tenantService.ComplianceRegistries = &ComplianceRegistryService{svc: tenantService}
|
||||
return tenantService
|
||||
}
|
||||
|
||||
@@ -167,6 +167,22 @@ enum NonconformityRegistryStatus
|
||||
)
|
||||
}
|
||||
|
||||
enum ComplianceRegistryStatus
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryStatus") {
|
||||
OPEN
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryStatusOpen"
|
||||
)
|
||||
IN_PROGRESS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryStatusInProgress"
|
||||
)
|
||||
CLOSED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryStatusClosed"
|
||||
)
|
||||
}
|
||||
|
||||
# Order Field Enums
|
||||
enum UserOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.UserOrderField") {
|
||||
@@ -624,6 +640,30 @@ enum NonconformityRegistryOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum ComplianceRegistryOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderFieldCreatedAt"
|
||||
)
|
||||
REFERENCE_ID
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderFieldReferenceId"
|
||||
)
|
||||
LAST_REVIEW_DATE
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderFieldLastReviewDate"
|
||||
)
|
||||
DUE_DATE
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderFieldDueDate"
|
||||
)
|
||||
STATUS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ComplianceRegistryOrderFieldStatus"
|
||||
)
|
||||
}
|
||||
|
||||
enum TrustCenterAccessOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.TrustCenterAccessOrderField") {
|
||||
CREATED_AT
|
||||
@@ -721,6 +761,14 @@ input NonconformityRegistryOrder
|
||||
field: NonconformityRegistryOrderField!
|
||||
}
|
||||
|
||||
input ComplianceRegistryOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.ComplianceRegistryOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: ComplianceRegistryOrderField!
|
||||
}
|
||||
|
||||
input TrustCenterAccessOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterAccessOrderBy"
|
||||
@@ -944,6 +992,14 @@ type Organization implements Node {
|
||||
orderBy: NonconformityRegistryOrder
|
||||
): NonconformityRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
complianceRegistries(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: ComplianceRegistryOrder
|
||||
): ComplianceRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenter: TrustCenter @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
@@ -1353,6 +1409,24 @@ type NonconformityRegistry implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type ComplianceRegistry implements Node {
|
||||
id: ID!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
referenceId: String!
|
||||
area: String
|
||||
source: String
|
||||
audit: Audit! @goField(forceResolver: true)
|
||||
requirement: String
|
||||
actionsToBeImplemented: String
|
||||
regulator: String
|
||||
owner: People! @goField(forceResolver: true)
|
||||
lastReviewDate: Datetime
|
||||
dueDate: Datetime
|
||||
status: ComplianceRegistryStatus!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Report implements Node {
|
||||
id: ID!
|
||||
objectKey: String!
|
||||
@@ -1650,6 +1724,20 @@ type NonconformityRegistryEdge {
|
||||
node: NonconformityRegistry!
|
||||
}
|
||||
|
||||
type ComplianceRegistryConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.ComplianceRegistryConnection"
|
||||
) {
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
edges: [ComplianceRegistryEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type ComplianceRegistryEdge {
|
||||
cursor: CursorKey!
|
||||
node: ComplianceRegistry!
|
||||
}
|
||||
|
||||
# Root Types
|
||||
type Query {
|
||||
node(id: ID!): Node!
|
||||
@@ -1880,6 +1968,17 @@ type Mutation {
|
||||
deleteNonconformityRegistry(
|
||||
input: DeleteNonconformityRegistryInput!
|
||||
): DeleteNonconformityRegistryPayload!
|
||||
|
||||
# Compliance Registry mutations
|
||||
createComplianceRegistry(
|
||||
input: CreateComplianceRegistryInput!
|
||||
): CreateComplianceRegistryPayload!
|
||||
updateComplianceRegistry(
|
||||
input: UpdateComplianceRegistryInput!
|
||||
): UpdateComplianceRegistryPayload!
|
||||
deleteComplianceRegistry(
|
||||
input: DeleteComplianceRegistryInput!
|
||||
): DeleteComplianceRegistryPayload!
|
||||
}
|
||||
|
||||
# Input Types
|
||||
@@ -2374,6 +2473,40 @@ input DeleteNonconformityRegistryInput {
|
||||
nonconformityRegistryId: ID!
|
||||
}
|
||||
|
||||
input CreateComplianceRegistryInput {
|
||||
organizationId: ID!
|
||||
referenceId: String!
|
||||
area: String
|
||||
source: String
|
||||
auditId: ID!
|
||||
requirement: String
|
||||
actionsToBeImplemented: String
|
||||
regulator: String
|
||||
ownerId: ID!
|
||||
lastReviewDate: Datetime
|
||||
dueDate: Datetime
|
||||
status: ComplianceRegistryStatus!
|
||||
}
|
||||
|
||||
input UpdateComplianceRegistryInput {
|
||||
id: ID!
|
||||
referenceId: String
|
||||
area: String
|
||||
source: String
|
||||
auditId: ID
|
||||
requirement: String
|
||||
actionsToBeImplemented: String
|
||||
regulator: String
|
||||
ownerId: ID
|
||||
lastReviewDate: Datetime
|
||||
dueDate: Datetime
|
||||
status: ComplianceRegistryStatus
|
||||
}
|
||||
|
||||
input DeleteComplianceRegistryInput {
|
||||
complianceRegistryId: ID!
|
||||
}
|
||||
|
||||
# Payload Types
|
||||
type CreateOrganizationPayload {
|
||||
organizationEdge: OrganizationEdge!
|
||||
@@ -3055,3 +3188,15 @@ type UpdateNonconformityRegistryPayload {
|
||||
type DeleteNonconformityRegistryPayload {
|
||||
deletedNonconformityRegistryId: ID!
|
||||
}
|
||||
|
||||
type CreateComplianceRegistryPayload {
|
||||
complianceRegistryEdge: ComplianceRegistryEdge!
|
||||
}
|
||||
|
||||
type UpdateComplianceRegistryPayload {
|
||||
complianceRegistry: ComplianceRegistry!
|
||||
}
|
||||
|
||||
type DeleteComplianceRegistryPayload {
|
||||
deletedComplianceRegistryId: ID!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
77
pkg/server/api/console/v1/types/compliance_registry.go
Normal file
77
pkg/server/api/console/v1/types/compliance_registry.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// 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 types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
type (
|
||||
ComplianceRegistryOrderBy OrderBy[coredata.ComplianceRegistryOrderField]
|
||||
|
||||
ComplianceRegistryConnection struct {
|
||||
TotalCount int
|
||||
Edges []*ComplianceRegistryEdge
|
||||
PageInfo PageInfo
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func NewComplianceRegistryConnection(
|
||||
p *page.Page[*coredata.ComplianceRegistry, coredata.ComplianceRegistryOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
) *ComplianceRegistryConnection {
|
||||
edges := make([]*ComplianceRegistryEdge, len(p.Data))
|
||||
for i, registry := range p.Data {
|
||||
edges[i] = NewComplianceRegistryEdge(registry, p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &ComplianceRegistryConnection{
|
||||
Edges: edges,
|
||||
PageInfo: *NewPageInfo(p),
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewComplianceRegistry(cr *coredata.ComplianceRegistry) *ComplianceRegistry {
|
||||
return &ComplianceRegistry{
|
||||
ID: cr.ID,
|
||||
ReferenceID: cr.ReferenceID,
|
||||
Area: cr.Area,
|
||||
Source: cr.Source,
|
||||
Requirement: cr.Requirement,
|
||||
ActionsToBeImplemented: cr.ActionsToBeImplemented,
|
||||
Regulator: cr.Regulator,
|
||||
LastReviewDate: cr.LastReviewDate,
|
||||
DueDate: cr.DueDate,
|
||||
Status: cr.Status,
|
||||
CreatedAt: cr.CreatedAt,
|
||||
UpdatedAt: cr.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewComplianceRegistryEdge(cr *coredata.ComplianceRegistry, orderField coredata.ComplianceRegistryOrderField) *ComplianceRegistryEdge {
|
||||
return &ComplianceRegistryEdge{
|
||||
Node: NewComplianceRegistry(cr),
|
||||
Cursor: cr.CursorKey(orderField),
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,32 @@ type CancelSignatureRequestPayload struct {
|
||||
DeletedDocumentVersionSignatureID gid.GID `json:"deletedDocumentVersionSignatureId"`
|
||||
}
|
||||
|
||||
type ComplianceRegistry struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Organization *Organization `json:"organization"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Area *string `json:"area,omitempty"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
Audit *Audit `json:"audit"`
|
||||
Requirement *string `json:"requirement,omitempty"`
|
||||
ActionsToBeImplemented *string `json:"actionsToBeImplemented,omitempty"`
|
||||
Regulator *string `json:"regulator,omitempty"`
|
||||
Owner *People `json:"owner"`
|
||||
LastReviewDate *time.Time `json:"lastReviewDate,omitempty"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status coredata.ComplianceRegistryStatus `json:"status"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (ComplianceRegistry) IsNode() {}
|
||||
func (this ComplianceRegistry) GetID() gid.GID { return this.ID }
|
||||
|
||||
type ComplianceRegistryEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *ComplianceRegistry `json:"node"`
|
||||
}
|
||||
|
||||
type ConfirmEmailInput struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
@@ -196,6 +222,25 @@ type CreateAuditPayload struct {
|
||||
AuditEdge *AuditEdge `json:"auditEdge"`
|
||||
}
|
||||
|
||||
type CreateComplianceRegistryInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Area *string `json:"area,omitempty"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
Requirement *string `json:"requirement,omitempty"`
|
||||
ActionsToBeImplemented *string `json:"actionsToBeImplemented,omitempty"`
|
||||
Regulator *string `json:"regulator,omitempty"`
|
||||
OwnerID gid.GID `json:"ownerId"`
|
||||
LastReviewDate *time.Time `json:"lastReviewDate,omitempty"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status coredata.ComplianceRegistryStatus `json:"status"`
|
||||
}
|
||||
|
||||
type CreateComplianceRegistryPayload struct {
|
||||
ComplianceRegistryEdge *ComplianceRegistryEdge `json:"complianceRegistryEdge"`
|
||||
}
|
||||
|
||||
type CreateControlAuditMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
@@ -503,6 +548,14 @@ type DeleteAuditReportPayload struct {
|
||||
Audit *Audit `json:"audit"`
|
||||
}
|
||||
|
||||
type DeleteComplianceRegistryInput struct {
|
||||
ComplianceRegistryID gid.GID `json:"complianceRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteComplianceRegistryPayload struct {
|
||||
DeletedComplianceRegistryID gid.GID `json:"deletedComplianceRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteControlAuditMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
@@ -964,6 +1017,7 @@ type Organization struct {
|
||||
Data *DatumConnection `json:"data"`
|
||||
Audits *AuditConnection `json:"audits"`
|
||||
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
|
||||
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
@@ -1233,6 +1287,25 @@ type UpdateAuditPayload struct {
|
||||
Audit *Audit `json:"audit"`
|
||||
}
|
||||
|
||||
type UpdateComplianceRegistryInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
ReferenceID *string `json:"referenceId,omitempty"`
|
||||
Area *string `json:"area,omitempty"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
AuditID *gid.GID `json:"auditId,omitempty"`
|
||||
Requirement *string `json:"requirement,omitempty"`
|
||||
ActionsToBeImplemented *string `json:"actionsToBeImplemented,omitempty"`
|
||||
Regulator *string `json:"regulator,omitempty"`
|
||||
OwnerID *gid.GID `json:"ownerId,omitempty"`
|
||||
LastReviewDate *time.Time `json:"lastReviewDate,omitempty"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status *coredata.ComplianceRegistryStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateComplianceRegistryPayload struct {
|
||||
ComplianceRegistry *ComplianceRegistry `json:"complianceRegistry"`
|
||||
}
|
||||
|
||||
type UpdateControlInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
SectionTitle *string `json:"sectionTitle,omitempty"`
|
||||
|
||||
@@ -220,6 +220,73 @@ func (r *auditConnectionResolver) TotalCount(ctx context.Context, obj *types.Aud
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Organization is the resolver for the organization field.
|
||||
func (r *complianceRegistryResolver) Organization(ctx context.Context, obj *types.ComplianceRegistry) (*types.Organization, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ComplianceRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry: %w", err))
|
||||
}
|
||||
|
||||
organization, err := prb.Organizations.Get(ctx, registry.OrganizationID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry organization: %w", err))
|
||||
}
|
||||
|
||||
return types.NewOrganization(organization), nil
|
||||
}
|
||||
|
||||
// Audit is the resolver for the audit field.
|
||||
func (r *complianceRegistryResolver) Audit(ctx context.Context, obj *types.ComplianceRegistry) (*types.Audit, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ComplianceRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry: %w", err))
|
||||
}
|
||||
|
||||
audit, err := prb.Audits.Get(ctx, registry.AuditID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry audit: %w", err))
|
||||
}
|
||||
|
||||
return types.NewAudit(audit), nil
|
||||
}
|
||||
|
||||
// Owner is the resolver for the owner field.
|
||||
func (r *complianceRegistryResolver) Owner(ctx context.Context, obj *types.ComplianceRegistry) (*types.People, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ComplianceRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry: %w", err))
|
||||
}
|
||||
|
||||
people, err := prb.Peoples.Get(ctx, registry.OwnerID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry owner: %w", err))
|
||||
}
|
||||
|
||||
return types.NewPeople(people), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *complianceRegistryConnectionResolver) TotalCount(ctx context.Context, obj *types.ComplianceRegistryConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.ComplianceRegistries.CountByOrganizationID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot count compliance registries: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
||||
}
|
||||
|
||||
// Framework is the resolver for the framework field.
|
||||
func (r *controlResolver) Framework(ctx context.Context, obj *types.Control) (*types.Framework, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -2783,6 +2850,78 @@ func (r *mutationResolver) DeleteNonconformityRegistry(ctx context.Context, inpu
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateComplianceRegistry is the resolver for the createComplianceRegistry field.
|
||||
func (r *mutationResolver) CreateComplianceRegistry(ctx context.Context, input types.CreateComplianceRegistryInput) (*types.CreateComplianceRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
req := probo.CreateComplianceRegistryRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Area: input.Area,
|
||||
Source: input.Source,
|
||||
AuditID: input.AuditID,
|
||||
Requirement: input.Requirement,
|
||||
ActionsToBeImplemented: input.ActionsToBeImplemented,
|
||||
Regulator: input.Regulator,
|
||||
OwnerID: input.OwnerID,
|
||||
LastReviewDate: input.LastReviewDate,
|
||||
DueDate: input.DueDate,
|
||||
Status: &input.Status,
|
||||
}
|
||||
|
||||
registry, err := prb.ComplianceRegistries.Create(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create compliance registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateComplianceRegistryPayload{
|
||||
ComplianceRegistryEdge: types.NewComplianceRegistryEdge(registry, coredata.ComplianceRegistryOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateComplianceRegistry is the resolver for the updateComplianceRegistry field.
|
||||
func (r *mutationResolver) UpdateComplianceRegistry(ctx context.Context, input types.UpdateComplianceRegistryInput) (*types.UpdateComplianceRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
req := probo.UpdateComplianceRegistryRequest{
|
||||
ID: input.ID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Area: &input.Area,
|
||||
Source: &input.Source,
|
||||
AuditID: input.AuditID,
|
||||
Requirement: &input.Requirement,
|
||||
ActionsToBeImplemented: &input.ActionsToBeImplemented,
|
||||
Regulator: &input.Regulator,
|
||||
OwnerID: input.OwnerID,
|
||||
LastReviewDate: &input.LastReviewDate,
|
||||
DueDate: &input.DueDate,
|
||||
Status: input.Status,
|
||||
}
|
||||
|
||||
registry, err := prb.ComplianceRegistries.Update(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update compliance registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.UpdateComplianceRegistryPayload{
|
||||
ComplianceRegistry: types.NewComplianceRegistry(registry),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteComplianceRegistry is the resolver for the deleteComplianceRegistry field.
|
||||
func (r *mutationResolver) DeleteComplianceRegistry(ctx context.Context, input types.DeleteComplianceRegistryInput) (*types.DeleteComplianceRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.ComplianceRegistryID.TenantID())
|
||||
|
||||
err := prb.ComplianceRegistries.Delete(ctx, input.ComplianceRegistryID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete compliance registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteComplianceRegistryPayload{
|
||||
DeletedComplianceRegistryID: input.ComplianceRegistryID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Organization is the resolver for the organization field.
|
||||
func (r *nonconformityRegistryResolver) Organization(ctx context.Context, obj *types.NonconformityRegistry) (*types.Organization, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3230,6 +3369,31 @@ func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj
|
||||
return types.NewNonconformityRegistryConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// ComplianceRegistries is the resolver for the complianceRegistries field.
|
||||
func (r *organizationResolver) ComplianceRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ComplianceRegistryOrderBy) (*types.ComplianceRegistryConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ComplianceRegistryOrderField]{
|
||||
Field: coredata.ComplianceRegistryOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.ComplianceRegistryOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.ComplianceRegistries.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization compliance registries: %w", err))
|
||||
}
|
||||
|
||||
return types.NewComplianceRegistryConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// TrustCenter is the resolver for the trustCenter field.
|
||||
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3379,6 +3543,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
||||
panic(fmt.Errorf("cannot get nonconformity registry: %w", err))
|
||||
}
|
||||
return types.NewNonconformityRegistry(nonconformityRegistry), nil
|
||||
case coredata.ComplianceRegistryEntityType:
|
||||
complianceRegistry, err := prb.ComplianceRegistries.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get compliance registry: %w", err))
|
||||
}
|
||||
return types.NewComplianceRegistry(complianceRegistry), nil
|
||||
case coredata.ReportEntityType:
|
||||
report, err := prb.Reports.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -4077,6 +4247,16 @@ func (r *Resolver) AuditConnection() schema.AuditConnectionResolver {
|
||||
return &auditConnectionResolver{r}
|
||||
}
|
||||
|
||||
// ComplianceRegistry returns schema.ComplianceRegistryResolver implementation.
|
||||
func (r *Resolver) ComplianceRegistry() schema.ComplianceRegistryResolver {
|
||||
return &complianceRegistryResolver{r}
|
||||
}
|
||||
|
||||
// ComplianceRegistryConnection returns schema.ComplianceRegistryConnectionResolver implementation.
|
||||
func (r *Resolver) ComplianceRegistryConnection() schema.ComplianceRegistryConnectionResolver {
|
||||
return &complianceRegistryConnectionResolver{r}
|
||||
}
|
||||
|
||||
// Control returns schema.ControlResolver implementation.
|
||||
func (r *Resolver) Control() schema.ControlResolver { return &controlResolver{r} }
|
||||
|
||||
@@ -4218,6 +4398,8 @@ type assetResolver struct{ *Resolver }
|
||||
type assetConnectionResolver struct{ *Resolver }
|
||||
type auditResolver struct{ *Resolver }
|
||||
type auditConnectionResolver struct{ *Resolver }
|
||||
type complianceRegistryResolver struct{ *Resolver }
|
||||
type complianceRegistryConnectionResolver struct{ *Resolver }
|
||||
type controlResolver struct{ *Resolver }
|
||||
type controlConnectionResolver struct{ *Resolver }
|
||||
type datumResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user