github.com/litesolutions/justifay-api@v1.0.0-2.0.20220707114139-46f28a909481/internal/pkg/query/query.go (about)

     1  package query
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/litesolutions/justifay-api/model"
     7  )
     8  
     9  // ForTenant returns query for filtering rows by tenant_id
    10  func ForTenant(u *model.AuthUser, tenantId int32) string {
    11  	switch u.Role {
    12  	case model.SuperAdminRole, model.AdminRole:
    13  		if tenantId != 0 {
    14  			return fmt.Sprintf("tenant_id = %v", tenantId)
    15  		}
    16  		return ""
    17  	default:
    18  		return fmt.Sprintf("tenant_id = %v", u.TenantID)
    19  
    20  	}
    21  }