Sha256: f3f9edcf434e0621895b946ea9ac2163b75f96edf405f6192fceb26c7c8f026d

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Shark
  class Contact < Base
    extend ContactService::Resource
    include Shark::NormalizedEmail

    custom_endpoint :avatar, on: :collection, request_method: :get

    property :account_id

    has_many :memberships
    has_many :groups
    has_one :permission

    def self.find_by_email(email)
      normalized_email = normalize_email(email)
      options = { filter: { equals: { email: normalized_email } } }
      where(options).first
    end

    # @example
    #   contacts = Shark::ContactService::Contact.find_by_permissions([
    #     { resource: 'paragraph::contract', privilege: 'admin' },
    #     { resource: 'datenraum', privilege: 'admin'}
    #   ])
    #
    # @param permissions_filter [Array] the filter of resources and privileges.
    # @api public
    def self.find_by_permissions(permissions_filter)
      includes('permission').where(permissions: permissions_filter)
    end

    def account
      return nil if account_id.blank?

      Shark::Account.find(account_id).first
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bima-shark-sdk-2.3.1 lib/shark/contact.rb
bima-shark-sdk-2.3.0 lib/shark/contact.rb