mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Add from/until sorting to balance API
This commit is contained in:
parent
27e441bc24
commit
7b4214def1
2 changed files with 8 additions and 14 deletions
|
@ -2,10 +2,9 @@ module Repp
|
||||||
module V1
|
module V1
|
||||||
class AccountsController < BaseController
|
class AccountsController < BaseController
|
||||||
def balance
|
def balance
|
||||||
return activity if params[:detailed] == 'true'
|
|
||||||
|
|
||||||
resp = { balance: current_user.registrar.cash_account.balance,
|
resp = { balance: current_user.registrar.cash_account.balance,
|
||||||
currency: current_user.registrar.cash_account.currency }
|
currency: current_user.registrar.cash_account.currency }
|
||||||
|
resp[:activities] = activities if params[:detailed] == 'true'
|
||||||
render_success(data: resp)
|
render_success(data: resp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,22 +16,21 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def activities
|
def activities
|
||||||
bal = current_user.registrar.cash_account.balance
|
|
||||||
act = []
|
|
||||||
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
||||||
|
activities = activities.where('created_at >= ?', params[:from]) if params[:from]
|
||||||
|
activities = activities.where('created_at <= ?', params[:until]) if params[:until]
|
||||||
|
arr = []
|
||||||
activities.each do |a|
|
activities.each do |a|
|
||||||
act << {
|
arr << {
|
||||||
created_at: a.created_at,
|
created_at: a.created_at,
|
||||||
description: a.description,
|
description: a.description,
|
||||||
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
||||||
sum: a.sum,
|
sum: a.sum,
|
||||||
balance: bal,
|
balance: a.new_balance,
|
||||||
}
|
}
|
||||||
|
|
||||||
bal = a.activity_type == 'add_credit' ? bal = bal + a.sum : bal - a.sum
|
|
||||||
end
|
end
|
||||||
|
|
||||||
act
|
arr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,10 +13,6 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
||||||
get '/repp/v1/accounts/balance', headers: @auth_headers
|
get '/repp/v1/accounts/balance', headers: @auth_headers
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
puts response.body
|
|
||||||
puts @registrar.registrar.cash_account.balance
|
|
||||||
puts @registrar.registrar.cash_account.currency
|
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal 1000, json[:code]
|
assert_equal 1000, json[:code]
|
||||||
assert_equal 'Command completed successfully', json[:message]
|
assert_equal 'Command completed successfully', json[:message]
|
||||||
|
@ -28,7 +24,7 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
||||||
started_from = "2020-01-01"
|
started_from = "2020-01-01"
|
||||||
end_to = DateTime.current.to_date.to_s(:db)
|
end_to = DateTime.current.to_date.to_s(:db)
|
||||||
|
|
||||||
get "/repp/v1/accounts/balance?detailed=true&started_from=#{started_from}&end_to=#{end_to}", headers: @auth_headers
|
get "/repp/v1/accounts/balance?detailed=true&from=#{started_from}&until=#{end_to}", headers: @auth_headers
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue