Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions core/kyc/mocks/repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions core/kyc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Repository interface {
GetByOrgID(context.Context, string) (KYC, error)
List(context.Context) ([]KYC, error)
Upsert(context.Context, KYC) (KYC, error)
Delete(context.Context, string) error
}

type Service struct {
Expand All @@ -29,3 +30,7 @@ func (s Service) SetKyc(ctx context.Context, kyc KYC) (KYC, error) {
func (s Service) ListKycs(ctx context.Context) ([]KYC, error) {
return s.repository.List(ctx)
}

func (s Service) DeleteKyc(ctx context.Context, orgID string) error {
return s.repository.Delete(ctx, orgID)
}
23 changes: 23 additions & 0 deletions internal/store/postgres/kyc_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ func (r OrgKycRepository) Upsert(ctx context.Context, input kyc.KYC) (kyc.KYC, e
return result.KYC.transformToKyc()
}

// Delete removes the kyc record of an org. Deleting is idempotent: an org
// without a kyc record returns success.
func (r OrgKycRepository) Delete(ctx context.Context, orgID string) error {
query, params, err := dialect.Delete(TABLE_ORGANIZATIONS_KYC).Where(goqu.Ex{
"org_id": orgID,
}).ToSQL()
if err != nil {
return fmt.Errorf("%w: %w", errQuery, err)
}

if err = r.dbc.WithTimeout(ctx, TABLE_ORGANIZATIONS_KYC, "Delete", func(ctx context.Context) error {
_, err := r.dbc.ExecContext(ctx, query, params...)
return err
}); err != nil {
err = checkPostgresError(err)
if errors.Is(err, ErrInvalidTextRepresentation) {
return kyc.ErrInvalidUUID
}
return err
}
return nil
}

func (r OrgKycRepository) List(ctx context.Context) ([]kyc.KYC, error) {
// Define table references
orgs := goqu.T(TABLE_ORGANIZATIONS)
Expand Down
Loading