diff --git a/apps/api-gql/internal/delivery/gql/resolvers/admin-users.resolver.go b/apps/api-gql/internal/delivery/gql/resolvers/admin-users.resolver.go index 589596636..d1cdccfb1 100644 --- a/apps/api-gql/internal/delivery/gql/resolvers/admin-users.resolver.go +++ b/apps/api-gql/internal/delivery/gql/resolvers/admin-users.resolver.go @@ -86,7 +86,7 @@ func (r *queryResolver) TwirUsers( PerPage: perPage, ChannelIsEnabled: opts.IsBotEnabled.Value(), ChannelIsBotAdmin: opts.IsBotAdmin.Value(), - ChannelIsBanned: opts.IsBanned.Value(), + UserIsBanned: opts.IsBanned.Value(), HasBadges: opts.Badges.Value(), } diff --git a/apps/api-gql/internal/services/twir-users/twir-users.go b/apps/api-gql/internal/services/twir-users/twir-users.go index 830bd76a7..48420ac77 100644 --- a/apps/api-gql/internal/services/twir-users/twir-users.go +++ b/apps/api-gql/internal/services/twir-users/twir-users.go @@ -61,7 +61,7 @@ type GetManyInput struct { PerPage int ChannelIsEnabled *bool ChannelIsBotAdmin *bool - ChannelIsBanned *bool + UserIsBanned *bool HasBadges []string } @@ -96,7 +96,7 @@ func (c *Service) GetMany(ctx context.Context, input GetManyInput) ( IDs: nil, ChannelEnabled: input.ChannelIsEnabled, ChannelIsBotAdmin: input.ChannelIsBotAdmin, - ChannelIsBanned: input.ChannelIsBanned, + IsBanned: input.UserIsBanned, HasBadgesIDS: input.HasBadges, } diff --git a/libs/repositories/users-with-channel/pgx/pgx.go b/libs/repositories/users-with-channel/pgx/pgx.go index 52c0b6094..907c926c9 100644 --- a/libs/repositories/users-with-channel/pgx/pgx.go +++ b/libs/repositories/users-with-channel/pgx/pgx.go @@ -152,8 +152,8 @@ func (c *Pgx) GetManyByIDS( selectQuery = selectQuery.Where(squirrel.Eq{`u."isBotAdmin"`: input.ChannelIsBotAdmin}) } - if input.ChannelIsBanned != nil { - selectQuery = selectQuery.Where(squirrel.Eq{`u.is_banned`: input.ChannelIsBanned}) + if input.IsBanned != nil { + selectQuery = selectQuery.Where(squirrel.Eq{`u.is_banned`: input.IsBanned}) } query, args, err := selectQuery.ToSql() @@ -184,15 +184,17 @@ func (c *Pgx) GetManyCount(ctx context.Context, input users_with_channel.GetMany error, ) { selectQuery := sq. - Select("COUNT(DISTINCT u.id)"). - From("users u"). - LeftJoin("channels uc ON u.id = uc.id"). - LeftJoin("badges_users bu ON u.id = bu.user_id") + Select("COUNT(*)"). + From("users u") if len(input.IDs) > 0 { selectQuery = selectQuery.Where(squirrel.Eq{"u.id": input.IDs}) } + if input.ChannelIsBotAdmin != nil || input.ChannelEnabled != nil { + selectQuery = selectQuery.LeftJoin("channels uc ON u.id = uc.id") + } + if input.ChannelEnabled != nil { selectQuery = selectQuery.Where(squirrel.Eq{`uc."isEnabled"`: input.ChannelEnabled}) } @@ -201,12 +203,14 @@ func (c *Pgx) GetManyCount(ctx context.Context, input users_with_channel.GetMany selectQuery = selectQuery.Where(squirrel.Eq{`u."isBotAdmin"`: input.ChannelIsBotAdmin}) } - if input.ChannelIsBanned != nil { - selectQuery = selectQuery.Where(squirrel.Eq{`u.is_banned`: input.ChannelIsBanned}) + if input.IsBanned != nil { + selectQuery = selectQuery.Where(squirrel.Eq{`u.is_banned`: input.IsBanned}) } if len(input.HasBadgesIDS) > 0 { - selectQuery = selectQuery.Where(squirrel.Eq{"bu.badge_id": input.HasBadgesIDS}) + selectQuery = selectQuery. + LeftJoin("channels uc ON u.id = uc.id"). + Where(squirrel.Eq{"bu.badge_id": input.HasBadgesIDS}) } query, args, err := selectQuery.ToSql() diff --git a/libs/repositories/users-with-channel/users-with-channel.go b/libs/repositories/users-with-channel/users-with-channel.go index b19d4b7cf..d112d6b58 100644 --- a/libs/repositories/users-with-channel/users-with-channel.go +++ b/libs/repositories/users-with-channel/users-with-channel.go @@ -20,5 +20,5 @@ type GetManyInput struct { ChannelEnabled *bool ChannelIsBotAdmin *bool - ChannelIsBanned *bool + IsBanned *bool }