Add dpa on vendors
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -42,4 +42,5 @@ const (
|
||||
VendorBusinessAssociateAgreementEntityType
|
||||
FileEntityType
|
||||
VendorContactEntityType
|
||||
VendorDataPrivacyAgreementEntityType
|
||||
)
|
||||
|
||||
29
pkg/coredata/migrations/20250813T141529Z.sql
Normal file
29
pkg/coredata/migrations/20250813T141529Z.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
CREATE TABLE vendor_data_privacy_agreements (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT NOT NULL,
|
||||
tenant_id TEXT NOT NULL,
|
||||
vendor_id TEXT NOT NULL,
|
||||
valid_from DATE,
|
||||
valid_until DATE,
|
||||
file_id TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
|
||||
CONSTRAINT vendor_data_privacy_agreements_organization_vendor_unique
|
||||
UNIQUE (organization_id, vendor_id),
|
||||
|
||||
CONSTRAINT vendor_data_privacy_agreements_file_id_unique
|
||||
UNIQUE (file_id),
|
||||
|
||||
CONSTRAINT vendor_data_privacy_agreements_organization_id_fkey
|
||||
FOREIGN KEY (organization_id)
|
||||
REFERENCES organizations(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT vendor_data_privacy_agreements_file_id_fkey
|
||||
FOREIGN KEY (file_id)
|
||||
REFERENCES files(id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
280
pkg/coredata/vendor_data_privacy_agreement.go
Normal file
280
pkg/coredata/vendor_data_privacy_agreement.go
Normal file
@@ -0,0 +1,280 @@
|
||||
// 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 (
|
||||
VendorDataPrivacyAgreement struct {
|
||||
ID gid.GID `db:"id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
VendorID gid.GID `db:"vendor_id"`
|
||||
ValidFrom *time.Time `db:"valid_from"`
|
||||
ValidUntil *time.Time `db:"valid_until"`
|
||||
FileID gid.GID `db:"file_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
VendorDataPrivacyAgreements []*VendorDataPrivacyAgreement
|
||||
)
|
||||
|
||||
func (v VendorDataPrivacyAgreement) CursorKey(orderBy VendorDataPrivacyAgreementOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case VendorDataPrivacyAgreementOrderFieldValidFrom:
|
||||
return page.NewCursorKey(v.ID, v.ValidFrom)
|
||||
case VendorDataPrivacyAgreementOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(v.ID, v.CreatedAt)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) LoadByVendorID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
vendorID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
vendor_id,
|
||||
valid_from,
|
||||
valid_until,
|
||||
file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
vendor_data_privacy_agreements
|
||||
WHERE
|
||||
%s
|
||||
AND vendor_id = @vendor_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"vendor_id": vendorID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
vendorDataPrivacyAgreement, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[VendorDataPrivacyAgreement])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
*vdpa = vendorDataPrivacyAgreement
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
vendorDataPrivacyAgreementID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
vendor_id,
|
||||
valid_from,
|
||||
valid_until,
|
||||
file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
vendor_data_privacy_agreements
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"id": vendorDataPrivacyAgreementID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
vendorDataPrivacyAgreement, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[VendorDataPrivacyAgreement])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
*vdpa = vendorDataPrivacyAgreement
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE
|
||||
vendor_data_privacy_agreements
|
||||
SET
|
||||
valid_from = @valid_from,
|
||||
valid_until = @valid_until,
|
||||
file_id = @file_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": vdpa.ID,
|
||||
"valid_from": vdpa.ValidFrom,
|
||||
"valid_until": vdpa.ValidUntil,
|
||||
"file_id": vdpa.FileID,
|
||||
"updated_at": vdpa.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) Upsert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
vendor_data_privacy_agreements (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
vendor_id,
|
||||
valid_from,
|
||||
valid_until,
|
||||
file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
@id,
|
||||
@tenant_id,
|
||||
@organization_id,
|
||||
@vendor_id,
|
||||
@valid_from,
|
||||
@valid_until,
|
||||
@file_id,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
ON CONFLICT (organization_id, vendor_id) DO UPDATE SET
|
||||
id = EXCLUDED.id,
|
||||
valid_from = EXCLUDED.valid_from,
|
||||
valid_until = EXCLUDED.valid_until,
|
||||
file_id = EXCLUDED.file_id,
|
||||
updated_at = EXCLUDED.updated_at
|
||||
`
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": vdpa.ID,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"vendor_id": vdpa.VendorID,
|
||||
"organization_id": vdpa.OrganizationID,
|
||||
"valid_from": vdpa.ValidFrom,
|
||||
"valid_until": vdpa.ValidUntil,
|
||||
"file_id": vdpa.FileID,
|
||||
"created_at": vdpa.CreatedAt,
|
||||
"updated_at": vdpa.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE
|
||||
FROM
|
||||
vendor_data_privacy_agreements
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": vdpa.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (vdpa *VendorDataPrivacyAgreement) DeleteByVendorID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
vendorID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
DELETE
|
||||
FROM
|
||||
vendor_data_privacy_agreements
|
||||
WHERE
|
||||
%s
|
||||
AND vendor_id = @vendor_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"vendor_id": vendorID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
return err
|
||||
}
|
||||
41
pkg/coredata/vendor_data_privacy_agreement_order_field.go
Normal file
41
pkg/coredata/vendor_data_privacy_agreement_order_field.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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
|
||||
|
||||
type (
|
||||
VendorDataPrivacyAgreementOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
VendorDataPrivacyAgreementOrderFieldValidFrom VendorDataPrivacyAgreementOrderField = "VALID_FROM"
|
||||
VendorDataPrivacyAgreementOrderFieldCreatedAt VendorDataPrivacyAgreementOrderField = "CREATED_AT"
|
||||
)
|
||||
|
||||
func (p VendorDataPrivacyAgreementOrderField) Column() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p VendorDataPrivacyAgreementOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p VendorDataPrivacyAgreementOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *VendorDataPrivacyAgreementOrderField) UnmarshalText(text []byte) error {
|
||||
*p = VendorDataPrivacyAgreementOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -73,6 +73,7 @@ type (
|
||||
VendorComplianceReports *VendorComplianceReportService
|
||||
VendorBusinessAssociateAgreements *VendorBusinessAssociateAgreementService
|
||||
VendorContacts *VendorContactService
|
||||
VendorDataPrivacyAgreements *VendorDataPrivacyAgreementService
|
||||
Connectors *ConnectorService
|
||||
Assets *AssetService
|
||||
Data *DatumService
|
||||
@@ -161,6 +162,7 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
tenantService.VendorComplianceReports = &VendorComplianceReportService{svc: tenantService}
|
||||
tenantService.VendorBusinessAssociateAgreements = &VendorBusinessAssociateAgreementService{svc: tenantService}
|
||||
tenantService.VendorContacts = &VendorContactService{svc: tenantService}
|
||||
tenantService.VendorDataPrivacyAgreements = &VendorDataPrivacyAgreementService{svc: tenantService}
|
||||
tenantService.Connectors = &ConnectorService{svc: tenantService}
|
||||
tenantService.Assets = &AssetService{svc: tenantService}
|
||||
tenantService.Data = &DatumService{svc: tenantService}
|
||||
|
||||
@@ -261,10 +261,6 @@ func (s VendorBusinessAssociateAgreementService) Update(
|
||||
return fmt.Errorf("cannot load existing vendor business associate agreement: %w", err)
|
||||
}
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if req.ValidFrom != nil {
|
||||
existingAgreement.ValidFrom = *req.ValidFrom
|
||||
@@ -275,14 +271,14 @@ func (s VendorBusinessAssociateAgreementService) Update(
|
||||
|
||||
existingAgreement.UpdatedAt = now
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
if err := existingAgreement.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update vendor business associate agreement: %w", err)
|
||||
}
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
346
pkg/probo/vendor_data_privacy_agreement_service.go
Normal file
346
pkg/probo/vendor_data_privacy_agreement_service.go
Normal file
@@ -0,0 +1,346 @@
|
||||
// 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"
|
||||
"io"
|
||||
"mime"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"go.gearno.de/crypto/uuid"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
VendorDataPrivacyAgreementService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
VendorDataPrivacyAgreementCreateRequest struct {
|
||||
File io.Reader
|
||||
ValidFrom *time.Time
|
||||
ValidUntil *time.Time
|
||||
FileName string
|
||||
}
|
||||
|
||||
VendorDataPrivacyAgreementUpdateRequest struct {
|
||||
ValidFrom **time.Time
|
||||
ValidUntil **time.Time
|
||||
}
|
||||
)
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) GetByVendorID(
|
||||
ctx context.Context,
|
||||
vendorID gid.GID,
|
||||
) (*coredata.VendorDataPrivacyAgreement, *coredata.File, error) {
|
||||
var vendorDataPrivacyAgreement *coredata.VendorDataPrivacyAgreement
|
||||
var file *coredata.File
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendorDataPrivacyAgreement = &coredata.VendorDataPrivacyAgreement{}
|
||||
if err := vendorDataPrivacyAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
file = &coredata.File{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return vendorDataPrivacyAgreement, file, nil
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) Upload(
|
||||
ctx context.Context,
|
||||
vendorID gid.GID,
|
||||
req *VendorDataPrivacyAgreementCreateRequest,
|
||||
) (*coredata.VendorDataPrivacyAgreement, *coredata.File, error) {
|
||||
objectKey, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot generate object key: %w", err)
|
||||
}
|
||||
|
||||
mimeType := mime.TypeByExtension(filepath.Ext(req.FileName))
|
||||
|
||||
_, err = s.svc.s3.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: &s.svc.bucket,
|
||||
Key: aws.String(objectKey.String()),
|
||||
Body: req.File,
|
||||
ContentType: &mimeType,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot upload file to S3: %w", err)
|
||||
}
|
||||
|
||||
headOutput, err := s.svc.s3.HeadObject(ctx, &s3.HeadObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(objectKey.String()),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot get object metadata: %w", err)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
fileID := gid.New(s.svc.scope.GetTenantID(), coredata.FileEntityType)
|
||||
vendorDataPrivacyAgreementID := gid.New(s.svc.scope.GetTenantID(), coredata.VendorDataPrivacyAgreementEntityType)
|
||||
|
||||
var vendorDataPrivacyAgreement *coredata.VendorDataPrivacyAgreement
|
||||
var file *coredata.File
|
||||
|
||||
err = s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendor := &coredata.Vendor{}
|
||||
if err := vendor.LoadByID(ctx, conn, s.svc.scope, vendorID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor: %w", err)
|
||||
}
|
||||
|
||||
file = &coredata.File{
|
||||
ID: fileID,
|
||||
BucketName: s.svc.bucket,
|
||||
MimeType: mimeType,
|
||||
FileName: req.FileName,
|
||||
FileKey: objectKey.String(),
|
||||
FileSize: int(*headOutput.ContentLength),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
vendorDataPrivacyAgreement = &coredata.VendorDataPrivacyAgreement{
|
||||
ID: vendorDataPrivacyAgreementID,
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
OrganizationID: vendor.OrganizationID,
|
||||
VendorID: vendorID,
|
||||
ValidFrom: req.ValidFrom,
|
||||
ValidUntil: req.ValidUntil,
|
||||
FileID: fileID,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := file.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert file: %w", err)
|
||||
}
|
||||
|
||||
if err := vendorDataPrivacyAgreement.Upsert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return vendorDataPrivacyAgreement, file, nil
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) Get(
|
||||
ctx context.Context,
|
||||
vendorDataPrivacyAgreementID gid.GID,
|
||||
) (*coredata.VendorDataPrivacyAgreement, *coredata.File, error) {
|
||||
var vendorDataPrivacyAgreement *coredata.VendorDataPrivacyAgreement
|
||||
var file *coredata.File
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendorDataPrivacyAgreement = &coredata.VendorDataPrivacyAgreement{}
|
||||
if err := vendorDataPrivacyAgreement.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreementID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
file = &coredata.File{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return vendorDataPrivacyAgreement, file, nil
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) GenerateFileURL(
|
||||
ctx context.Context,
|
||||
vendorDataPrivacyAgreementID gid.GID,
|
||||
expiresIn time.Duration,
|
||||
) (string, error) {
|
||||
var file *coredata.File
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendorDataPrivacyAgreement := &coredata.VendorDataPrivacyAgreement{}
|
||||
if err := vendorDataPrivacyAgreement.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreementID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
file = &coredata.File{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
presignClient := s3.NewPresignClient(s.svc.s3)
|
||||
|
||||
encodedFilename := url.QueryEscape(file.FileName)
|
||||
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
||||
encodedFilename, encodedFilename)
|
||||
|
||||
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(file.FileKey),
|
||||
ResponseCacheControl: aws.String("max-age=3600, public"),
|
||||
ResponseContentDisposition: aws.String(contentDisposition),
|
||||
}, func(opts *s3.PresignOptions) {
|
||||
opts.Expires = expiresIn
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
|
||||
}
|
||||
|
||||
return presignedReq.URL, nil
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) Update(
|
||||
ctx context.Context,
|
||||
vendorID gid.GID,
|
||||
req *VendorDataPrivacyAgreementUpdateRequest,
|
||||
) (*coredata.VendorDataPrivacyAgreement, *coredata.File, error) {
|
||||
existingAgreement := &coredata.VendorDataPrivacyAgreement{}
|
||||
file := &coredata.File{}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := existingAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
|
||||
return fmt.Errorf("cannot load existing vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if req.ValidFrom != nil {
|
||||
existingAgreement.ValidFrom = *req.ValidFrom
|
||||
}
|
||||
if req.ValidUntil != nil {
|
||||
existingAgreement.ValidUntil = *req.ValidUntil
|
||||
}
|
||||
|
||||
existingAgreement.UpdatedAt = now
|
||||
|
||||
if err := existingAgreement.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return existingAgreement, file, nil
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) Delete(
|
||||
ctx context.Context,
|
||||
vendorDataPrivacyAgreementID gid.GID,
|
||||
) error {
|
||||
return s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendorDataPrivacyAgreement := &coredata.VendorDataPrivacyAgreement{}
|
||||
if err := vendorDataPrivacyAgreement.LoadByID(ctx, conn, s.svc.scope, vendorDataPrivacyAgreementID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
file := &coredata.File{ID: vendorDataPrivacyAgreement.FileID}
|
||||
|
||||
if err := vendorDataPrivacyAgreement.Delete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
if err := file.SoftDelete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot soft delete file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s VendorDataPrivacyAgreementService) DeleteByVendorID(
|
||||
ctx context.Context,
|
||||
vendorID gid.GID,
|
||||
) error {
|
||||
return s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
vendorDataPrivacyAgreement := &coredata.VendorDataPrivacyAgreement{}
|
||||
if err := vendorDataPrivacyAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
|
||||
return fmt.Errorf("cannot load vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
file := &coredata.File{ID: vendorDataPrivacyAgreement.FileID}
|
||||
|
||||
if err := vendorDataPrivacyAgreement.DeleteByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
|
||||
return fmt.Errorf("cannot delete vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
if err := file.SoftDelete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot soft delete file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -942,6 +942,7 @@ type Vendor implements Node {
|
||||
): VendorComplianceReportConnection! @goField(forceResolver: true)
|
||||
|
||||
businessAssociateAgreement: VendorBusinessAssociateAgreement @goField(forceResolver: true)
|
||||
dataPrivacyAgreement: VendorDataPrivacyAgreement @goField(forceResolver: true)
|
||||
|
||||
contacts(
|
||||
first: Int
|
||||
@@ -1015,6 +1016,18 @@ type VendorContact implements Node {
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type VendorDataPrivacyAgreement implements Node {
|
||||
id: ID!
|
||||
vendor: Vendor! @goField(forceResolver: true)
|
||||
validFrom: Datetime
|
||||
validUntil: Datetime
|
||||
fileName: String!
|
||||
fileUrl: String! @goField(forceResolver: true)
|
||||
fileSize: Int!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type Framework implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
@@ -1678,6 +1691,17 @@ type Mutation {
|
||||
input: DeleteVendorBusinessAssociateAgreementInput!
|
||||
): DeleteVendorBusinessAssociateAgreementPayload!
|
||||
|
||||
# Vendor Data Privacy Agreement mutations
|
||||
uploadVendorDataPrivacyAgreement(
|
||||
input: UploadVendorDataPrivacyAgreementInput!
|
||||
): UploadVendorDataPrivacyAgreementPayload!
|
||||
updateVendorDataPrivacyAgreement(
|
||||
input: UpdateVendorDataPrivacyAgreementInput!
|
||||
): UpdateVendorDataPrivacyAgreementPayload!
|
||||
deleteVendorDataPrivacyAgreement(
|
||||
input: DeleteVendorDataPrivacyAgreementInput!
|
||||
): DeleteVendorDataPrivacyAgreementPayload!
|
||||
|
||||
# Document mutations
|
||||
createDocument(input: CreateDocumentInput!): CreateDocumentPayload!
|
||||
updateDocument(input: UpdateDocumentInput!): UpdateDocumentPayload!
|
||||
@@ -2071,6 +2095,24 @@ input DeleteVendorBusinessAssociateAgreementInput {
|
||||
vendorId: ID!
|
||||
}
|
||||
|
||||
input UploadVendorDataPrivacyAgreementInput {
|
||||
vendorId: ID!
|
||||
validFrom: Datetime
|
||||
validUntil: Datetime
|
||||
fileName: String!
|
||||
file: Upload!
|
||||
}
|
||||
|
||||
input UpdateVendorDataPrivacyAgreementInput {
|
||||
vendorId: ID!
|
||||
validFrom: Datetime
|
||||
validUntil: Datetime
|
||||
}
|
||||
|
||||
input DeleteVendorDataPrivacyAgreementInput {
|
||||
vendorId: ID!
|
||||
}
|
||||
|
||||
input CreateDocumentInput {
|
||||
organizationId: ID!
|
||||
title: String!
|
||||
@@ -2375,6 +2417,18 @@ type DeleteVendorBusinessAssociateAgreementPayload {
|
||||
deletedVendorId: ID!
|
||||
}
|
||||
|
||||
type UploadVendorDataPrivacyAgreementPayload {
|
||||
vendorDataPrivacyAgreement: VendorDataPrivacyAgreement!
|
||||
}
|
||||
|
||||
type UpdateVendorDataPrivacyAgreementPayload {
|
||||
vendorDataPrivacyAgreement: VendorDataPrivacyAgreement!
|
||||
}
|
||||
|
||||
type DeleteVendorDataPrivacyAgreementPayload {
|
||||
deletedVendorId: ID!
|
||||
}
|
||||
|
||||
type CreateDocumentPayload {
|
||||
documentEdge: DocumentEdge!
|
||||
documentVersionEdge: DocumentVersionEdge!
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -631,6 +631,14 @@ type DeleteVendorContactPayload struct {
|
||||
DeletedVendorContactID gid.GID `json:"deletedVendorContactId"`
|
||||
}
|
||||
|
||||
type DeleteVendorDataPrivacyAgreementInput struct {
|
||||
VendorID gid.GID `json:"vendorId"`
|
||||
}
|
||||
|
||||
type DeleteVendorDataPrivacyAgreementPayload struct {
|
||||
DeletedVendorID gid.GID `json:"deletedVendorId"`
|
||||
}
|
||||
|
||||
type DeleteVendorInput struct {
|
||||
VendorID gid.GID `json:"vendorId"`
|
||||
}
|
||||
@@ -1306,6 +1314,16 @@ type UpdateVendorContactPayload struct {
|
||||
VendorContact *VendorContact `json:"vendorContact"`
|
||||
}
|
||||
|
||||
type UpdateVendorDataPrivacyAgreementInput struct {
|
||||
VendorID gid.GID `json:"vendorId"`
|
||||
ValidFrom *time.Time `json:"validFrom,omitempty"`
|
||||
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateVendorDataPrivacyAgreementPayload struct {
|
||||
VendorDataPrivacyAgreement *VendorDataPrivacyAgreement `json:"vendorDataPrivacyAgreement"`
|
||||
}
|
||||
|
||||
type UpdateVendorInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
@@ -1384,6 +1402,18 @@ type UploadVendorComplianceReportPayload struct {
|
||||
VendorComplianceReportEdge *VendorComplianceReportEdge `json:"vendorComplianceReportEdge"`
|
||||
}
|
||||
|
||||
type UploadVendorDataPrivacyAgreementInput struct {
|
||||
VendorID gid.GID `json:"vendorId"`
|
||||
ValidFrom *time.Time `json:"validFrom,omitempty"`
|
||||
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||
FileName string `json:"fileName"`
|
||||
File graphql.Upload `json:"file"`
|
||||
}
|
||||
|
||||
type UploadVendorDataPrivacyAgreementPayload struct {
|
||||
VendorDataPrivacyAgreement *VendorDataPrivacyAgreement `json:"vendorDataPrivacyAgreement"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID gid.GID `json:"id"`
|
||||
FullName string `json:"fullName"`
|
||||
@@ -1414,6 +1444,7 @@ type Vendor struct {
|
||||
Organization *Organization `json:"organization"`
|
||||
ComplianceReports *VendorComplianceReportConnection `json:"complianceReports"`
|
||||
BusinessAssociateAgreement *VendorBusinessAssociateAgreement `json:"businessAssociateAgreement,omitempty"`
|
||||
DataPrivacyAgreement *VendorDataPrivacyAgreement `json:"dataPrivacyAgreement,omitempty"`
|
||||
Contacts *VendorContactConnection `json:"contacts"`
|
||||
RiskAssessments *VendorRiskAssessmentConnection `json:"riskAssessments"`
|
||||
BusinessOwner *People `json:"businessOwner,omitempty"`
|
||||
@@ -1503,6 +1534,21 @@ type VendorContactEdge struct {
|
||||
Node *VendorContact `json:"node"`
|
||||
}
|
||||
|
||||
type VendorDataPrivacyAgreement struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Vendor *Vendor `json:"vendor"`
|
||||
ValidFrom *time.Time `json:"validFrom,omitempty"`
|
||||
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||
FileName string `json:"fileName"`
|
||||
FileURL string `json:"fileUrl"`
|
||||
FileSize int `json:"fileSize"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (VendorDataPrivacyAgreement) IsNode() {}
|
||||
func (this VendorDataPrivacyAgreement) GetID() gid.GID { return this.ID }
|
||||
|
||||
type VendorEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *Vendor `json:"node"`
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
func NewVendorDataPrivacyAgreement(v *coredata.VendorDataPrivacyAgreement, file *coredata.File) *VendorDataPrivacyAgreement {
|
||||
return &VendorDataPrivacyAgreement{
|
||||
ID: v.ID,
|
||||
ValidFrom: v.ValidFrom,
|
||||
ValidUntil: v.ValidUntil,
|
||||
FileName: file.FileName,
|
||||
FileSize: file.FileSize,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -2022,6 +2022,64 @@ func (r *mutationResolver) DeleteVendorBusinessAssociateAgreement(ctx context.Co
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UploadVendorDataPrivacyAgreement is the resolver for the uploadVendorDataPrivacyAgreement field.
|
||||
func (r *mutationResolver) UploadVendorDataPrivacyAgreement(ctx context.Context, input types.UploadVendorDataPrivacyAgreementInput) (*types.UploadVendorDataPrivacyAgreementPayload, error) {
|
||||
prb := r.ProboService(ctx, input.VendorID.TenantID())
|
||||
|
||||
vendorDataPrivacyAgreement, file, err := prb.VendorDataPrivacyAgreements.Upload(
|
||||
ctx,
|
||||
input.VendorID,
|
||||
&probo.VendorDataPrivacyAgreementCreateRequest{
|
||||
File: input.File.File,
|
||||
ValidFrom: input.ValidFrom,
|
||||
ValidUntil: input.ValidUntil,
|
||||
FileName: input.FileName,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to upload vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return &types.UploadVendorDataPrivacyAgreementPayload{
|
||||
VendorDataPrivacyAgreement: types.NewVendorDataPrivacyAgreement(vendorDataPrivacyAgreement, file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateVendorDataPrivacyAgreement is the resolver for the updateVendorDataPrivacyAgreement field.
|
||||
func (r *mutationResolver) UpdateVendorDataPrivacyAgreement(ctx context.Context, input types.UpdateVendorDataPrivacyAgreementInput) (*types.UpdateVendorDataPrivacyAgreementPayload, error) {
|
||||
prb := r.ProboService(ctx, input.VendorID.TenantID())
|
||||
|
||||
vendorDataPrivacyAgreement, file, err := prb.VendorDataPrivacyAgreements.Update(
|
||||
ctx,
|
||||
input.VendorID,
|
||||
&probo.VendorDataPrivacyAgreementUpdateRequest{
|
||||
ValidFrom: &input.ValidFrom,
|
||||
ValidUntil: &input.ValidUntil,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return &types.UpdateVendorDataPrivacyAgreementPayload{
|
||||
VendorDataPrivacyAgreement: types.NewVendorDataPrivacyAgreement(vendorDataPrivacyAgreement, file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteVendorDataPrivacyAgreement is the resolver for the deleteVendorDataPrivacyAgreement field.
|
||||
func (r *mutationResolver) DeleteVendorDataPrivacyAgreement(ctx context.Context, input types.DeleteVendorDataPrivacyAgreementInput) (*types.DeleteVendorDataPrivacyAgreementPayload, error) {
|
||||
prb := r.ProboService(ctx, input.VendorID.TenantID())
|
||||
|
||||
err := prb.VendorDataPrivacyAgreements.DeleteByVendorID(ctx, input.VendorID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to delete vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return &types.DeleteVendorDataPrivacyAgreementPayload{
|
||||
DeletedVendorID: input.VendorID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateDocument is the resolver for the createDocument field.
|
||||
func (r *mutationResolver) CreateDocument(ctx context.Context, input types.CreateDocumentInput) (*types.CreateDocumentPayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
@@ -3469,6 +3527,22 @@ func (r *vendorResolver) BusinessAssociateAgreement(ctx context.Context, obj *ty
|
||||
return types.NewVendorBusinessAssociateAgreement(vendorBusinessAssociateAgreement, file), nil
|
||||
}
|
||||
|
||||
// DataPrivacyAgreement is the resolver for the dataPrivacyAgreement field.
|
||||
func (r *vendorResolver) DataPrivacyAgreement(ctx context.Context, obj *types.Vendor) (*types.VendorDataPrivacyAgreement, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
vendorDataPrivacyAgreement, file, err := prb.VendorDataPrivacyAgreements.GetByVendorID(ctx, obj.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("failed to get vendor data privacy agreement: %w", err)
|
||||
}
|
||||
|
||||
return types.NewVendorDataPrivacyAgreement(vendorDataPrivacyAgreement, file), nil
|
||||
}
|
||||
|
||||
// Contacts is the resolver for the contacts field.
|
||||
func (r *vendorResolver) Contacts(ctx context.Context, obj *types.Vendor, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorContactOrderBy) (*types.VendorContactConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3654,6 +3728,30 @@ func (r *vendorContactResolver) Vendor(ctx context.Context, obj *types.VendorCon
|
||||
return types.NewVendor(vendor), nil
|
||||
}
|
||||
|
||||
// Vendor is the resolver for the vendor field.
|
||||
func (r *vendorDataPrivacyAgreementResolver) Vendor(ctx context.Context, obj *types.VendorDataPrivacyAgreement) (*types.Vendor, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
vendor, err := prb.Vendors.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get vendor: %w", err)
|
||||
}
|
||||
|
||||
return types.NewVendor(vendor), nil
|
||||
}
|
||||
|
||||
// FileURL is the resolver for the fileUrl field.
|
||||
func (r *vendorDataPrivacyAgreementResolver) FileURL(ctx context.Context, obj *types.VendorDataPrivacyAgreement) (string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
fileURL, err := prb.VendorDataPrivacyAgreements.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to generate file URL: %w", err)
|
||||
}
|
||||
|
||||
return fileURL, nil
|
||||
}
|
||||
|
||||
// Vendor is the resolver for the vendor field.
|
||||
func (r *vendorRiskAssessmentResolver) Vendor(ctx context.Context, obj *types.VendorRiskAssessment) (*types.Vendor, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -3838,6 +3936,11 @@ func (r *Resolver) VendorConnection() schema.VendorConnectionResolver {
|
||||
// VendorContact returns schema.VendorContactResolver implementation.
|
||||
func (r *Resolver) VendorContact() schema.VendorContactResolver { return &vendorContactResolver{r} }
|
||||
|
||||
// VendorDataPrivacyAgreement returns schema.VendorDataPrivacyAgreementResolver implementation.
|
||||
func (r *Resolver) VendorDataPrivacyAgreement() schema.VendorDataPrivacyAgreementResolver {
|
||||
return &vendorDataPrivacyAgreementResolver{r}
|
||||
}
|
||||
|
||||
// VendorRiskAssessment returns schema.VendorRiskAssessmentResolver implementation.
|
||||
func (r *Resolver) VendorRiskAssessment() schema.VendorRiskAssessmentResolver {
|
||||
return &vendorRiskAssessmentResolver{r}
|
||||
@@ -3880,5 +3983,6 @@ type vendorBusinessAssociateAgreementResolver struct{ *Resolver }
|
||||
type vendorComplianceReportResolver struct{ *Resolver }
|
||||
type vendorConnectionResolver struct{ *Resolver }
|
||||
type vendorContactResolver struct{ *Resolver }
|
||||
type vendorDataPrivacyAgreementResolver struct{ *Resolver }
|
||||
type vendorRiskAssessmentResolver struct{ *Resolver }
|
||||
type viewerResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user