Allow entering custom amount to settle #18

Merged
bilal.catic merged 4 commits from allow-entering-custom-amount-to-settle into master 2020-10-06 08:43:05 +02:00
3 changed files with 6 additions and 5 deletions
Showing only changes of commit 04abd4be78 - Show all commits

View File

@@ -28,9 +28,10 @@ class HomiesController < ApplicationController
def settle
homie_id = params[:homie_id].to_i
amount = params[:amount].present? ? params[:amount].to_d : nil
homie = Homie.find(homie_id)
if homie.settle
if homie.settle(amount)
json_response []
else
error_response :bad_request

View File

@@ -12,8 +12,8 @@ class Homie < ApplicationRecord
end
end
def settle
total = MoneyMove.where(homie_id: id).all.sum(:amount)
def settle(amount)
total = amount.nil? ? MoneyMove.where(homie_id: id).all.sum(:amount) : amount
all_money_moves = MoneyMove.where(homie_id: id).all
transaction do
@@ -22,7 +22,7 @@ class Homie < ApplicationRecord
MoneyMove.create_settle_record(id, total)
end
true
rescue StandardError => e
rescue StandardError
false
end
end

View File

@@ -10,7 +10,7 @@ Rails.application.routes.draw do
get 'cash'
end
member do
delete 'settle'
post 'settle'
end
end
end