nidus-sync/platform/text/phone_number.go

38 lines
1.4 KiB
Go
Raw Normal View History

package text
import (
"context"
"fmt"
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
"source.gleipnir.technology/Gleipnir/nidus-sync/db/enums"
modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
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 phoneStatus(ctx context.Context, src types.E164) (enums.CommsPhonestatustype, error) {
phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString())
if err != nil {
return enums.CommsPhonestatustypeUnconfirmed, fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src.PhoneString(), err)
}
return phone.Status, nil
}