Class: Cats::Core::DispatchTransactionsController
- Inherits:
 - 
      ApplicationController
      
        
- Object
 - ActionController::API
 - ApplicationController
 - Cats::Core::DispatchTransactionsController
 
 
- Includes:
 - Common
 
- Defined in:
 - app/controllers/cats/core/dispatch_transactions_controller.rb
 
Instance Method Summary collapse
- 
  
    
      #create_allocation  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
This end-point is used to create upstream dispatch transactions.
 - #filter ⇒ Object
 - #index ⇒ Object
 
Methods included from Common
Methods inherited from ApplicationController
#authenticate, #current_user, #skip_bullet
Instance Method Details
#create_allocation ⇒ Object
This end-point is used to create upstream dispatch transactions. We need a specific method like this because for upstream the source stack is a dummy one and we need to use that without waiting for the user to give us a source.
      16 17 18 19 20 21 22 23 24 25 26 27 28 29 30  | 
    
      # File 'app/controllers/cats/core/dispatch_transactions_controller.rb', line 16 def create_allocation = DispatchAuthorization.find(model_params[:dispatch_authorization_id]) commodity = .dispatch.dispatch_plan_item.commodity transaction = DispatchTransaction.new(model_params) # Fetch supplier stack by commodity stack = Stack.joins(:store).find_by(commodity: commodity, store: {code: "SUP-STORE"}) transaction.source = stack if transaction.save render json: {success: true, data: serialize(transaction)}, status: :created else render json: {success: false, error: transaction.errors.[0]}, status: :unprocessable_entity end end  | 
  
#filter ⇒ Object
      32 33 34 35  | 
    
      # File 'app/controllers/cats/core/dispatch_transactions_controller.rb', line 32 def filter query = DispatchTransaction.ransack(params[:q]) render json: {success: true, data: serialize(query.result)} end  | 
  
#index ⇒ Object
      6 7 8 9 10  | 
    
      # File 'app/controllers/cats/core/dispatch_transactions_controller.rb', line 6 def index super do DispatchTransaction.includes(:source, :unit).where(dispatch_authorization_id: params[:id]) end end  |