Add continual improvement registries
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
324
pkg/coredata/continual_improvement_registries.go
Normal file
324
pkg/coredata/continual_improvement_registries.go
Normal file
@@ -0,0 +1,324 @@
|
||||
// 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 (
|
||||
ContinualImprovementRegistry struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
ReferenceID string `db:"reference_id"`
|
||||
Description *string `db:"description"`
|
||||
AuditID gid.GID `db:"audit_id"`
|
||||
Source *string `db:"source"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
TargetDate *time.Time `db:"target_date"`
|
||||
Status ContinualImprovementRegistriesStatus `db:"status"`
|
||||
Priority ContinualImprovementRegistriesPriority `db:"priority"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
ContinualImprovementRegistries []*ContinualImprovementRegistry
|
||||
)
|
||||
|
||||
func (cir *ContinualImprovementRegistry) CursorKey(field ContinualImprovementRegistriesOrderField) page.CursorKey {
|
||||
switch field {
|
||||
case ContinualImprovementRegistriesOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(cir.ID, cir.CreatedAt)
|
||||
case ContinualImprovementRegistriesOrderFieldTargetDate:
|
||||
return page.NewCursorKey(cir.ID, cir.TargetDate)
|
||||
case ContinualImprovementRegistriesOrderFieldStatus:
|
||||
return page.NewCursorKey(cir.ID, cir.Status)
|
||||
case ContinualImprovementRegistriesOrderFieldPriority:
|
||||
return page.NewCursorKey(cir.ID, cir.Priority)
|
||||
case ContinualImprovementRegistriesOrderFieldReferenceId:
|
||||
return page.NewCursorKey(cir.ID, cir.ReferenceID)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", field))
|
||||
}
|
||||
|
||||
func (cir *ContinualImprovementRegistry) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
continualImprovementRegistryID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
source,
|
||||
owner_id,
|
||||
target_date,
|
||||
status,
|
||||
priority,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
continual_improvement_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @continual_improvement_registry_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"continual_improvement_registry_id": continualImprovementRegistryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
registry, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ContinualImprovementRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
*cir = registry
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cirs *ContinualImprovementRegistries) CountByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
continual_improvement_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 continual improvement registries: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (cirs *ContinualImprovementRegistries) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[ContinualImprovementRegistriesOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
source,
|
||||
owner_id,
|
||||
target_date,
|
||||
status,
|
||||
priority,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
continual_improvement_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 continual improvement registries: %w", err)
|
||||
}
|
||||
|
||||
registries, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ContinualImprovementRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect continual improvement registries: %w", err)
|
||||
}
|
||||
|
||||
*cirs = registries
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cir *ContinualImprovementRegistry) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO continual_improvement_registries (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
source,
|
||||
owner_id,
|
||||
target_date,
|
||||
status,
|
||||
priority,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@reference_id,
|
||||
@description,
|
||||
@audit_id,
|
||||
@source,
|
||||
@owner_id,
|
||||
@target_date,
|
||||
@status,
|
||||
@priority,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cir.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"organization_id": cir.OrganizationID,
|
||||
"reference_id": cir.ReferenceID,
|
||||
"description": cir.Description,
|
||||
"audit_id": cir.AuditID,
|
||||
"source": cir.Source,
|
||||
"owner_id": cir.OwnerID,
|
||||
"target_date": cir.TargetDate,
|
||||
"status": cir.Status,
|
||||
"priority": cir.Priority,
|
||||
"created_at": cir.CreatedAt,
|
||||
"updated_at": cir.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cir *ContinualImprovementRegistry) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE continual_improvement_registries SET
|
||||
reference_id = @reference_id,
|
||||
description = @description,
|
||||
audit_id = @audit_id,
|
||||
source = @source,
|
||||
owner_id = @owner_id,
|
||||
target_date = @target_date,
|
||||
status = @status,
|
||||
priority = @priority,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": cir.ID,
|
||||
"reference_id": cir.ReferenceID,
|
||||
"description": cir.Description,
|
||||
"audit_id": cir.AuditID,
|
||||
"source": cir.Source,
|
||||
"owner_id": cir.OwnerID,
|
||||
"target_date": cir.TargetDate,
|
||||
"status": cir.Status,
|
||||
"priority": cir.Priority,
|
||||
"updated_at": cir.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cir *ContinualImprovementRegistry) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM continual_improvement_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": cir.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
55
pkg/coredata/continual_improvement_registries_order_field.go
Normal file
55
pkg/coredata/continual_improvement_registries_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 ContinualImprovementRegistriesOrderField string
|
||||
|
||||
const (
|
||||
ContinualImprovementRegistriesOrderFieldCreatedAt ContinualImprovementRegistriesOrderField = "CREATED_AT"
|
||||
ContinualImprovementRegistriesOrderFieldTargetDate ContinualImprovementRegistriesOrderField = "TARGET_DATE"
|
||||
ContinualImprovementRegistriesOrderFieldStatus ContinualImprovementRegistriesOrderField = "STATUS"
|
||||
ContinualImprovementRegistriesOrderFieldPriority ContinualImprovementRegistriesOrderField = "PRIORITY"
|
||||
ContinualImprovementRegistriesOrderFieldReferenceId ContinualImprovementRegistriesOrderField = "REFERENCE_ID"
|
||||
)
|
||||
|
||||
func (p ContinualImprovementRegistriesOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ContinualImprovementRegistriesOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p ContinualImprovementRegistriesOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *ContinualImprovementRegistriesOrderField) UnmarshalText(text []byte) error {
|
||||
val := string(text)
|
||||
switch val {
|
||||
case string(ContinualImprovementRegistriesOrderFieldCreatedAt),
|
||||
string(ContinualImprovementRegistriesOrderFieldTargetDate),
|
||||
string(ContinualImprovementRegistriesOrderFieldStatus),
|
||||
string(ContinualImprovementRegistriesOrderFieldPriority),
|
||||
string(ContinualImprovementRegistriesOrderFieldReferenceId):
|
||||
*p = ContinualImprovementRegistriesOrderField(val)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid ContinualImprovementRegistriesOrderField value: %q", val)
|
||||
}
|
||||
60
pkg/coredata/continual_improvement_registries_priority.go
Normal file
60
pkg/coredata/continual_improvement_registries_priority.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 ContinualImprovementRegistriesPriority string
|
||||
|
||||
const (
|
||||
ContinualImprovementRegistriesPriorityLow ContinualImprovementRegistriesPriority = "LOW"
|
||||
ContinualImprovementRegistriesPriorityMedium ContinualImprovementRegistriesPriority = "MEDIUM"
|
||||
ContinualImprovementRegistriesPriorityHigh ContinualImprovementRegistriesPriority = "HIGH"
|
||||
)
|
||||
|
||||
func (cirp ContinualImprovementRegistriesPriority) String() string {
|
||||
return string(cirp)
|
||||
}
|
||||
|
||||
func (cirp *ContinualImprovementRegistriesPriority) 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 ContinualImprovementRegistriesPriority: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "LOW":
|
||||
*cirp = ContinualImprovementRegistriesPriorityLow
|
||||
case "MEDIUM":
|
||||
*cirp = ContinualImprovementRegistriesPriorityMedium
|
||||
case "HIGH":
|
||||
*cirp = ContinualImprovementRegistriesPriorityHigh
|
||||
default:
|
||||
return fmt.Errorf("invalid ContinualImprovementRegistriesPriority value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cirp ContinualImprovementRegistriesPriority) Value() (driver.Value, error) {
|
||||
return cirp.String(), nil
|
||||
}
|
||||
60
pkg/coredata/continual_improvement_registries_status.go
Normal file
60
pkg/coredata/continual_improvement_registries_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 ContinualImprovementRegistriesStatus string
|
||||
|
||||
const (
|
||||
ContinualImprovementRegistriesStatusOpen ContinualImprovementRegistriesStatus = "OPEN"
|
||||
ContinualImprovementRegistriesStatusInProgress ContinualImprovementRegistriesStatus = "IN_PROGRESS"
|
||||
ContinualImprovementRegistriesStatusClosed ContinualImprovementRegistriesStatus = "CLOSED"
|
||||
)
|
||||
|
||||
func (cirs ContinualImprovementRegistriesStatus) String() string {
|
||||
return string(cirs)
|
||||
}
|
||||
|
||||
func (cirs *ContinualImprovementRegistriesStatus) 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 ContinualImprovementRegistriesStatus: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "OPEN":
|
||||
*cirs = ContinualImprovementRegistriesStatusOpen
|
||||
case "IN_PROGRESS":
|
||||
*cirs = ContinualImprovementRegistriesStatusInProgress
|
||||
case "CLOSED":
|
||||
*cirs = ContinualImprovementRegistriesStatusClosed
|
||||
default:
|
||||
return fmt.Errorf("invalid ContinualImprovementRegistriesStatus value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cirs ContinualImprovementRegistriesStatus) Value() (driver.Value, error) {
|
||||
return cirs.String(), nil
|
||||
}
|
||||
@@ -47,4 +47,5 @@ const (
|
||||
ComplianceRegistryEntityType
|
||||
VendorServiceEntityType
|
||||
SnapshotEntityType
|
||||
ContinualImprovementRegistryEntityType
|
||||
)
|
||||
|
||||
45
pkg/coredata/migrations/20250826T121441Z.sql
Normal file
45
pkg/coredata/migrations/20250826T121441Z.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
CREATE TYPE continual_improvement_registries_status AS ENUM (
|
||||
'OPEN',
|
||||
'IN_PROGRESS',
|
||||
'CLOSED'
|
||||
);
|
||||
|
||||
CREATE TYPE continual_improvement_registries_priority AS ENUM (
|
||||
'LOW',
|
||||
'MEDIUM',
|
||||
'HIGH'
|
||||
);
|
||||
|
||||
CREATE TABLE continual_improvement_registries (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id TEXT NOT NULL,
|
||||
organization_id TEXT NOT NULL,
|
||||
reference_id TEXT NOT NULL,
|
||||
description TEXT,
|
||||
audit_id TEXT NOT NULL,
|
||||
source TEXT,
|
||||
owner_id TEXT NOT NULL,
|
||||
target_date DATE,
|
||||
status continual_improvement_registries_status NOT NULL,
|
||||
priority continual_improvement_registries_priority NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
|
||||
CONSTRAINT continual_improvement_registries_organization_id_fkey
|
||||
FOREIGN KEY (organization_id)
|
||||
REFERENCES organizations(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT continual_improvement_registries_owner_id_fkey
|
||||
FOREIGN KEY (owner_id)
|
||||
REFERENCES peoples(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
|
||||
CONSTRAINT continual_improvement_registries_audit_id_fkey
|
||||
FOREIGN KEY (audit_id)
|
||||
REFERENCES audits(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
279
pkg/probo/continual_improvement_registries_service.go
Normal file
279
pkg/probo/continual_improvement_registries_service.go
Normal file
@@ -0,0 +1,279 @@
|
||||
// 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 ContinualImprovementRegistriesService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
type (
|
||||
CreateContinualImprovementRegistryRequest struct {
|
||||
OrganizationID gid.GID
|
||||
ReferenceID string
|
||||
Description *string
|
||||
AuditID gid.GID
|
||||
Source *string
|
||||
OwnerID gid.GID
|
||||
TargetDate *time.Time
|
||||
Status *coredata.ContinualImprovementRegistriesStatus
|
||||
Priority *coredata.ContinualImprovementRegistriesPriority
|
||||
}
|
||||
|
||||
UpdateContinualImprovementRegistryRequest struct {
|
||||
ID gid.GID
|
||||
ReferenceID *string
|
||||
Description **string
|
||||
AuditID *gid.GID
|
||||
Source **string
|
||||
OwnerID *gid.GID
|
||||
TargetDate **time.Time
|
||||
Status *coredata.ContinualImprovementRegistriesStatus
|
||||
Priority *coredata.ContinualImprovementRegistriesPriority
|
||||
}
|
||||
)
|
||||
|
||||
func (s ContinualImprovementRegistriesService) Get(
|
||||
ctx context.Context,
|
||||
continualImprovementRegistryID gid.GID,
|
||||
) (*coredata.ContinualImprovementRegistry, error) {
|
||||
registry := &coredata.ContinualImprovementRegistry{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := registry.LoadByID(ctx, conn, s.svc.scope, continualImprovementRegistryID); err != nil {
|
||||
return fmt.Errorf("cannot load continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ContinualImprovementRegistriesService) Create(
|
||||
ctx context.Context,
|
||||
req *CreateContinualImprovementRegistryRequest,
|
||||
) (*coredata.ContinualImprovementRegistry, error) {
|
||||
now := time.Now()
|
||||
|
||||
registry := &coredata.ContinualImprovementRegistry{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.ContinualImprovementRegistryEntityType),
|
||||
OrganizationID: req.OrganizationID,
|
||||
ReferenceID: req.ReferenceID,
|
||||
Description: req.Description,
|
||||
AuditID: req.AuditID,
|
||||
Source: req.Source,
|
||||
OwnerID: req.OwnerID,
|
||||
TargetDate: req.TargetDate,
|
||||
Status: *req.Status,
|
||||
Priority: *req.Priority,
|
||||
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 continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ContinualImprovementRegistriesService) Update(
|
||||
ctx context.Context,
|
||||
req *UpdateContinualImprovementRegistryRequest,
|
||||
) (*coredata.ContinualImprovementRegistry, error) {
|
||||
registry := &coredata.ContinualImprovementRegistry{}
|
||||
|
||||
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 continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
if req.ReferenceID != nil {
|
||||
registry.ReferenceID = *req.ReferenceID
|
||||
}
|
||||
|
||||
if req.Description != nil {
|
||||
registry.Description = *req.Description
|
||||
}
|
||||
|
||||
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.Source != nil {
|
||||
registry.Source = *req.Source
|
||||
}
|
||||
|
||||
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.TargetDate != nil {
|
||||
registry.TargetDate = *req.TargetDate
|
||||
}
|
||||
|
||||
if req.Status != nil {
|
||||
registry.Status = *req.Status
|
||||
}
|
||||
|
||||
if req.Priority != nil {
|
||||
registry.Priority = *req.Priority
|
||||
}
|
||||
|
||||
registry.UpdatedAt = time.Now()
|
||||
|
||||
if err := registry.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *ContinualImprovementRegistriesService) Delete(
|
||||
ctx context.Context,
|
||||
continualImprovementRegistryID gid.GID,
|
||||
) error {
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
registry := &coredata.ContinualImprovementRegistry{}
|
||||
if err := registry.LoadByID(ctx, conn, s.svc.scope, continualImprovementRegistryID); err != nil {
|
||||
return fmt.Errorf("cannot load continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
if err := registry.Delete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete continual improvement registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s ContinualImprovementRegistriesService) 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.ContinualImprovementRegistries{}
|
||||
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count continual improvement registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s ContinualImprovementRegistriesService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.ContinualImprovementRegistriesOrderField],
|
||||
) (*page.Page[*coredata.ContinualImprovementRegistry, coredata.ContinualImprovementRegistriesOrderField], error) {
|
||||
var registries coredata.ContinualImprovementRegistries
|
||||
|
||||
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 continual improvement registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(registries, cursor), nil
|
||||
}
|
||||
@@ -85,6 +85,7 @@ type (
|
||||
NonconformityRegistries *NonconformityRegistryService
|
||||
ComplianceRegistries *ComplianceRegistryService
|
||||
Snapshots *SnapshotService
|
||||
ContinualImprovementRegistries *ContinualImprovementRegistriesService
|
||||
}
|
||||
)
|
||||
|
||||
@@ -174,12 +175,10 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
tenantService.Audits = &AuditService{svc: tenantService}
|
||||
tenantService.Reports = &ReportService{svc: tenantService}
|
||||
tenantService.TrustCenters = &TrustCenterService{svc: tenantService}
|
||||
tenantService.TrustCenterAccesses = &TrustCenterAccessService{
|
||||
svc: tenantService,
|
||||
usrmgr: s.usrmgr,
|
||||
}
|
||||
tenantService.TrustCenterAccesses = &TrustCenterAccessService{svc: tenantService, usrmgr: s.usrmgr}
|
||||
tenantService.NonconformityRegistries = &NonconformityRegistryService{svc: tenantService}
|
||||
tenantService.ComplianceRegistries = &ComplianceRegistryService{svc: tenantService}
|
||||
tenantService.Snapshots = &SnapshotService{svc: tenantService}
|
||||
tenantService.ContinualImprovementRegistries = &ContinualImprovementRegistriesService{svc: tenantService}
|
||||
return tenantService
|
||||
}
|
||||
|
||||
@@ -183,6 +183,38 @@ enum ComplianceRegistryStatus
|
||||
)
|
||||
}
|
||||
|
||||
enum ContinualImprovementRegistriesStatus
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesStatus") {
|
||||
OPEN
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesStatusOpen"
|
||||
)
|
||||
IN_PROGRESS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesStatusInProgress"
|
||||
)
|
||||
CLOSED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesStatusClosed"
|
||||
)
|
||||
}
|
||||
|
||||
enum ContinualImprovementRegistriesPriority
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesPriority") {
|
||||
LOW
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesPriorityLow"
|
||||
)
|
||||
MEDIUM
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesPriorityMedium"
|
||||
)
|
||||
HIGH
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesPriorityHigh"
|
||||
)
|
||||
}
|
||||
|
||||
# Order Field Enums
|
||||
enum UserOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.UserOrderField") {
|
||||
@@ -678,6 +710,30 @@ enum ComplianceRegistryOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum ContinualImprovementRegistriesOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderFieldCreatedAt"
|
||||
)
|
||||
REFERENCE_ID
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderFieldReferenceId"
|
||||
)
|
||||
TARGET_DATE
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderFieldTargetDate"
|
||||
)
|
||||
STATUS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderFieldStatus"
|
||||
)
|
||||
PRIORITY
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.ContinualImprovementRegistriesOrderFieldPriority"
|
||||
)
|
||||
}
|
||||
|
||||
enum TrustCenterAccessOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.TrustCenterAccessOrderField") {
|
||||
CREATED_AT
|
||||
@@ -827,6 +883,14 @@ input ComplianceRegistryOrder
|
||||
field: ComplianceRegistryOrderField!
|
||||
}
|
||||
|
||||
input ContinualImprovementRegistriesOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.ContinualImprovementRegistriesOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: ContinualImprovementRegistriesOrderField!
|
||||
}
|
||||
|
||||
input TrustCenterAccessOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterAccessOrderBy"
|
||||
@@ -1079,6 +1143,14 @@ type Organization implements Node {
|
||||
orderBy: ComplianceRegistryOrder
|
||||
): ComplianceRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
continualImprovementRegistries(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: ContinualImprovementRegistriesOrder
|
||||
): ContinualImprovementRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
snapshots(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
@@ -1539,6 +1611,21 @@ type ComplianceRegistry implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type ContinualImprovementRegistry implements Node {
|
||||
id: ID!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
referenceId: String!
|
||||
description: String
|
||||
audit: Audit! @goField(forceResolver: true)
|
||||
source: String
|
||||
owner: People! @goField(forceResolver: true)
|
||||
targetDate: Datetime
|
||||
status: ContinualImprovementRegistriesStatus!
|
||||
priority: ContinualImprovementRegistriesPriority!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Snapshot implements Node {
|
||||
id: ID!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
@@ -1880,6 +1967,20 @@ type ComplianceRegistryEdge {
|
||||
node: ComplianceRegistry!
|
||||
}
|
||||
|
||||
type ContinualImprovementRegistryConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.ContinualImprovementRegistryConnection"
|
||||
) {
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
edges: [ContinualImprovementRegistryEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type ContinualImprovementRegistryEdge {
|
||||
cursor: CursorKey!
|
||||
node: ContinualImprovementRegistry!
|
||||
}
|
||||
|
||||
type SnapshotConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.SnapshotConnection"
|
||||
@@ -2151,6 +2252,17 @@ type Mutation {
|
||||
input: DeleteComplianceRegistryInput!
|
||||
): DeleteComplianceRegistryPayload!
|
||||
|
||||
# Continual Improvement Registry mutations
|
||||
createContinualImprovementRegistry(
|
||||
input: CreateContinualImprovementRegistryInput!
|
||||
): CreateContinualImprovementRegistryPayload!
|
||||
updateContinualImprovementRegistry(
|
||||
input: UpdateContinualImprovementRegistryInput!
|
||||
): UpdateContinualImprovementRegistryPayload!
|
||||
deleteContinualImprovementRegistry(
|
||||
input: DeleteContinualImprovementRegistryInput!
|
||||
): DeleteContinualImprovementRegistryPayload!
|
||||
|
||||
# Snapshot mutations
|
||||
createSnapshot(input: CreateSnapshotInput!): CreateSnapshotPayload!
|
||||
deleteSnapshot(input: DeleteSnapshotInput!): DeleteSnapshotPayload!
|
||||
@@ -2719,6 +2831,34 @@ input DeleteComplianceRegistryInput {
|
||||
complianceRegistryId: ID!
|
||||
}
|
||||
|
||||
input CreateContinualImprovementRegistryInput {
|
||||
organizationId: ID!
|
||||
referenceId: String!
|
||||
description: String
|
||||
auditId: ID!
|
||||
source: String
|
||||
ownerId: ID!
|
||||
targetDate: Datetime
|
||||
status: ContinualImprovementRegistriesStatus!
|
||||
priority: ContinualImprovementRegistriesPriority!
|
||||
}
|
||||
|
||||
input UpdateContinualImprovementRegistryInput {
|
||||
id: ID!
|
||||
referenceId: String
|
||||
description: String
|
||||
auditId: ID
|
||||
source: String
|
||||
ownerId: ID
|
||||
targetDate: Datetime
|
||||
status: ContinualImprovementRegistriesStatus
|
||||
priority: ContinualImprovementRegistriesPriority
|
||||
}
|
||||
|
||||
input DeleteContinualImprovementRegistryInput {
|
||||
continualImprovementRegistryId: ID!
|
||||
}
|
||||
|
||||
input CreateSnapshotInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
@@ -3450,6 +3590,18 @@ type DeleteComplianceRegistryPayload {
|
||||
deletedComplianceRegistryId: ID!
|
||||
}
|
||||
|
||||
type CreateContinualImprovementRegistryPayload {
|
||||
continualImprovementRegistryEdge: ContinualImprovementRegistryEdge!
|
||||
}
|
||||
|
||||
type UpdateContinualImprovementRegistryPayload {
|
||||
continualImprovementRegistry: ContinualImprovementRegistry!
|
||||
}
|
||||
|
||||
type DeleteContinualImprovementRegistryPayload {
|
||||
deletedContinualImprovementRegistryId: ID!
|
||||
}
|
||||
|
||||
type CreateSnapshotPayload {
|
||||
snapshotEdge: SnapshotEdge!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,74 @@
|
||||
// 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 (
|
||||
ContinualImprovementRegistriesOrderBy OrderBy[coredata.ContinualImprovementRegistriesOrderField]
|
||||
|
||||
ContinualImprovementRegistryConnection struct {
|
||||
TotalCount int
|
||||
Edges []*ContinualImprovementRegistryEdge
|
||||
PageInfo PageInfo
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func NewContinualImprovementRegistryConnection(
|
||||
p *page.Page[*coredata.ContinualImprovementRegistry, coredata.ContinualImprovementRegistriesOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
) *ContinualImprovementRegistryConnection {
|
||||
edges := make([]*ContinualImprovementRegistryEdge, len(p.Data))
|
||||
for i, registry := range p.Data {
|
||||
edges[i] = NewContinualImprovementRegistryEdge(registry, p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &ContinualImprovementRegistryConnection{
|
||||
Edges: edges,
|
||||
PageInfo: *NewPageInfo(p),
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewContinualImprovementRegistry(cir *coredata.ContinualImprovementRegistry) *ContinualImprovementRegistry {
|
||||
return &ContinualImprovementRegistry{
|
||||
ID: cir.ID,
|
||||
ReferenceID: cir.ReferenceID,
|
||||
Description: cir.Description,
|
||||
Source: cir.Source,
|
||||
TargetDate: cir.TargetDate,
|
||||
Status: cir.Status,
|
||||
Priority: cir.Priority,
|
||||
CreatedAt: cir.CreatedAt,
|
||||
UpdatedAt: cir.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewContinualImprovementRegistryEdge(cir *coredata.ContinualImprovementRegistry, orderField coredata.ContinualImprovementRegistriesOrderField) *ContinualImprovementRegistryEdge {
|
||||
return &ContinualImprovementRegistryEdge{
|
||||
Node: NewContinualImprovementRegistry(cir),
|
||||
Cursor: cir.CursorKey(orderField),
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,29 @@ type ConnectorOrder struct {
|
||||
Direction page.OrderDirection `json:"direction"`
|
||||
}
|
||||
|
||||
type ContinualImprovementRegistry struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Organization *Organization `json:"organization"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Audit *Audit `json:"audit"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
Owner *People `json:"owner"`
|
||||
TargetDate *time.Time `json:"targetDate,omitempty"`
|
||||
Status coredata.ContinualImprovementRegistriesStatus `json:"status"`
|
||||
Priority coredata.ContinualImprovementRegistriesPriority `json:"priority"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (ContinualImprovementRegistry) IsNode() {}
|
||||
func (this ContinualImprovementRegistry) GetID() gid.GID { return this.ID }
|
||||
|
||||
type ContinualImprovementRegistryEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *ContinualImprovementRegistry `json:"node"`
|
||||
}
|
||||
|
||||
type Control struct {
|
||||
ID gid.GID `json:"id"`
|
||||
SectionTitle string `json:"sectionTitle"`
|
||||
@@ -242,6 +265,22 @@ type CreateComplianceRegistryPayload struct {
|
||||
ComplianceRegistryEdge *ComplianceRegistryEdge `json:"complianceRegistryEdge"`
|
||||
}
|
||||
|
||||
type CreateContinualImprovementRegistryInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
OwnerID gid.GID `json:"ownerId"`
|
||||
TargetDate *time.Time `json:"targetDate,omitempty"`
|
||||
Status coredata.ContinualImprovementRegistriesStatus `json:"status"`
|
||||
Priority coredata.ContinualImprovementRegistriesPriority `json:"priority"`
|
||||
}
|
||||
|
||||
type CreateContinualImprovementRegistryPayload struct {
|
||||
ContinualImprovementRegistryEdge *ContinualImprovementRegistryEdge `json:"continualImprovementRegistryEdge"`
|
||||
}
|
||||
|
||||
type CreateControlAuditMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
@@ -595,6 +634,14 @@ type DeleteComplianceRegistryPayload struct {
|
||||
DeletedComplianceRegistryID gid.GID `json:"deletedComplianceRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteContinualImprovementRegistryInput struct {
|
||||
ContinualImprovementRegistryID gid.GID `json:"continualImprovementRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteContinualImprovementRegistryPayload struct {
|
||||
DeletedContinualImprovementRegistryID gid.GID `json:"deletedContinualImprovementRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteControlAuditMappingInput struct {
|
||||
ControlID gid.GID `json:"controlId"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
@@ -1065,28 +1112,29 @@ type NonconformityRegistryEdge struct {
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LogoURL *string `json:"logoUrl,omitempty"`
|
||||
Users *UserConnection `json:"users"`
|
||||
Connectors *ConnectorConnection `json:"connectors"`
|
||||
Frameworks *FrameworkConnection `json:"frameworks"`
|
||||
Controls *ControlConnection `json:"controls"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
Documents *DocumentConnection `json:"documents"`
|
||||
Measures *MeasureConnection `json:"measures"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
Assets *AssetConnection `json:"assets"`
|
||||
Data *DatumConnection `json:"data"`
|
||||
Audits *AuditConnection `json:"audits"`
|
||||
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
|
||||
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
|
||||
Snapshots *SnapshotConnection `json:"snapshots"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
LogoURL *string `json:"logoUrl,omitempty"`
|
||||
Users *UserConnection `json:"users"`
|
||||
Connectors *ConnectorConnection `json:"connectors"`
|
||||
Frameworks *FrameworkConnection `json:"frameworks"`
|
||||
Controls *ControlConnection `json:"controls"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
Documents *DocumentConnection `json:"documents"`
|
||||
Measures *MeasureConnection `json:"measures"`
|
||||
Risks *RiskConnection `json:"risks"`
|
||||
Tasks *TaskConnection `json:"tasks"`
|
||||
Assets *AssetConnection `json:"assets"`
|
||||
Data *DatumConnection `json:"data"`
|
||||
Audits *AuditConnection `json:"audits"`
|
||||
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
|
||||
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
|
||||
ContinualImprovementRegistries *ContinualImprovementRegistryConnection `json:"continualImprovementRegistries"`
|
||||
Snapshots *SnapshotConnection `json:"snapshots"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Organization) IsNode() {}
|
||||
@@ -1391,6 +1439,22 @@ type UpdateComplianceRegistryPayload struct {
|
||||
ComplianceRegistry *ComplianceRegistry `json:"complianceRegistry"`
|
||||
}
|
||||
|
||||
type UpdateContinualImprovementRegistryInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
ReferenceID *string `json:"referenceId,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
AuditID *gid.GID `json:"auditId,omitempty"`
|
||||
Source *string `json:"source,omitempty"`
|
||||
OwnerID *gid.GID `json:"ownerId,omitempty"`
|
||||
TargetDate *time.Time `json:"targetDate,omitempty"`
|
||||
Status *coredata.ContinualImprovementRegistriesStatus `json:"status,omitempty"`
|
||||
Priority *coredata.ContinualImprovementRegistriesPriority `json:"priority,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateContinualImprovementRegistryPayload struct {
|
||||
ContinualImprovementRegistry *ContinualImprovementRegistry `json:"continualImprovementRegistry"`
|
||||
}
|
||||
|
||||
type UpdateControlInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
SectionTitle *string `json:"sectionTitle,omitempty"`
|
||||
|
||||
@@ -287,6 +287,73 @@ func (r *complianceRegistryConnectionResolver) TotalCount(ctx context.Context, o
|
||||
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
||||
}
|
||||
|
||||
// Organization is the resolver for the organization field.
|
||||
func (r *continualImprovementRegistryResolver) Organization(ctx context.Context, obj *types.ContinualImprovementRegistry) (*types.Organization, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ContinualImprovementRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
organization, err := prb.Organizations.Get(ctx, registry.OrganizationID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry organization: %w", err))
|
||||
}
|
||||
|
||||
return types.NewOrganization(organization), nil
|
||||
}
|
||||
|
||||
// Audit is the resolver for the audit field.
|
||||
func (r *continualImprovementRegistryResolver) Audit(ctx context.Context, obj *types.ContinualImprovementRegistry) (*types.Audit, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ContinualImprovementRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
audit, err := prb.Audits.Get(ctx, registry.AuditID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry audit: %w", err))
|
||||
}
|
||||
|
||||
return types.NewAudit(audit), nil
|
||||
}
|
||||
|
||||
// Owner is the resolver for the owner field.
|
||||
func (r *continualImprovementRegistryResolver) Owner(ctx context.Context, obj *types.ContinualImprovementRegistry) (*types.People, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.ContinualImprovementRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
people, err := prb.Peoples.Get(ctx, registry.OwnerID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry owner: %w", err))
|
||||
}
|
||||
|
||||
return types.NewPeople(people), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *continualImprovementRegistryConnectionResolver) TotalCount(ctx context.Context, obj *types.ContinualImprovementRegistryConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.ContinualImprovementRegistries.CountByOrganizationID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot count continual improvement 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())
|
||||
@@ -3051,6 +3118,72 @@ func (r *mutationResolver) DeleteComplianceRegistry(ctx context.Context, input t
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateContinualImprovementRegistry is the resolver for the createContinualImprovementRegistry field.
|
||||
func (r *mutationResolver) CreateContinualImprovementRegistry(ctx context.Context, input types.CreateContinualImprovementRegistryInput) (*types.CreateContinualImprovementRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
req := probo.CreateContinualImprovementRegistryRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Description: input.Description,
|
||||
AuditID: input.AuditID,
|
||||
Source: input.Source,
|
||||
OwnerID: input.OwnerID,
|
||||
TargetDate: input.TargetDate,
|
||||
Status: &input.Status,
|
||||
Priority: &input.Priority,
|
||||
}
|
||||
|
||||
registry, err := prb.ContinualImprovementRegistries.Create(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.CreateContinualImprovementRegistryPayload{
|
||||
ContinualImprovementRegistryEdge: types.NewContinualImprovementRegistryEdge(registry, coredata.ContinualImprovementRegistriesOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateContinualImprovementRegistry is the resolver for the updateContinualImprovementRegistry field.
|
||||
func (r *mutationResolver) UpdateContinualImprovementRegistry(ctx context.Context, input types.UpdateContinualImprovementRegistryInput) (*types.UpdateContinualImprovementRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
req := probo.UpdateContinualImprovementRegistryRequest{
|
||||
ID: input.ID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Description: &input.Description,
|
||||
AuditID: input.AuditID,
|
||||
Source: &input.Source,
|
||||
OwnerID: input.OwnerID,
|
||||
TargetDate: &input.TargetDate,
|
||||
Status: input.Status,
|
||||
Priority: input.Priority,
|
||||
}
|
||||
|
||||
registry, err := prb.ContinualImprovementRegistries.Update(ctx, &req)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.UpdateContinualImprovementRegistryPayload{
|
||||
ContinualImprovementRegistry: types.NewContinualImprovementRegistry(registry),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteContinualImprovementRegistry is the resolver for the deleteContinualImprovementRegistry field.
|
||||
func (r *mutationResolver) DeleteContinualImprovementRegistry(ctx context.Context, input types.DeleteContinualImprovementRegistryInput) (*types.DeleteContinualImprovementRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.ContinualImprovementRegistryID.TenantID())
|
||||
|
||||
err := prb.ContinualImprovementRegistries.Delete(ctx, input.ContinualImprovementRegistryID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete continual improvement registry: %w", err))
|
||||
}
|
||||
|
||||
return &types.DeleteContinualImprovementRegistryPayload{
|
||||
DeletedContinualImprovementRegistryID: input.ContinualImprovementRegistryID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateSnapshot is the resolver for the createSnapshot field.
|
||||
func (r *mutationResolver) CreateSnapshot(ctx context.Context, input types.CreateSnapshotInput) (*types.CreateSnapshotPayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
@@ -3562,6 +3695,32 @@ func (r *organizationResolver) ComplianceRegistries(ctx context.Context, obj *ty
|
||||
return types.NewComplianceRegistryConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// ContinualImprovementRegistries is the resolver for the continualImprovementRegistries field.
|
||||
func (r *organizationResolver) ContinualImprovementRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ContinualImprovementRegistriesOrderBy) (*types.ContinualImprovementRegistryConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.ContinualImprovementRegistriesOrderField]{
|
||||
Field: coredata.ContinualImprovementRegistriesOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.ContinualImprovementRegistriesOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.ContinualImprovementRegistries.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization continual improvement registries: %w", err))
|
||||
}
|
||||
|
||||
return types.NewContinualImprovementRegistryConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// Snapshots is the resolver for the snapshots field.
|
||||
func (r *organizationResolver) Snapshots(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.SnapshotOrderBy) (*types.SnapshotConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3748,6 +3907,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
||||
panic(fmt.Errorf("cannot get compliance registry: %w", err))
|
||||
}
|
||||
return types.NewComplianceRegistry(complianceRegistry), nil
|
||||
case coredata.ContinualImprovementRegistryEntityType:
|
||||
continualImprovementRegistry, err := prb.ContinualImprovementRegistries.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get continual improvement registry: %w", err))
|
||||
}
|
||||
return types.NewContinualImprovementRegistry(continualImprovementRegistry), nil
|
||||
case coredata.ReportEntityType:
|
||||
report, err := prb.Reports.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -4568,6 +4733,16 @@ func (r *Resolver) ComplianceRegistryConnection() schema.ComplianceRegistryConne
|
||||
return &complianceRegistryConnectionResolver{r}
|
||||
}
|
||||
|
||||
// ContinualImprovementRegistry returns schema.ContinualImprovementRegistryResolver implementation.
|
||||
func (r *Resolver) ContinualImprovementRegistry() schema.ContinualImprovementRegistryResolver {
|
||||
return &continualImprovementRegistryResolver{r}
|
||||
}
|
||||
|
||||
// ContinualImprovementRegistryConnection returns schema.ContinualImprovementRegistryConnectionResolver implementation.
|
||||
func (r *Resolver) ContinualImprovementRegistryConnection() schema.ContinualImprovementRegistryConnectionResolver {
|
||||
return &continualImprovementRegistryConnectionResolver{r}
|
||||
}
|
||||
|
||||
// Control returns schema.ControlResolver implementation.
|
||||
func (r *Resolver) Control() schema.ControlResolver { return &controlResolver{r} }
|
||||
|
||||
@@ -4722,6 +4897,8 @@ type auditResolver struct{ *Resolver }
|
||||
type auditConnectionResolver struct{ *Resolver }
|
||||
type complianceRegistryResolver struct{ *Resolver }
|
||||
type complianceRegistryConnectionResolver struct{ *Resolver }
|
||||
type continualImprovementRegistryResolver struct{ *Resolver }
|
||||
type continualImprovementRegistryConnectionResolver struct{ *Resolver }
|
||||
type controlResolver struct{ *Resolver }
|
||||
type controlConnectionResolver struct{ *Resolver }
|
||||
type datumResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user