Add nonconformity registries
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -43,4 +43,5 @@ const (
|
||||
FileEntityType
|
||||
VendorContactEntityType
|
||||
VendorDataPrivacyAgreementEntityType
|
||||
NonconformityRegistryEntityType
|
||||
)
|
||||
|
||||
41
pkg/coredata/migrations/20250814T091852Z.sql
Normal file
41
pkg/coredata/migrations/20250814T091852Z.sql
Normal file
@@ -0,0 +1,41 @@
|
||||
CREATE TYPE nonconformity_registries_status AS ENUM (
|
||||
'OPEN',
|
||||
'IN_PROGRESS',
|
||||
'CLOSED'
|
||||
);
|
||||
|
||||
CREATE TABLE nonconformity_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,
|
||||
date_identified DATE,
|
||||
root_cause TEXT NOT NULL,
|
||||
corrective_action TEXT,
|
||||
owner_id TEXT NOT NULL,
|
||||
due_date DATE,
|
||||
status nonconformity_registries_status NOT NULL,
|
||||
effectiveness_check TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
|
||||
CONSTRAINT nonconformity_registries_organization_id_fkey
|
||||
FOREIGN KEY (organization_id)
|
||||
REFERENCES organizations(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT nonconformity_registries_owner_id_fkey
|
||||
FOREIGN KEY (owner_id)
|
||||
REFERENCES peoples(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
|
||||
CONSTRAINT nonconformity_registries_audit_id_fkey
|
||||
FOREIGN KEY (audit_id)
|
||||
REFERENCES audits(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
341
pkg/coredata/nonconformity_registry.go
Normal file
341
pkg/coredata/nonconformity_registry.go
Normal file
@@ -0,0 +1,341 @@
|
||||
// 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 (
|
||||
NonconformityRegistry 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"`
|
||||
DateIdentified *time.Time `db:"date_identified"`
|
||||
RootCause string `db:"root_cause"`
|
||||
CorrectiveAction *string `db:"corrective_action"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
DueDate *time.Time `db:"due_date"`
|
||||
Status NonconformityRegistryStatus `db:"status"`
|
||||
EffectivenessCheck *string `db:"effectiveness_check"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
NonconformityRegistries []*NonconformityRegistry
|
||||
)
|
||||
|
||||
func (nr *NonconformityRegistry) CursorKey(field NonconformityRegistryOrderField) page.CursorKey {
|
||||
switch field {
|
||||
case NonconformityRegistryOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(nr.ID, nr.CreatedAt)
|
||||
case NonconformityRegistryOrderFieldDateIdentified:
|
||||
return page.NewCursorKey(nr.ID, nr.DateIdentified)
|
||||
case NonconformityRegistryOrderFieldDueDate:
|
||||
return page.NewCursorKey(nr.ID, nr.DueDate)
|
||||
case NonconformityRegistryOrderFieldStatus:
|
||||
return page.NewCursorKey(nr.ID, nr.Status)
|
||||
case NonconformityRegistryOrderFieldReferenceId:
|
||||
return page.NewCursorKey(nr.ID, nr.ReferenceID)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", field))
|
||||
}
|
||||
|
||||
func (nr *NonconformityRegistry) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
nonconformityRegistryID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
date_identified,
|
||||
root_cause,
|
||||
corrective_action,
|
||||
owner_id,
|
||||
due_date,
|
||||
status,
|
||||
effectiveness_check,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
nonconformity_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @nonconformity_registry_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"nonconformity_registry_id": nonconformityRegistryID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
registry, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[NonconformityRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
*nr = registry
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nrs *NonconformityRegistries) CountByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(id)
|
||||
FROM
|
||||
nonconformity_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 nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (nrs *NonconformityRegistries) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[NonconformityRegistryOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
date_identified,
|
||||
root_cause,
|
||||
corrective_action,
|
||||
owner_id,
|
||||
due_date,
|
||||
status,
|
||||
effectiveness_check,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
nonconformity_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 nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
registries, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[NonconformityRegistry])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
*nrs = registries
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nr *NonconformityRegistry) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO nonconformity_registries (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
reference_id,
|
||||
description,
|
||||
audit_id,
|
||||
date_identified,
|
||||
root_cause,
|
||||
corrective_action,
|
||||
owner_id,
|
||||
due_date,
|
||||
status,
|
||||
effectiveness_check,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@reference_id,
|
||||
@description,
|
||||
@audit_id,
|
||||
@date_identified,
|
||||
@root_cause,
|
||||
@corrective_action,
|
||||
@owner_id,
|
||||
@due_date,
|
||||
@status,
|
||||
@effectiveness_check,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": nr.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"organization_id": nr.OrganizationID,
|
||||
"reference_id": nr.ReferenceID,
|
||||
"description": nr.Description,
|
||||
"audit_id": nr.AuditID,
|
||||
"date_identified": nr.DateIdentified,
|
||||
"root_cause": nr.RootCause,
|
||||
"corrective_action": nr.CorrectiveAction,
|
||||
"owner_id": nr.OwnerID,
|
||||
"due_date": nr.DueDate,
|
||||
"status": nr.Status,
|
||||
"effectiveness_check": nr.EffectivenessCheck,
|
||||
"created_at": nr.CreatedAt,
|
||||
"updated_at": nr.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nr *NonconformityRegistry) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE nonconformity_registries
|
||||
SET
|
||||
reference_id = @reference_id,
|
||||
description = @description,
|
||||
date_identified = @date_identified,
|
||||
root_cause = @root_cause,
|
||||
corrective_action = @corrective_action,
|
||||
due_date = @due_date,
|
||||
status = @status,
|
||||
effectiveness_check = @effectiveness_check,
|
||||
owner_id = @owner_id,
|
||||
audit_id = @audit_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": nr.ID,
|
||||
"reference_id": nr.ReferenceID,
|
||||
"description": nr.Description,
|
||||
"date_identified": nr.DateIdentified,
|
||||
"root_cause": nr.RootCause,
|
||||
"corrective_action": nr.CorrectiveAction,
|
||||
"due_date": nr.DueDate,
|
||||
"status": nr.Status,
|
||||
"effectiveness_check": nr.EffectivenessCheck,
|
||||
"owner_id": nr.OwnerID,
|
||||
"audit_id": nr.AuditID,
|
||||
"updated_at": nr.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nr *NonconformityRegistry) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM nonconformity_registries
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": nr.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
55
pkg/coredata/nonconformity_registry_order_field.go
Normal file
55
pkg/coredata/nonconformity_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 NonconformityRegistryOrderField string
|
||||
|
||||
const (
|
||||
NonconformityRegistryOrderFieldCreatedAt NonconformityRegistryOrderField = "CREATED_AT"
|
||||
NonconformityRegistryOrderFieldDateIdentified NonconformityRegistryOrderField = "DATE_IDENTIFIED"
|
||||
NonconformityRegistryOrderFieldDueDate NonconformityRegistryOrderField = "DUE_DATE"
|
||||
NonconformityRegistryOrderFieldStatus NonconformityRegistryOrderField = "STATUS"
|
||||
NonconformityRegistryOrderFieldReferenceId NonconformityRegistryOrderField = "REFERENCE_ID"
|
||||
)
|
||||
|
||||
func (p NonconformityRegistryOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p NonconformityRegistryOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p NonconformityRegistryOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *NonconformityRegistryOrderField) UnmarshalText(text []byte) error {
|
||||
val := string(text)
|
||||
switch val {
|
||||
case string(NonconformityRegistryOrderFieldCreatedAt),
|
||||
string(NonconformityRegistryOrderFieldDateIdentified),
|
||||
string(NonconformityRegistryOrderFieldDueDate),
|
||||
string(NonconformityRegistryOrderFieldStatus),
|
||||
string(NonconformityRegistryOrderFieldReferenceId):
|
||||
*p = NonconformityRegistryOrderField(val)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid NonconformityRegistryOrderField value: %q", val)
|
||||
}
|
||||
60
pkg/coredata/nonconformity_registry_status.go
Normal file
60
pkg/coredata/nonconformity_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 NonconformityRegistryStatus string
|
||||
|
||||
const (
|
||||
NonconformityRegistryStatusOpen NonconformityRegistryStatus = "OPEN"
|
||||
NonconformityRegistryStatusInProgress NonconformityRegistryStatus = "IN_PROGRESS"
|
||||
NonconformityRegistryStatusClosed NonconformityRegistryStatus = "CLOSED"
|
||||
)
|
||||
|
||||
func (nrs NonconformityRegistryStatus) String() string {
|
||||
return string(nrs)
|
||||
}
|
||||
|
||||
func (nrs *NonconformityRegistryStatus) 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 NonconformityRegistryStatus: %T", value)
|
||||
}
|
||||
|
||||
switch s {
|
||||
case "OPEN":
|
||||
*nrs = NonconformityRegistryStatusOpen
|
||||
case "IN_PROGRESS":
|
||||
*nrs = NonconformityRegistryStatusInProgress
|
||||
case "CLOSED":
|
||||
*nrs = NonconformityRegistryStatusClosed
|
||||
default:
|
||||
return fmt.Errorf("invalid NonconformityRegistryStatus value: %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nrs NonconformityRegistryStatus) Value() (driver.Value, error) {
|
||||
return nrs.String(), nil
|
||||
}
|
||||
270
pkg/probo/nonconformity_registry_service.go
Normal file
270
pkg/probo/nonconformity_registry_service.go
Normal file
@@ -0,0 +1,270 @@
|
||||
// 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 NonconformityRegistryService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
type (
|
||||
CreateNonconformityRegistryRequest struct {
|
||||
OrganizationID gid.GID
|
||||
ReferenceID string
|
||||
Description *string
|
||||
AuditID gid.GID
|
||||
DateIdentified *time.Time
|
||||
RootCause string
|
||||
CorrectiveAction *string
|
||||
OwnerID gid.GID
|
||||
DueDate *time.Time
|
||||
Status *coredata.NonconformityRegistryStatus
|
||||
EffectivenessCheck *string
|
||||
}
|
||||
|
||||
UpdateNonconformityRegistryRequest struct {
|
||||
ID gid.GID
|
||||
ReferenceID *string
|
||||
Description **string
|
||||
DateIdentified **time.Time
|
||||
RootCause *string
|
||||
CorrectiveAction **string
|
||||
OwnerID *gid.GID
|
||||
AuditID *gid.GID
|
||||
DueDate **time.Time
|
||||
Status *coredata.NonconformityRegistryStatus
|
||||
EffectivenessCheck **string
|
||||
}
|
||||
)
|
||||
|
||||
func (s NonconformityRegistryService) Get(
|
||||
ctx context.Context,
|
||||
nonconformityRegistryID gid.GID,
|
||||
) (*coredata.NonconformityRegistry, error) {
|
||||
registry := &coredata.NonconformityRegistry{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return registry.LoadByID(ctx, conn, s.svc.scope, nonconformityRegistryID)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *NonconformityRegistryService) Create(
|
||||
ctx context.Context,
|
||||
req *CreateNonconformityRegistryRequest,
|
||||
) (*coredata.NonconformityRegistry, error) {
|
||||
now := time.Now()
|
||||
|
||||
registry := &coredata.NonconformityRegistry{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.NonconformityRegistryEntityType),
|
||||
OrganizationID: req.OrganizationID,
|
||||
ReferenceID: req.ReferenceID,
|
||||
Description: req.Description,
|
||||
AuditID: req.AuditID,
|
||||
DateIdentified: req.DateIdentified,
|
||||
RootCause: req.RootCause,
|
||||
CorrectiveAction: req.CorrectiveAction,
|
||||
OwnerID: req.OwnerID,
|
||||
DueDate: req.DueDate,
|
||||
Status: coredata.NonconformityRegistryStatusOpen,
|
||||
EffectivenessCheck: req.EffectivenessCheck,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if req.Status != nil {
|
||||
registry.Status = *req.Status
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
people := &coredata.People{}
|
||||
if err := people.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 nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s *NonconformityRegistryService) Update(
|
||||
ctx context.Context,
|
||||
req *UpdateNonconformityRegistryRequest,
|
||||
) (*coredata.NonconformityRegistry, error) {
|
||||
registry := &coredata.NonconformityRegistry{}
|
||||
|
||||
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 nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
if req.ReferenceID != nil {
|
||||
registry.ReferenceID = *req.ReferenceID
|
||||
}
|
||||
if req.Description != nil {
|
||||
registry.Description = *req.Description
|
||||
}
|
||||
if req.DateIdentified != nil {
|
||||
registry.DateIdentified = *req.DateIdentified
|
||||
}
|
||||
if req.RootCause != nil {
|
||||
registry.RootCause = *req.RootCause
|
||||
}
|
||||
if req.CorrectiveAction != nil {
|
||||
registry.CorrectiveAction = *req.CorrectiveAction
|
||||
}
|
||||
if req.OwnerID != nil {
|
||||
registry.OwnerID = *req.OwnerID
|
||||
}
|
||||
if req.AuditID != nil {
|
||||
registry.AuditID = *req.AuditID
|
||||
}
|
||||
if req.DueDate != nil {
|
||||
registry.DueDate = *req.DueDate
|
||||
}
|
||||
if req.Status != nil {
|
||||
registry.Status = *req.Status
|
||||
}
|
||||
if req.EffectivenessCheck != nil {
|
||||
registry.EffectivenessCheck = *req.EffectivenessCheck
|
||||
}
|
||||
|
||||
registry.UpdatedAt = time.Now()
|
||||
|
||||
if err := registry.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return registry, nil
|
||||
}
|
||||
|
||||
func (s NonconformityRegistryService) Delete(
|
||||
ctx context.Context,
|
||||
nonconformityRegistryID gid.GID,
|
||||
) error {
|
||||
registry := coredata.NonconformityRegistry{ID: nonconformityRegistryID}
|
||||
return s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := registry.Delete(ctx, conn, s.svc.scope)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete nonconformity registry: %w", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s NonconformityRegistryService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.NonconformityRegistryOrderField],
|
||||
) (*page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField], error) {
|
||||
var registries coredata.NonconformityRegistries
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(registries, cursor), nil
|
||||
}
|
||||
|
||||
func (s NonconformityRegistryService) CountForOrganizationID(
|
||||
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.NonconformityRegistries{}
|
||||
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
@@ -81,6 +81,7 @@ type (
|
||||
Reports *ReportService
|
||||
TrustCenters *TrustCenterService
|
||||
TrustCenterAccesses *TrustCenterAccessService
|
||||
NonconformityRegistries *NonconformityRegistryService
|
||||
}
|
||||
)
|
||||
|
||||
@@ -173,5 +174,6 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
svc: tenantService,
|
||||
usrmgr: s.usrmgr,
|
||||
}
|
||||
tenantService.NonconformityRegistries = &NonconformityRegistryService{svc: tenantService}
|
||||
return tenantService
|
||||
}
|
||||
|
||||
@@ -151,6 +151,22 @@ enum AuditState
|
||||
)
|
||||
}
|
||||
|
||||
enum NonconformityRegistryStatus
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryStatus") {
|
||||
OPEN
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryStatusOpen"
|
||||
)
|
||||
IN_PROGRESS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryStatusInProgress"
|
||||
)
|
||||
CLOSED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryStatusClosed"
|
||||
)
|
||||
}
|
||||
|
||||
# Order Field Enums
|
||||
enum UserOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.UserOrderField") {
|
||||
@@ -584,6 +600,30 @@ enum AuditOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum NonconformityRegistryOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderField") {
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderFieldCreatedAt"
|
||||
)
|
||||
REFERENCE_ID
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderFieldReferenceId"
|
||||
)
|
||||
DATE_IDENTIFIED
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderFieldDateIdentified"
|
||||
)
|
||||
DUE_DATE
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderFieldDueDate"
|
||||
)
|
||||
STATUS
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.NonconformityRegistryOrderFieldStatus"
|
||||
)
|
||||
}
|
||||
|
||||
enum TrustCenterAccessOrderField
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.TrustCenterAccessOrderField") {
|
||||
CREATED_AT
|
||||
@@ -673,6 +713,14 @@ input AuditOrder
|
||||
field: AuditOrderField!
|
||||
}
|
||||
|
||||
input NonconformityRegistryOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.NonconformityRegistryOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: NonconformityRegistryOrderField!
|
||||
}
|
||||
|
||||
input TrustCenterAccessOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterAccessOrderBy"
|
||||
@@ -888,6 +936,14 @@ type Organization implements Node {
|
||||
orderBy: AuditOrder
|
||||
): AuditConnection! @goField(forceResolver: true)
|
||||
|
||||
nonconformityRegistries(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: NonconformityRegistryOrder
|
||||
): NonconformityRegistryConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenter: TrustCenter @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
@@ -1280,6 +1336,23 @@ type Audit implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type NonconformityRegistry implements Node {
|
||||
id: ID!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
referenceId: String!
|
||||
description: String
|
||||
audit: Audit! @goField(forceResolver: true)
|
||||
dateIdentified: Datetime
|
||||
rootCause: String!
|
||||
correctiveAction: String
|
||||
owner: People! @goField(forceResolver: true)
|
||||
dueDate: Datetime
|
||||
status: NonconformityRegistryStatus!
|
||||
effectivenessCheck: String
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Report implements Node {
|
||||
id: ID!
|
||||
objectKey: String!
|
||||
@@ -1563,6 +1636,20 @@ type AuditEdge {
|
||||
node: Audit!
|
||||
}
|
||||
|
||||
type NonconformityRegistryConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.NonconformityRegistryConnection"
|
||||
) {
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
edges: [NonconformityRegistryEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type NonconformityRegistryEdge {
|
||||
cursor: CursorKey!
|
||||
node: NonconformityRegistry!
|
||||
}
|
||||
|
||||
# Root Types
|
||||
type Query {
|
||||
node(id: ID!): Node!
|
||||
@@ -1782,6 +1869,17 @@ type Mutation {
|
||||
deleteAudit(input: DeleteAuditInput!): DeleteAuditPayload!
|
||||
uploadAuditReport(input: UploadAuditReportInput!): UploadAuditReportPayload!
|
||||
deleteAuditReport(input: DeleteAuditReportInput!): DeleteAuditReportPayload!
|
||||
|
||||
# Nonconformity Registry mutations
|
||||
createNonconformityRegistry(
|
||||
input: CreateNonconformityRegistryInput!
|
||||
): CreateNonconformityRegistryPayload!
|
||||
updateNonconformityRegistry(
|
||||
input: UpdateNonconformityRegistryInput!
|
||||
): UpdateNonconformityRegistryPayload!
|
||||
deleteNonconformityRegistry(
|
||||
input: DeleteNonconformityRegistryInput!
|
||||
): DeleteNonconformityRegistryPayload!
|
||||
}
|
||||
|
||||
# Input Types
|
||||
@@ -2243,6 +2341,39 @@ input DeleteAuditReportInput {
|
||||
auditId: ID!
|
||||
}
|
||||
|
||||
# Nonconformity Registry input types
|
||||
input CreateNonconformityRegistryInput {
|
||||
organizationId: ID!
|
||||
referenceId: String!
|
||||
description: String
|
||||
auditId: ID!
|
||||
dateIdentified: Datetime
|
||||
rootCause: String!
|
||||
correctiveAction: String
|
||||
ownerId: ID!
|
||||
dueDate: Datetime
|
||||
status: NonconformityRegistryStatus!
|
||||
effectivenessCheck: String
|
||||
}
|
||||
|
||||
input UpdateNonconformityRegistryInput {
|
||||
id: ID!
|
||||
referenceId: String
|
||||
description: String
|
||||
dateIdentified: Datetime
|
||||
rootCause: String
|
||||
correctiveAction: String
|
||||
ownerId: ID
|
||||
auditId: ID
|
||||
dueDate: Datetime
|
||||
status: NonconformityRegistryStatus
|
||||
effectivenessCheck: String
|
||||
}
|
||||
|
||||
input DeleteNonconformityRegistryInput {
|
||||
nonconformityRegistryId: ID!
|
||||
}
|
||||
|
||||
# Payload Types
|
||||
type CreateOrganizationPayload {
|
||||
organizationEdge: OrganizationEdge!
|
||||
@@ -2911,3 +3042,16 @@ type UploadAuditReportPayload {
|
||||
type DeleteAuditReportPayload {
|
||||
audit: Audit!
|
||||
}
|
||||
|
||||
# Nonconformity Registry payload types
|
||||
type CreateNonconformityRegistryPayload {
|
||||
nonconformityRegistryEdge: NonconformityRegistryEdge!
|
||||
}
|
||||
|
||||
type UpdateNonconformityRegistryPayload {
|
||||
nonconformityRegistry: NonconformityRegistry!
|
||||
}
|
||||
|
||||
type DeleteNonconformityRegistryPayload {
|
||||
deletedNonconformityRegistryId: ID!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
76
pkg/server/api/console/v1/types/nonconformity_registry.go
Normal file
76
pkg/server/api/console/v1/types/nonconformity_registry.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// 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 (
|
||||
NonconformityRegistryOrderBy OrderBy[coredata.NonconformityRegistryOrderField]
|
||||
|
||||
NonconformityRegistryConnection struct {
|
||||
TotalCount int
|
||||
Edges []*NonconformityRegistryEdge
|
||||
PageInfo PageInfo
|
||||
|
||||
Resolver any
|
||||
ParentID gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func NewNonconformityRegistryConnection(
|
||||
p *page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField],
|
||||
parentType any,
|
||||
parentID gid.GID,
|
||||
) *NonconformityRegistryConnection {
|
||||
edges := make([]*NonconformityRegistryEdge, len(p.Data))
|
||||
for i, registry := range p.Data {
|
||||
edges[i] = NewNonconformityRegistryEdge(registry, p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &NonconformityRegistryConnection{
|
||||
Edges: edges,
|
||||
PageInfo: *NewPageInfo(p),
|
||||
|
||||
Resolver: parentType,
|
||||
ParentID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNonconformityRegistry(nr *coredata.NonconformityRegistry) *NonconformityRegistry {
|
||||
return &NonconformityRegistry{
|
||||
ID: nr.ID,
|
||||
ReferenceID: nr.ReferenceID,
|
||||
Description: nr.Description,
|
||||
DateIdentified: nr.DateIdentified,
|
||||
RootCause: nr.RootCause,
|
||||
CorrectiveAction: nr.CorrectiveAction,
|
||||
DueDate: nr.DueDate,
|
||||
Status: nr.Status,
|
||||
EffectivenessCheck: nr.EffectivenessCheck,
|
||||
CreatedAt: nr.CreatedAt,
|
||||
UpdatedAt: nr.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNonconformityRegistryEdge(nr *coredata.NonconformityRegistry, orderField coredata.NonconformityRegistryOrderField) *NonconformityRegistryEdge {
|
||||
return &NonconformityRegistryEdge{
|
||||
Node: NewNonconformityRegistry(nr),
|
||||
Cursor: nr.CursorKey(orderField),
|
||||
}
|
||||
}
|
||||
@@ -306,6 +306,24 @@ type CreateMeasurePayload struct {
|
||||
MeasureEdge *MeasureEdge `json:"measureEdge"`
|
||||
}
|
||||
|
||||
type CreateNonconformityRegistryInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
AuditID gid.GID `json:"auditId"`
|
||||
DateIdentified *time.Time `json:"dateIdentified,omitempty"`
|
||||
RootCause string `json:"rootCause"`
|
||||
CorrectiveAction *string `json:"correctiveAction,omitempty"`
|
||||
OwnerID gid.GID `json:"ownerId"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status coredata.NonconformityRegistryStatus `json:"status"`
|
||||
EffectivenessCheck *string `json:"effectivenessCheck,omitempty"`
|
||||
}
|
||||
|
||||
type CreateNonconformityRegistryPayload struct {
|
||||
NonconformityRegistryEdge *NonconformityRegistryEdge `json:"nonconformityRegistryEdge"`
|
||||
}
|
||||
|
||||
type CreateOrganizationInput struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
@@ -571,6 +589,14 @@ type DeleteMeasurePayload struct {
|
||||
DeletedMeasureID gid.GID `json:"deletedMeasureId"`
|
||||
}
|
||||
|
||||
type DeleteNonconformityRegistryInput struct {
|
||||
NonconformityRegistryID gid.GID `json:"nonconformityRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteNonconformityRegistryPayload struct {
|
||||
DeletedNonconformityRegistryID gid.GID `json:"deletedNonconformityRegistryId"`
|
||||
}
|
||||
|
||||
type DeleteOrganizationInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
}
|
||||
@@ -895,26 +921,52 @@ type MeasureFilter struct {
|
||||
type Mutation struct {
|
||||
}
|
||||
|
||||
type NonconformityRegistry struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Organization *Organization `json:"organization"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Audit *Audit `json:"audit"`
|
||||
DateIdentified *time.Time `json:"dateIdentified,omitempty"`
|
||||
RootCause string `json:"rootCause"`
|
||||
CorrectiveAction *string `json:"correctiveAction,omitempty"`
|
||||
Owner *People `json:"owner"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status coredata.NonconformityRegistryStatus `json:"status"`
|
||||
EffectivenessCheck *string `json:"effectivenessCheck,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (NonconformityRegistry) IsNode() {}
|
||||
func (this NonconformityRegistry) GetID() gid.GID { return this.ID }
|
||||
|
||||
type NonconformityRegistryEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *NonconformityRegistry `json:"node"`
|
||||
}
|
||||
|
||||
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"`
|
||||
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"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Organization) IsNode() {}
|
||||
@@ -1251,6 +1303,24 @@ type UpdateMeasurePayload struct {
|
||||
Measure *Measure `json:"measure"`
|
||||
}
|
||||
|
||||
type UpdateNonconformityRegistryInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
ReferenceID *string `json:"referenceId,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
DateIdentified *time.Time `json:"dateIdentified,omitempty"`
|
||||
RootCause *string `json:"rootCause,omitempty"`
|
||||
CorrectiveAction *string `json:"correctiveAction,omitempty"`
|
||||
OwnerID *gid.GID `json:"ownerId,omitempty"`
|
||||
AuditID *gid.GID `json:"auditId,omitempty"`
|
||||
DueDate *time.Time `json:"dueDate,omitempty"`
|
||||
Status *coredata.NonconformityRegistryStatus `json:"status,omitempty"`
|
||||
EffectivenessCheck *string `json:"effectivenessCheck,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateNonconformityRegistryPayload struct {
|
||||
NonconformityRegistry *NonconformityRegistry `json:"nonconformityRegistry"`
|
||||
}
|
||||
|
||||
type UpdateOrganizationInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
@@ -2713,6 +2713,143 @@ func (r *mutationResolver) DeleteAuditReport(ctx context.Context, input types.De
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateNonconformityRegistry is the resolver for the createNonconformityRegistry field.
|
||||
func (r *mutationResolver) CreateNonconformityRegistry(ctx context.Context, input types.CreateNonconformityRegistryInput) (*types.CreateNonconformityRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
req := probo.CreateNonconformityRegistryRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Description: input.Description,
|
||||
AuditID: input.AuditID,
|
||||
DateIdentified: input.DateIdentified,
|
||||
RootCause: input.RootCause,
|
||||
CorrectiveAction: input.CorrectiveAction,
|
||||
OwnerID: input.OwnerID,
|
||||
DueDate: input.DueDate,
|
||||
Status: &input.Status,
|
||||
EffectivenessCheck: input.EffectivenessCheck,
|
||||
}
|
||||
|
||||
registry, err := prb.NonconformityRegistries.Create(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return &types.CreateNonconformityRegistryPayload{
|
||||
NonconformityRegistryEdge: types.NewNonconformityRegistryEdge(registry, coredata.NonconformityRegistryOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateNonconformityRegistry is the resolver for the updateNonconformityRegistry field.
|
||||
func (r *mutationResolver) UpdateNonconformityRegistry(ctx context.Context, input types.UpdateNonconformityRegistryInput) (*types.UpdateNonconformityRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
req := probo.UpdateNonconformityRegistryRequest{
|
||||
ID: input.ID,
|
||||
ReferenceID: input.ReferenceID,
|
||||
Description: &input.Description,
|
||||
DateIdentified: &input.DateIdentified,
|
||||
RootCause: input.RootCause,
|
||||
CorrectiveAction: &input.CorrectiveAction,
|
||||
OwnerID: input.OwnerID,
|
||||
AuditID: input.AuditID,
|
||||
DueDate: &input.DueDate,
|
||||
Status: input.Status,
|
||||
EffectivenessCheck: &input.EffectivenessCheck,
|
||||
}
|
||||
|
||||
registry, err := prb.NonconformityRegistries.Update(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot update nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return &types.UpdateNonconformityRegistryPayload{
|
||||
NonconformityRegistry: types.NewNonconformityRegistry(registry),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteNonconformityRegistry is the resolver for the deleteNonconformityRegistry field.
|
||||
func (r *mutationResolver) DeleteNonconformityRegistry(ctx context.Context, input types.DeleteNonconformityRegistryInput) (*types.DeleteNonconformityRegistryPayload, error) {
|
||||
prb := r.ProboService(ctx, input.NonconformityRegistryID.TenantID())
|
||||
|
||||
err := prb.NonconformityRegistries.Delete(ctx, input.NonconformityRegistryID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot delete nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
return &types.DeleteNonconformityRegistryPayload{
|
||||
DeletedNonconformityRegistryID: input.NonconformityRegistryID,
|
||||
}, 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())
|
||||
|
||||
registry, err := prb.NonconformityRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
organization, err := prb.Organizations.Get(ctx, registry.OrganizationID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry organization: %w", err)
|
||||
}
|
||||
|
||||
return types.NewOrganization(organization), nil
|
||||
}
|
||||
|
||||
// Audit is the resolver for the audit field.
|
||||
func (r *nonconformityRegistryResolver) Audit(ctx context.Context, obj *types.NonconformityRegistry) (*types.Audit, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.NonconformityRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
audit, err := prb.Audits.Get(ctx, registry.AuditID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry audit: %w", err)
|
||||
}
|
||||
|
||||
return types.NewAudit(audit), nil
|
||||
}
|
||||
|
||||
// Owner is the resolver for the owner field.
|
||||
func (r *nonconformityRegistryResolver) Owner(ctx context.Context, obj *types.NonconformityRegistry) (*types.People, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
registry, err := prb.NonconformityRegistries.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry: %w", err)
|
||||
}
|
||||
|
||||
people, err := prb.Peoples.Get(ctx, registry.OwnerID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get nonconformity registry owner: %w", err)
|
||||
}
|
||||
|
||||
return types.NewPeople(people), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *nonconformityRegistryConnectionResolver) TotalCount(ctx context.Context, obj *types.NonconformityRegistryConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
switch obj.Resolver.(type) {
|
||||
case *organizationResolver:
|
||||
count, err := prb.NonconformityRegistries.CountForOrganizationID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count nonconformity registries: %w", err)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("unsupported resolver: %T", obj.Resolver)
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organization) (*string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3068,6 +3205,31 @@ func (r *organizationResolver) Audits(ctx context.Context, obj *types.Organizati
|
||||
return types.NewAuditConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// NonconformityRegistries is the resolver for the nonconformityRegistries field.
|
||||
func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) (*types.NonconformityRegistryConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.NonconformityRegistryOrderField]{
|
||||
Field: coredata.NonconformityRegistryOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.NonconformityRegistryOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
page, err := prb.NonconformityRegistries.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list organization nonconformity registries: %w", err)
|
||||
}
|
||||
|
||||
return types.NewNonconformityRegistryConnection(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())
|
||||
@@ -3211,6 +3373,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
||||
panic(fmt.Errorf("cannot get audit: %w", err))
|
||||
}
|
||||
return types.NewAudit(audit), nil
|
||||
case coredata.NonconformityRegistryEntityType:
|
||||
nonconformityRegistry, err := prb.NonconformityRegistries.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get nonconformity registry: %w", err))
|
||||
}
|
||||
return types.NewNonconformityRegistry(nonconformityRegistry), nil
|
||||
case coredata.ReportEntityType:
|
||||
report, err := prb.Reports.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -3970,6 +4138,16 @@ func (r *Resolver) MeasureConnection() schema.MeasureConnectionResolver {
|
||||
// Mutation returns schema.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
// NonconformityRegistry returns schema.NonconformityRegistryResolver implementation.
|
||||
func (r *Resolver) NonconformityRegistry() schema.NonconformityRegistryResolver {
|
||||
return &nonconformityRegistryResolver{r}
|
||||
}
|
||||
|
||||
// NonconformityRegistryConnection returns schema.NonconformityRegistryConnectionResolver implementation.
|
||||
func (r *Resolver) NonconformityRegistryConnection() schema.NonconformityRegistryConnectionResolver {
|
||||
return &nonconformityRegistryConnectionResolver{r}
|
||||
}
|
||||
|
||||
// Organization returns schema.OrganizationResolver implementation.
|
||||
func (r *Resolver) Organization() schema.OrganizationResolver { return &organizationResolver{r} }
|
||||
|
||||
@@ -4055,6 +4233,8 @@ type frameworkConnectionResolver struct{ *Resolver }
|
||||
type measureResolver struct{ *Resolver }
|
||||
type measureConnectionResolver struct{ *Resolver }
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type nonconformityRegistryResolver struct{ *Resolver }
|
||||
type nonconformityRegistryConnectionResolver struct{ *Resolver }
|
||||
type organizationResolver struct{ *Resolver }
|
||||
type peopleConnectionResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user