Skip to content

Commit 39ce959

Browse files
sauloperezenricostano
authored andcommitted
Revert "Extract GiveTime service"
This reverts commit 6c4202b.
1 parent c42b636 commit 39ce959

File tree

3 files changed

+25
-69
lines changed

3 files changed

+25
-69
lines changed

app/controllers/users_controller.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ def update
6262
end
6363

6464
def give_time
65-
give_time = GiveTime.new(self)
66-
67-
@user = give_time.user
68-
@transfer = give_time.transfer
69-
@sources = give_time.sources
70-
@offer = give_time.offer
65+
@user = scoped_users.find(params[:id])
66+
@destination = @user.members.
67+
find_by(organization: current_organization).account.id
68+
@source = find_transfer_source
69+
@offer = find_transfer_offer
70+
@transfer = Transfer.new(source: @source,
71+
destination: @destination,
72+
post: @offer)
73+
@sources = find_transfer_sources_for_admin
7174
end
7275

7376
private
@@ -82,6 +85,22 @@ def user_params
8285
params.require(:user).permit *fields_to_permit
8386
end
8487

88+
def find_transfer_offer
89+
current_organization.offers.
90+
find(params[:offer]) if params[:offer].present?
91+
end
92+
93+
def find_transfer_source
94+
current_user.members.
95+
find_by(organization: current_organization).account.id
96+
end
97+
98+
def find_transfer_sources_for_admin
99+
return unless admin?
100+
[current_organization.account] +
101+
current_organization.member_accounts.where("members.active is true")
102+
end
103+
85104
def find_user
86105
if current_user.id == params[:id].to_i
87106
current_user

app/models/transfer.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ class Transfer < ActiveRecord::Base
1919

2020
after_create :make_movements
2121

22-
# TODO: Extract it along with destination, source and amount accessors. It
23-
# absolutely violates encapsulation and adds high coupling.
24-
#
25-
# EDIT: It might not be that easy. The simple_form_for in give_time.html.erb
26-
# depends on this model having the destination column. A form object could be
27-
# a solution.
2822
def make_movements
2923
movements.create(account: Account.find(source_id), amount: -amount.to_i)
3024
movements.create(account: Account.find(destination_id), amount: amount.to_i)

app/services/give_time.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)