Make username unique, make is_subscribed nullable
This commit is contained in:
parent
1cd4a31404
commit
e8e840ec44
11 changed files with 149 additions and 74 deletions
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/nyaruka/phonenumbers"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
|
|
@ -55,7 +56,7 @@ func ensureInDB(ctx context.Context, destination string) (err error) {
|
|||
if err.Error() == "sql: no rows in result set" {
|
||||
_, err = models.CommsPhones.Insert(&models.CommsPhoneSetter{
|
||||
E164: omit.From(destination),
|
||||
IsSubscribed: omit.From(false),
|
||||
IsSubscribed: omitnull.FromPtr[bool](nil),
|
||||
}).One(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to insert new phone contact: %w", err)
|
||||
|
|
@ -81,16 +82,6 @@ func insertTextLog(ctx context.Context, content string, destination string, sour
|
|||
|
||||
return err
|
||||
}
|
||||
func isSubscribed(ctx context.Context, destination string) (bool, error) {
|
||||
phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, destination)
|
||||
if err != nil {
|
||||
if err.Error() == "sql: no rows in result set" {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to find phone number %s: %w", destination, err)
|
||||
}
|
||||
return phone.IsSubscribed, nil
|
||||
}
|
||||
|
||||
func generatePublicId(t enums.CommsMessagetypeemail, m map[string]string) string {
|
||||
if m == nil || len(m) == 0 {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/nyaruka/phonenumbers"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
|
@ -43,29 +44,32 @@ func (j jobReportSubscription) source() string {
|
|||
}
|
||||
|
||||
func sendReportSubscription(ctx context.Context, job Job) error {
|
||||
j, ok := job.(jobReportSubscription)
|
||||
if !ok {
|
||||
return fmt.Errorf("job is not for report subscription confirmation")
|
||||
}
|
||||
/*
|
||||
j, ok := job.(jobReportSubscription)
|
||||
if !ok {
|
||||
return fmt.Errorf("job is not for report subscription confirmation")
|
||||
}
|
||||
|
||||
sub, err := isSubscribed(ctx, job.destination())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to check if subscribed: %w", err)
|
||||
}
|
||||
if !sub {
|
||||
err = sendText(ctx, j.source(), j.destination(), j.content(), enums.CommsTextoriginWebsiteAction, false)
|
||||
sub, err := isSubscribed(ctx, job.destination())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send report subscription confirmation: %w", err)
|
||||
return fmt.Errorf("Failed to check if subscribed: %w", err)
|
||||
}
|
||||
} else {
|
||||
err = delayMessage(ctx, j.source(), j.destination(), j.content(), enums.CommsTextjobtypeReportConfirmation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to delay report subscription message: %w", err)
|
||||
if !sub {
|
||||
err = sendText(ctx, j.source(), j.destination(), j.content(), enums.CommsTextoriginWebsiteAction, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send report subscription confirmation: %w", err)
|
||||
}
|
||||
} else {
|
||||
err = delayMessage(ctx, j.source(), j.destination(), j.content(), enums.CommsTextjobtypeReportConfirmation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to delay report subscription message: %w", err)
|
||||
}
|
||||
err := ensureInitialText(ctx, j.source(), j.destination())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to ensure initial text has been sent: %w", err)
|
||||
}
|
||||
}
|
||||
err := ensureInitialText(ctx, j.source(), j.destination())
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to ensure initial text has been sent: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue