Add API v1 finance_overview endpoint
This commit is contained in:
parent
4752a0aaa9
commit
7a6779ebfd
5 changed files with 140 additions and 0 deletions
23
app/controllers/api/v1/user/ordergroup_controller.rb
Normal file
23
app/controllers/api/v1/user/ordergroup_controller.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class Api::V1::User::OrdergroupController < Api::V1::BaseController
|
||||
|
||||
before_action ->{ doorkeeper_authorize! 'finance:user' }, only: [:financial_overview]
|
||||
|
||||
def financial_overview
|
||||
ordergroup = Ordergroup.include_transaction_class_sum.find(current_ordergroup.id)
|
||||
|
||||
render json: {
|
||||
financial_overview: {
|
||||
account_balance: ordergroup.account_balance.to_f,
|
||||
available_funds: ordergroup.get_available_funds.to_f,
|
||||
financial_transaction_class_sums: FinancialTransactionClass.sorted.map { |c|
|
||||
{
|
||||
id: c.id,
|
||||
name: c.display,
|
||||
amount: ordergroup["sum_of_class_#{c.id}"].to_f
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue