Class: Cats::Core::StoresController
Instance Method Summary
collapse
Methods included from Common
#create, #show, #update
#authenticate, #current_user, #skip_bullet
Instance Method Details
#assign_store ⇒ Object
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
|
#fdp ⇒ Object
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
|
#filter ⇒ Object
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
|
#index ⇒ Object
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_hub ⇒ Object
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_store ⇒ Object
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
|