42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package transaction
|
|
|
|
import (
|
|
"Rezina-Backend/internal/domain"
|
|
"Rezina-Backend/internal/ports"
|
|
"Rezina-Backend/internal/services/user"
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrBranchRequiredForRole = errors.New("branch_id is required to be passed for this role")
|
|
ErrInvalidBranchID = errors.New("invalid branch id")
|
|
ErrUnauthorizedCompanyID = errors.New("unauthorized company id")
|
|
ErrUnauthorizedBranchManager = errors.New("unauthorized branch manager")
|
|
ErrCustomerRoleNotAuthorized = errors.New("customer role not authorized")
|
|
ErrDepositCannotBeUnverified = errors.New("deposit cannot be unverified")
|
|
ErrShopBetHasExpired = errors.New("shop bet has already been expired")
|
|
)
|
|
|
|
type Service struct {
|
|
transactionStore ports.TransactionStore
|
|
userSvc *user.Service
|
|
}
|
|
|
|
func NewService(
|
|
transactionStore ports.TransactionStore,
|
|
userSvc *user.Service,
|
|
) *Service {
|
|
return &Service{
|
|
transactionStore: transactionStore,
|
|
userSvc: userSvc,
|
|
}
|
|
}
|
|
|
|
func (s *Service) GetBranchByRole(ctx context.Context, branchID *int64, role domain.Role, userID int64, userCompanyID domain.ValidInt64) (*int64, *int64, error) {
|
|
if (role == domain.RoleAdmin || role == domain.RoleSuperAdmin) && branchID == nil {
|
|
return nil, nil, ErrBranchRequiredForRole
|
|
}
|
|
return nil, nil, ErrCustomerRoleNotAuthorized
|
|
}
|