lib/finapps/rest/documents_orders.rb in finapps-5.0.32 vs lib/finapps/rest/documents_orders.rb in finapps-5.0.33

- old
+ new

@@ -8,11 +8,11 @@ include FinApps::Utils::QueryBuilder def list(params = nil) path = 'documents/orders' return super(path) if params.nil? - raise FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash + fail FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash super build_query_path(path, params) end def show(id) @@ -44,61 +44,62 @@ end private def build_filter(params) - search_query(params[:searchTerm]).merge(consumer_query(params[:consumer])).merge(tag_query(params[:tag])) + search_query(params[:searchTerm]) + .merge(consumer_query(params[:consumer])) + .merge(tag_query(params[:tag])) + .merge(status_query(params[:status])) end def search_query(term) - if term - query = with_space_search(term).concat(name_search(term)) - { - "$or": query - } - else - {} - end + return {} unless term + + query = with_space_search(term).concat(name_search(term)) + {"$or": query} end def name_search(term) search_arr = [] - if term.match(/\s/) + if /\s/.match?(term) term.split.each do |t| search_arr.append("applicant.first_name": t) search_arr.append("applicant.last_name": t) end end search_arr end def with_space_search(term) [ - { "applicant.email": term }, - { "applicant.first_name": term }, - { "applicant.last_name": term }, + {"applicant.email": term}, + {"applicant.first_name": term}, + {"applicant.last_name": term}, { "reference_no": { "$regex": "^#{term}", "$options": 'i' } } ] end def tag_query(tag) - if tag - { "tag": tag.empty? ? nil : tag } - else - {} - end + return {} unless tag + + {"tag": tag.empty? ? nil : tag} end + def status_query(status) + return {} unless status + + {status: status} + end + def consumer_query(consumer) - if consumer - { "consumer_id": consumer.empty? ? nil : consumer } - else - {} - end + return {} unless consumer + + {"consumer_id": consumer.empty? ? nil : consumer} end end end end