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:
parent
2d4a0347d6
commit
3cafca6cbd
3 changed files with 56 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue