Add Filter and Total Tempat WIsata
This commit is contained in:
@@ -207,3 +207,22 @@ func (r *UserRepository) UpdateUserWithTx(ctx context.Context, tx *gorm.DB, user
|
||||
func logError(ctx context.Context, action string, err error) {
|
||||
logger.ContextLogger(ctx).Error("error when "+action, zap.Error(err))
|
||||
}
|
||||
|
||||
func (r *UserRepository) CountUsersByRoleAndSiteOrPartner(ctx context.Context, roleID int, siteID *int64) (int, error) {
|
||||
var count int64
|
||||
|
||||
query := r.db.Table("users").
|
||||
Joins("LEFT JOIN user_roles ur ON users.id = ur.user_id").
|
||||
Where("ur.role_id = ?", roleID)
|
||||
|
||||
if siteID != nil {
|
||||
query = query.Where("ur.site_id = ?", siteID)
|
||||
}
|
||||
|
||||
if err := query.Count(&count).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when counting users by role and site/partner", zap.Error(err))
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(count), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user