Skip to content

Commit

Permalink
refactor: UserLoansController#create and #update
Browse files Browse the repository at this point in the history
  • Loading branch information
MelTravelz committed Oct 29, 2023
1 parent 683d415 commit 09883a5
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions app/controllers/api/v1/users/loans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,8 @@ def create
end

def update
# loan = Loan.find(params[:loan_id])

if params[:action_type] == 'accept'
@loan.update(status: 1)
@loan.puzzle.update(status: 2)
render json: LoanSerializer.new(@loan), status: 200
elsif params[:action_type] == 'withdraw'
@loan.update(status: 2)
@loan.puzzle.update(status: 0)
render json: LoanSerializer.new(@loan), status: 200
elsif params[:action_type] == 'deny'
@loan.update(status: 2)
@loan.puzzle.update(status: 2)
render json: LoanSerializer.new(@loan), status: 200
elsif params[:action_type] == 'close'
@loan.update(status: 3)
@loan.puzzle.update(status: 0)
render json: LoanSerializer.new(@loan), status: 200
else
render json: { error: "Unable to update loan status" }, status: 422
end
updated_loan = @loan.update_status_and_puzzle_status(params[:action_type])
render json: LoanSerializer.new(updated_loan), status: 200
end

private
Expand Down

0 comments on commit 09883a5

Please sign in to comment.