fix: user location fix
This commit is contained in:
@@ -51,15 +51,17 @@ const (
|
||||
type ReminderService struct {
|
||||
repo *repository.ReminderRepo
|
||||
prefs *repository.NotificationPrefsRepo
|
||||
users *repository.UserRepo
|
||||
notif *NotificationService
|
||||
logger *zap.Logger
|
||||
sadhnaURL string
|
||||
}
|
||||
|
||||
func NewReminderService(repo *repository.ReminderRepo, prefs *repository.NotificationPrefsRepo, notif *NotificationService, logger *zap.Logger, frontendURL string) *ReminderService {
|
||||
func NewReminderService(repo *repository.ReminderRepo, prefs *repository.NotificationPrefsRepo, users *repository.UserRepo, notif *NotificationService, logger *zap.Logger, frontendURL string) *ReminderService {
|
||||
return &ReminderService{
|
||||
repo: repo,
|
||||
prefs: prefs,
|
||||
users: users,
|
||||
notif: notif,
|
||||
logger: logger,
|
||||
sadhnaURL: strings.TrimRight(frontendURL, "/") + "/sadhna-streak",
|
||||
@@ -116,7 +118,21 @@ func (s *ReminderService) SetTimezone(ctx context.Context, userID, tz string) er
|
||||
if _, err := time.LoadLocation(tz); err != nil {
|
||||
return ErrInvalidTimezone
|
||||
}
|
||||
return s.repo.SetTimezone(ctx, userID, tz)
|
||||
if err := s.repo.SetTimezone(ctx, userID, tz); err != nil {
|
||||
return err
|
||||
}
|
||||
// Best-effort: backfill the account country from the timezone when it's
|
||||
// still unset (geo-IP at login is the primary source; SetCountryIfEmpty
|
||||
// never overwrites it). A no-op when the zone isn't in the table.
|
||||
if s.users != nil {
|
||||
if cc := tzCountry[tz]; cc != "" {
|
||||
if err := s.users.SetCountryIfEmpty(ctx, userID, cc); err != nil {
|
||||
s.logger.Warn("backfill country from timezone failed",
|
||||
zap.String("user", userID), zap.String("country", cc), zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunOnce evaluates every due candidate against `now` and fires the reminders
|
||||
|
||||
Reference in New Issue
Block a user