fix: user location fix

This commit is contained in:
Krispire Admin
2026-06-18 22:57:12 +05:30
parent 5c0581a1da
commit dc204577a8
3 changed files with 443 additions and 3 deletions
+18 -2
View File
@@ -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