Move properties of phones to the phone, not contact_phone

This makes sense because there will naturally be cases where multiple
districts have the same phone number mapped to different contacts.
This commit is contained in:
Eli Ribble 2026-05-22 20:56:22 +00:00
parent f957dc6982
commit 7b04822a9b
No known key found for this signature in database
14 changed files with 143 additions and 104 deletions

View file

@ -27,26 +27,6 @@ func ContactPhoneFromE164(ctx context.Context, txn db.Ex, e164 string) (model.Co
return db.ExecuteOneTx[model.ContactPhone](ctx, txn, statement)
}
func ContactPhoneUpdateConfirmedMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
statement := table.ContactPhone.UPDATE().
SET(table.ContactPhone.ConfirmedMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}
func ContactPhoneUpdateStopMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
/*
m := model.ContactPhone{}
m.StopMessageID = message_id
statement := table.ContactPhone.UPDATE(
table.ContactPhone.StopMessageID,
).MODEL(m).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
*/
statement := table.ContactPhone.UPDATE().
SET(table.ContactPhone.StopMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}
func ContactPhoneByContactIDs(ctx context.Context, txn db.Ex, contact_ids []int64) (result map[int64][]model.ContactPhone, err error) {
sql_ids := make([]postgres.Expression, len(contact_ids))
for i, contact_id := range contact_ids {

View file

@ -40,3 +40,34 @@ func PhoneFromE164(ctx context.Context, txn db.Ex, e164 string) (model.Phone, er
WHERE(table.Phone.E164.EQ(postgres.String(e164)))
return db.ExecuteOneTx[model.Phone](ctx, txn, statement)
}
func PhonesFromE164s(ctx context.Context, txn db.Ex, e164s []string) ([]model.Phone, error) {
sql_ids := make([]postgres.Expression, len(e164s))
for i, e164 := range e164s {
sql_ids[i] = postgres.String(e164)
}
statement := table.Phone.SELECT(
table.Phone.AllColumns,
).FROM(table.Phone).
WHERE(table.Phone.E164.IN(sql_ids...))
return db.ExecuteManyTx[model.Phone](ctx, txn, statement)
}
func PhoneUpdateConfirmedMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
statement := table.Phone.UPDATE().
SET(table.Phone.ConfirmedMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.Phone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}
func PhoneUpdateStopMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
/*
m := model.Phone{}
m.StopMessageID = message_id
statement := table.Phone.UPDATE(
table.Phone.StopMessageID,
).MODEL(m).
WHERE(table.Phone.E164.EQ(postgres.String(e164)))
*/
statement := table.Phone.UPDATE().
SET(table.Phone.StopMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.Phone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}