The key item here is that comms.phone and comms.email are meant to represent a real global namespace, but comms.contact is meant to represent an organization-specific namespace. This means the mapping, comms.contact_phone and comms.contact_email can't key off the global namespace. Otherwise the contact namespace would implicitly be global.
35 lines
1.2 KiB
Go
35 lines
1.2 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{
|
|
CanSms: true,
|
|
ConfirmedMessageID: nil,
|
|
ContactID: contact.ID,
|
|
E164: destination,
|
|
IsSubscribed: false,
|
|
StopMessageID: nil,
|
|
}
|
|
_, 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,
|
|
E164: number.PhoneString(),
|
|
IsSubscribed: false,
|
|
Status: modelcomms.Phonestatustype_Unconfirmed,
|
|
})
|
|
}
|