Class: Cats::Core::StoresController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/cats/core/stores_controller.rb

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

Methods inherited from ApplicationController

#authenticate, #current_user, #skip_bullet

Instance Method Details

#assign_storeObject



23
24
25
26
27
28
29
30
# File 'app/controllers/cats/core/stores_controller.rb', line 23

def assign_store
  store_keeper = User.find(params[:id])
  store_keeper.details["stores"] ||= []
  store_keeper.details["stores"] += store_params[:store_ids]
  store_keeper.save!

  render json: {success: true, data: serialize(store_keeper)}
end

#fdpObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/cats/core/stores_controller.rb', line 43

def fdp
  store = Store.find(params[:id])
  location = store.warehouse.parent
  if location.location_type == Location::FDP
    render json: {success: true, data: serialize(location)}
  else
    render json: {success: false, error: "No FDP is associated with store."}
  end
end

#filterObject



11
12
13
14
# File 'app/controllers/cats/core/stores_controller.rb', line 11

def filter
  query = Store.includes(:stacks).ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end

#indexObject



6
7
8
9
# File 'app/controllers/cats/core/stores_controller.rb', line 6

def index
  stores = Store.includes(:stacks).where(warehouse_id: params[:id])
  render json: {success: true, data: serialize(stores)}
end

#stores_for_hubObject



16
17
18
19
20
21
# File 'app/controllers/cats/core/stores_controller.rb', line 16

def stores_for_hub
  warehouses = Location.find(params[:id]).children
  ids = warehouses.map(&:id)
  stores = Store.includes(:stacks).where(warehouse_id: ids)
  render json: {success: true, data: serialize(stores)}
end

#unassign_storeObject



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/cats/core/stores_controller.rb', line 32

def unassign_store
  store_keeper = User.find(params[:id])
  if store_keeper.details.key?("stores")
    store_keeper.details["stores"] -= store_params[:store_ids]
    store_keeper.save!
    render json: {success: true, data: serialize(store_keeper)}
  else
    render json: {success: false, error: "User has no stores assigned."}
  end
end