This makes sense because there will naturally be cases where multiple districts have the same phone number mapped to different contacts.
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package text
|
|
|
|
import (
|
|
"context"
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
|
|
querycomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/comms"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
|
//"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func EnsureInDB(ctx context.Context, txn db.Ex, contact modelcomms.Contact, dst types.E164) (err error) {
|
|
return ensureInDB(ctx, txn, contact, dst.PhoneString())
|
|
}
|
|
func ensureInDB(ctx context.Context, txn db.Ex, contact modelcomms.Contact, destination string) (err error) {
|
|
contact_phone := modelcomms.ContactPhone{
|
|
ContactID: contact.ID,
|
|
E164: destination,
|
|
}
|
|
_, err = querycomms.ContactPhoneInsert(ctx, txn, contact_phone)
|
|
return err
|
|
}
|
|
func ensurePhoneInDB(ctx context.Context, txn db.Ex, number *types.E164) (modelcomms.Phone, error) {
|
|
return querycomms.PhoneInsertIfNotExists(ctx, txn, modelcomms.Phone{
|
|
CanSms: false,
|
|
ConfirmedMessageID: nil,
|
|
E164: number.PhoneString(),
|
|
StopMessageID: nil,
|
|
})
|
|
}
|