Merge branch 'master' of https://github.com/ZeusWPI/Tab
This commit is contained in:
commit
f9b6f17456
5 changed files with 13 additions and 17 deletions
|
@ -12,7 +12,6 @@ class TransactionsQuery
|
|||
def query
|
||||
Arel::SelectManager.new(ActiveRecord::Base)
|
||||
.from(arel)
|
||||
.order(@arel_table[:time].desc)
|
||||
end
|
||||
|
||||
def arel
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
class TransactionsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
skip_before_filter :verify_authenticity_token, only: :create
|
||||
|
||||
before_action :authenticate_user!, except: :create
|
||||
before_action :authenticate_user_or_client!, only: :create
|
||||
respond_to :js, only: :create
|
||||
|
||||
def index
|
||||
@transactions = Transaction.all
|
||||
end
|
||||
|
||||
def create
|
||||
@transaction = Transaction.new(transaction_params)
|
||||
@transaction.reverse if @transaction.amount < 0
|
||||
authorize!(:create, @transaction)
|
||||
|
||||
if @transaction.save
|
||||
head :created
|
||||
else
|
||||
render json: @transaction.errors.full_messages, status: :unprocessable_entity
|
||||
render json: @transaction.errors.full_messages,
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -24,13 +24,6 @@ class Transaction < ActiveRecord::Base
|
|||
validates :amount, numericality: { greater_than: 0 }
|
||||
validate :different_debtor_creditor
|
||||
|
||||
def initialize *args, **kwargs
|
||||
super *args, **kwargs
|
||||
if amount < 0
|
||||
self.creditor, self.debtor = debtor, creditor
|
||||
self.amount = self.amount.abs
|
||||
end
|
||||
end
|
||||
|
||||
def peer_of(user)
|
||||
return creditor if user == debtor
|
||||
|
@ -42,6 +35,11 @@ class Transaction < ActiveRecord::Base
|
|||
return amount if user == creditor
|
||||
end
|
||||
|
||||
def reverse
|
||||
self.creditor, self.debtor = self.debtor, self.creditor
|
||||
self.amount *= -1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def recalculate_balances
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
.input-group
|
||||
%span.input-group-addon
|
||||
%span.glyphicon.glyphicon-calendar
|
||||
%input.lower-bound.form-control.filter-align{type: 'date', placeholder: 'after', class: 'pure-group-addon'}
|
||||
%input.lower-bound.form-control.filter-align{type: 'date', placeholder: 'After', class: 'pure-group-addon'}
|
||||
.col-md-6
|
||||
.input-group
|
||||
%span.input-group-addon
|
||||
%span.glyphicon.glyphicon-calendar
|
||||
%input.upper-bound.form-control.filter-align{type: 'date', placeholder: 'after', class: 'pure-group-addon'}
|
||||
%input.upper-bound.form-control.filter-align{type: 'date', placeholder: 'Before', class: 'pure-group-addon'}
|
||||
.bound.input-listen.pure-u-1{ 'data-input-type': 'number-range', 'data-filter-name': 'Amount' }
|
||||
.row
|
||||
.col-md-6
|
||||
|
|
|
@ -35,5 +35,4 @@ RSpec.describe Transaction, type: :model do
|
|||
expect {trans.save!}.to change {@user.balance}.by(-10)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue