Class: Cats::Core::DispatchAuthorizationsController
Instance Method Summary
collapse
Methods included from Common
#show, #update
#authenticate, #current_user, #skip_bullet
Instance Method Details
#confirm ⇒ Object
24
25
26
27
28
29
30
|
# File 'app/controllers/cats/core/dispatch_authorizations_controller.rb', line 24
def confirm
authorization = DispatchAuthorization.find(params[:id])
authorization = authorization.confirm
render json: {success: true, data: serialize(authorization)}
rescue StandardError => e
render json: {success: false, error: e.message}
end
|
#create ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'app/controllers/cats/core/dispatch_authorizations_controller.rb', line 14
def create
authorization = DispatchAuthorization.new(model_params)
if authorization.save
AuthorizationService.new.send_dispatch_notification(authorization)
render json: {success: true, data: serialize(authorization)}, status: :created
else
render json: {success: false, error: authorization.errors.full_messages[0]}, status: :unprocessable_entity
end
end
|
#filter ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/cats/core/dispatch_authorizations_controller.rb', line 42
def filter
query = DispatchAuthorization.includes(
:dispatch,
:store,
:authorized_by,
:unit
).ransack(params[:q])
render json: {success: true, data: serialize(query.result.reverse_order)}
end
|
#index ⇒ Object
6
7
8
9
10
11
12
|
# File 'app/controllers/cats/core/dispatch_authorizations_controller.rb', line 6
def index
super do
DispatchAuthorization.includes(:dispatch, :store, :authorized_by, :unit).where(
dispatch_id: params[:id]
).reverse_order
end
end
|
#storekeeper_authorizations ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/cats/core/dispatch_authorizations_controller.rb', line 32
def storekeeper_authorizations
storekeeper = User.find(params[:id])
stores = storekeeper.stores
authorizations = DispatchAuthorization.joins(:dispatch)
.includes(:dispatch, :store, :authorized_by, :unit)
.where(store: stores, dispatch: {dispatch_status: Dispatch::APPROVED})
.reverse_order
render json: {success: true, data: serialize(authorizations)}
end
|