Set contact ID when creating a report
Some checks failed
/ golint (push) Failing after 3m51s

For now we just set it to the empty contact, which is a bit weird, and
wrong until we fix the update logic.
This commit is contained in:
Eli Ribble 2026-05-19 00:33:14 +00:00
parent 2d4a0347d6
commit 3cafca6cbd
No known key found for this signature in database
3 changed files with 56 additions and 0 deletions

View file

@ -2,6 +2,8 @@ package comms
import (
"context"
"errors"
"fmt"
//"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/nidus-sync/db"
@ -18,6 +20,39 @@ func ContactInsert(ctx context.Context, txn db.Ex, m model.Contact) (model.Conta
return db.ExecuteOneTx[model.Contact](ctx, txn, statement)
}
func ContactEmptyForOrganization(ctx context.Context, txn db.Ex, org_id int64) (*model.Contact, error) {
statement := table.Contact.SELECT(
table.Contact.AllColumns,
).FROM(table.Contact).
WHERE(
postgres.AND(
table.Contact.OrganizationID.EQ(postgres.Int(org_id)),
table.Contact.Name.EQ(postgres.String("")),
postgres.NOT(
postgres.EXISTS(
postgres.SELECT(
postgres.Int(1),
).FROM(table.ContactEmail).
WHERE(table.ContactEmail.ContactID.EQ(table.Contact.ID)),
)),
postgres.NOT(
postgres.EXISTS(
postgres.SELECT(
postgres.Int(1),
).FROM(table.ContactPhone).
WHERE(table.ContactPhone.ContactID.EQ(table.Contact.ID)),
)),
),
)
row, err := db.ExecuteOne[model.Contact](ctx, statement)
if err != nil {
if errors.Is(err, db.ErrNoRows) {
return nil, nil
}
return nil, fmt.Errorf("query contact: %w", err)
}
return &row, nil
}
func ContactFromID(ctx context.Context, txn db.Ex, id int64) (model.Contact, error) {
statement := table.Contact.SELECT(
table.Contact.AllColumns,