Sha256: 40e05ab6ae35d93518d7ef50bef157ccae3bf8022f0b3d3f35aa4e6fc8ea3b5c

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require_relative '../utils/query_builder'

module FinApps
  module REST
    class Screenings < FinAppsCore::REST::Resources # :nodoc:
      include FinApps::Utils::QueryBuilder

      def show(id)
        not_blank(id, :session_id)

        path = "#{end_point}/#{ERB::Util.url_encode(id)}/resume"
        super(nil, path)
      end

      def tenant_schemas
        path = 'schemas'
        send_request path, :get
      end

      def last(consumer_id)
        not_blank(consumer_id, :consumer_id)

        path = "#{end_point}/#{ERB::Util.url_encode(consumer_id)}/consumer"
        send_request_for_id path, :get, nil
      end

      def create(params)
        not_blank(params, :params)
        super params
      end

      def list(params = nil)
        return super if params.nil?
        fail FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash

        super build_query_path(end_point, params)
      end

      def update(id, params)
        not_blank(id, :session_id)
        not_blank(params, :params)

        path = "#{end_point}/#{ERB::Util.url_encode(id)}"
        super params, path
      end

      def destroy(id)
        not_blank(id, :session_id)

        super
      end

      private

      def build_filter(params)
        search_query(params[:searchTerm])
      end

      def search_query(term)
        return {} unless term

        query = search_query_object(term)
        {'$or': query}
      end

      def search_query_object(term)
        [
          {'consumer.public_id': term},
          {'consumer.email': term}
        ]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
finapps-6.3.1 lib/finapps/rest/screenings.rb
finapps-6.3.0 lib/finapps/rest/screenings.rb
finapps-6.2.0 lib/finapps/rest/screenings.rb
finapps-6.1.0 lib/finapps/rest/screenings.rb
finapps-6.0.0 lib/finapps/rest/screenings.rb