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,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package platform
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
modelcomms "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
|
||||
querycomms "github.com/Gleipnir-Technology/nidus-sync/db/query/comms"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
)
|
||||
|
|
@ -58,3 +60,17 @@ func ContactsForOrganization(ctx context.Context, org_id int32) (results []types
|
|||
}
|
||||
return results, nil
|
||||
}
|
||||
func ContactEmptyForOrganization(ctx context.Context, txn db.Ex, org_id int32) (modelcomms.Contact, error) {
|
||||
contact, err := querycomms.ContactEmptyForOrganization(ctx, txn, int64(org_id))
|
||||
if err != nil {
|
||||
return modelcomms.Contact{}, fmt.Errorf("querycomms: %w", err)
|
||||
}
|
||||
if contact != nil {
|
||||
return *contact, nil
|
||||
}
|
||||
return querycomms.ContactInsert(ctx, txn, modelcomms.Contact{
|
||||
Created: time.Now(),
|
||||
Name: "",
|
||||
OrganizationID: org_id,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,6 +379,11 @@ func publicReportCreate(ctx context.Context, setter_report modelpublicreport.Rep
|
|||
}
|
||||
setter_report.OrganizationID = organization_id
|
||||
|
||||
contact, err := ContactEmptyForOrganization(ctx, txn, organization_id)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("contact empty: %w", err)
|
||||
}
|
||||
setter_report.ReporterContactID = &contact.ID
|
||||
if addr != nil {
|
||||
setter_report.AddressID = addr.ID
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue