33 lines
983 B
Ruby
33 lines
983 B
Ruby
class Blockchain::BalanceQuery < ApplicationQuery
|
|
|
|
attr_reader :params, :is_current_admin_user
|
|
|
|
def initialize(params,is_current_admin_user)
|
|
@params = params
|
|
@is_current_admin_user = is_current_admin_user
|
|
end
|
|
|
|
def call
|
|
if is_current_admin_user
|
|
token_list, total_count = find_repo_with_token(params["user_id"], (params["page"] || 1), (params["limit"] || 10))
|
|
result_list = []
|
|
token_list.each do |t|
|
|
project = Project.find_by(id: t['token_name'].to_i)
|
|
if project.nil?
|
|
result_list << {project: nil, balance: t['balance']}
|
|
next
|
|
end
|
|
owner = User.find_by(id: project.user_id)
|
|
if owner.nil? || project.nil?
|
|
else
|
|
balance = t['balance']
|
|
result_list << {project: project, balance: balance}
|
|
end
|
|
end
|
|
results = {"status": 0, "projects": result_list, "total_count": total_count}
|
|
else
|
|
results = {"status": 1} # query failed
|
|
end
|
|
end
|
|
end
|