Class: Comee::Core::ClientsController
Instance Method Summary
collapse
Methods included from Common
#create, #show, #update
Methods included from Pagination
#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page
#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet
Instance Method Details
#agents ⇒ Object
52
53
54
55
56
57
|
# File 'app/controllers/comee/core/clients_controller.rb', line 52
def agents
client = Client.find(params[:id])
render_content(client.agents)
rescue StandardError => e
render json: {success: false, error: e.message}, status: 422
end
|
#consignees ⇒ Object
21
22
23
24
25
26
|
# File 'app/controllers/comee/core/clients_controller.rb', line 21
def consignees
client = Client.find(params[:id])
render json: {success: true, data: client.consignees}
rescue StandardError => e
render json: {success: false, error: e.message}, status: 422
end
|
#create_agent ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/comee/core/clients_controller.rb', line 28
def create_agent
client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
agent = Agent.new(agent_params)
if agent.save
client.agents << agent
client.save!
render_content(client)
else
render json: {success: false, error: agent.errors.full_messages[0]}, status: 422
end
end
|
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/comee/core/clients_controller.rb', line 40
def create_contact
client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
contact = Contact.new(contact_params)
if contact.save
client.contacts << contact
client.save!
render_content(client)
else
render json: {success: false, error: contact.errors.full_messages[0]}, status: 422
end
end
|
#filter ⇒ Object
14
15
16
17
18
19
|
# File 'app/controllers/comee/core/clients_controller.rb', line 14
def filter
clients = Client.includes(
:parent, :agents, :contacts, :client_warehouses, :client_addresses, :country, :user, :currency
).ransack(params[:q]).result
render_content(clients)
end
|
#index ⇒ Object
6
7
8
9
10
11
12
|
# File 'app/controllers/comee/core/clients_controller.rb', line 6
def index
super do
Client.includes(
:parent, :agents, :contacts, :client_warehouses, :client_addresses, :country, :user, :currency
).all
end
end
|