Update reporter contact on report update
This is as a complicated one because it involves merging contact information in tricky cases. I assume that phone should override email, primarily because setting up phones is more tightly regulated. This may be a terrible assumption. Issue: #13
This commit is contained in:
parent
dcce7cda1c
commit
6175e1a811
5 changed files with 139 additions and 30 deletions
|
|
@ -53,6 +53,24 @@ func ContactEmptyForOrganization(ctx context.Context, txn db.Ex, org_id int64) (
|
|||
}
|
||||
return &row, nil
|
||||
}
|
||||
func ContactFromEmail(ctx context.Context, txn db.Ex, email string) (*model.Contact, error) {
|
||||
statement := table.Contact.SELECT(
|
||||
table.Contact.AllColumns,
|
||||
).FROM(
|
||||
table.Contact.INNER_JOIN(
|
||||
table.ContactEmail,
|
||||
table.ContactEmail.ContactID.EQ(table.Contact.ID),
|
||||
),
|
||||
).WHERE(table.ContactEmail.Address.EQ(postgres.String(email)))
|
||||
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 from email '%s': %w", email, err)
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
func ContactFromID(ctx context.Context, txn db.Ex, id int64) (model.Contact, error) {
|
||||
statement := table.Contact.SELECT(
|
||||
table.Contact.AllColumns,
|
||||
|
|
@ -74,7 +92,24 @@ func ContactsFromIDs(ctx context.Context, txn db.Ex, contact_ids []int64) ([]mod
|
|||
WHERE(table.Contact.ID.IN(sql_ids...))
|
||||
return db.ExecuteManyTx[model.Contact](ctx, txn, statement)
|
||||
}
|
||||
|
||||
func ContactFromPhone(ctx context.Context, txn db.Ex, e164 string) (*model.Contact, error) {
|
||||
statement := table.Contact.SELECT(
|
||||
table.Contact.AllColumns,
|
||||
).FROM(
|
||||
table.Contact.INNER_JOIN(
|
||||
table.ContactPhone,
|
||||
table.ContactPhone.ContactID.EQ(table.Contact.ID),
|
||||
),
|
||||
).WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
|
||||
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 from phone '%s': %w", e164, err)
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
func ContactUpdateName(ctx context.Context, txn db.Ex, id int64, name string) error {
|
||||
statement := table.Contact.UPDATE().
|
||||
SET(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue