Class: CommunicartsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/communicarts_controller.rb

Instance Method Summary collapse

Instance Method Details

#approval_reply_receivedObject


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/communicarts_controller.rb', line 26

def approval_reply_received
  cart = Cart.where(external_id: params['cartNumber'].to_i).where(status: 'pending').first
  user = cart.approval_users.where(email_address: params['fromAddress']).first
  approval = cart.approvals.where(user_id: user.id).first
  new_status = approval_reply_received_status

  if params['comment']
    cart.comments.create(user_id: user.id, comment_text: params['comment'].strip)
  end

  Commands::Approval::UpdateFromApprovalResponse.new.perform(approval, new_status)
  render json: { message: "approval_reply_received"}, status: 200
end

#approval_responseObject


40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/communicarts_controller.rb', line 40

def approval_response
  @cart = Cart.find(params[:cart_id]).decorate
  @approval = @cart.approvals.find_by(user_id: params[:user_id])
  @show_comments = true

  Commands::Approval::UpdateFromApprovalResponse.new.perform(@approval, approval_response_status)
  @token.update_attributes(used_at: Time.now)

  flash[:success] = "You have #{approval_response_status} Cart #{@cart.public_identifier}."
end

#send_cartObject


15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/communicarts_controller.rb', line 15

def send_cart

  cart = Commands::Approval::InitiateCartApproval.new.perform(params)
  jcart = cart.as_json(include: {cart_items:
                                     {
                                         include: :cart_item_traits
                                     }
  })
  render json: jcart, status: 201
end