fix: resolve role-based bulk notification user targeting

GetAllUsers with unset PageSize was issuing LIMIT 0, so role-only bulk sends returned no recipients. Default to 100k for unpaginated lookups and normalize role/status case.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Yared Yemane 2026-06-15 06:57:33 -07:00
parent c73d2880ef
commit 9b3f494669
2 changed files with 16 additions and 5 deletions

View File

@ -877,7 +877,7 @@ Valid platform `users.role` values:
| Super admin | `SUPER_ADMIN` |
| Support | `SUPPORT` |
When `role` is set without `user_ids`, the API loads **all users** matching that role.
When `role` is set without `user_ids`, the API loads **all users** matching that role (up to 100k). Role values are matched case-insensitively (`STUDENT`, `student`, etc.).
### Combining targets

View File

@ -3,9 +3,13 @@ package user
import (
"Yimaru-Backend/internal/domain"
"context"
"strings"
"time"
)
// defaultUnpaginatedUserLimit is used when PageSize is unset (e.g. bulk notification role targeting).
const defaultUnpaginatedUserLimit int64 = 100_000
func (s *Service) UpdateUserKnowledgeLevel(ctx context.Context, userID int64, knowledgeLevel string) error {
return s.userStore.UpdateUserKnowledgeLevel(ctx, userID, knowledgeLevel)
}
@ -76,12 +80,14 @@ func (s *Service) GetAllUsers(
var role *string
if filter.Role != "" {
role = &filter.Role
normalized := strings.ToUpper(strings.TrimSpace(filter.Role))
role = &normalized
}
var status *string
if filter.Status != "" {
status = &filter.Status
normalized := strings.ToUpper(strings.TrimSpace(filter.Status))
status = &normalized
}
var query *string
@ -104,7 +110,12 @@ func (s *Service) GetAllUsers(
subscriptionStatus = &filter.SubscriptionStatus
}
offset := int32(filter.Page * filter.PageSize)
pageSize := filter.PageSize
if pageSize <= 0 {
pageSize = defaultUnpaginatedUserLimit
}
offset := int32(filter.Page * pageSize)
return s.userStore.GetAllUsers(
ctx,
@ -116,7 +127,7 @@ func (s *Service) GetAllUsers(
country,
region,
subscriptionStatus,
int32(filter.PageSize),
int32(pageSize),
offset,
)
}