class FinApps::REST::Operators
Public Instance Methods
create(params, path = nil)
click to toggle source
Calls superclass method
# File lib/finapps/rest/operators.rb 23 def create(params, path = nil) 24 not_blank(params, :params) 25 super params, path 26 end
destroy(id)
click to toggle source
Calls superclass method
# File lib/finapps/rest/operators.rb 46 def destroy(id) 47 not_blank(id, :operator_id) 48 super id 49 end
list(params = nil)
click to toggle source
Calls superclass method
# File lib/finapps/rest/operators.rb 10 def list(params = nil) 11 return super if params.nil? 12 fail FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash 13 14 super build_query_path(end_point, params) 15 end
show(id)
click to toggle source
Calls superclass method
# File lib/finapps/rest/operators.rb 17 def show(id) 18 not_blank(id, :operator_id) 19 20 super id 21 end
update(id, params)
click to toggle source
Calls superclass method
# File lib/finapps/rest/operators.rb 28 def update(id, params) 29 not_blank(id, :operator_id) 30 not_blank(params, :params) 31 32 path = "#{end_point}/#{ERB::Util.url_encode(id)}" 33 super params, path 34 end
update_password(params)
click to toggle source
# File lib/finapps/rest/operators.rb 36 def update_password(params) 37 # update password for current operator, need authorization session in header 38 not_blank(params, :params) 39 fail FinAppsCore::InvalidArgumentsError, 'Invalid argument: params.' unless validates params 40 41 path = "#{end_point}/password/change" 42 43 create params, path 44 end
Private Instance Methods
build_filter(params)
click to toggle source
# File lib/finapps/rest/operators.rb 59 def build_filter(params) 60 term_filter(params[:searchTerm]).merge(role_filter(params[:role])) 61 end
role_filter(role)
click to toggle source
# File lib/finapps/rest/operators.rb 77 def role_filter(role) 78 return {} unless role 79 80 roles = to_integers_array(role) 81 return {} if roles.empty? 82 83 {role: {'$in': roles}} 84 end
term_array(term)
click to toggle source
# File lib/finapps/rest/operators.rb 69 def term_array(term) 70 if term.include?('@') 71 [{email: term}] 72 else 73 [{last_name: term}] 74 end 75 end
term_filter(term)
click to toggle source
# File lib/finapps/rest/operators.rb 63 def term_filter(term) 64 return {} unless term 65 66 {'$or': term_array(term)} 67 end
to_integers_array(role)
click to toggle source
# File lib/finapps/rest/operators.rb 86 def to_integers_array(role) 87 (role.respond_to?(:map) ? role : [role]).filter_map {|i| Integer(i) } 88 end
validates(params)
click to toggle source
# File lib/finapps/rest/operators.rb 53 def validates(params) 54 params.key?(:password) && params[:password] && 55 params.key?(:password_confirm) && 56 params[:password_confirm] 57 end