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

@ -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,
})
}

View file

@ -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
}