Class: ContactsController
Instance Method Summary
collapse
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#create ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'app/controllers/contacts_controller.rb', line 78
def create
@contact.assign_attributes(contact_params)
raise ActiveRecord::RecordInvalid.new(@contact) unless @contact.valid?
@contact = @contact.write_procedure(user_name: current_user.truncated_email)
render json: {
message: I18n.t('messages.contact_created'),
redirect_to: "/app/settings/company/contacts/#{@contact.contact_id}/"
}
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', '),
redirect_to: "/app/settings/company/contacts/#{e.record.company_id}/"
}, status: :bad_request
end
|
#destroy ⇒ Object
114
115
116
|
# File 'app/controllers/contacts_controller.rb', line 114
def destroy
render json: {}, status: :not_found
end
|
#index ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/contacts_controller.rb', line 13
def index
query = params[:query] || ''
order = params[:order] || 'desc'
order_by = params[:orderBy] || 'contact_id'
limit = params[:limit] || 100
offset = params[:offset] || 0
data, metadata = fetch_records(
records: @contacts,
order_by: order_by,
order: order,
query: query,
limit: limit,
offset: offset,
search_fields: %w[
first_name
last_name
full_name
email
phone_no
]
).values_at(:data, :metadata)
data = data.as_json(
methods: %i[
position_description
address
formatted_phone_no
formatted_cell_phone_no
space_separated_address
],
include: [
:erp_user
]
)
render json: {
data: data,
metadata: metadata
}
end
|
#show ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/contacts_controller.rb', line 55
def show
record = @contact.as_json(
include: %i[
province
erp_user
],
methods: %i[
position_type
language_option
address_line1
address_line2
]
)
record['position_type'] = record['position_type'].merge(
user_required: Contact.type_requires_user?(record['position_type']['type'])
)
render json: {
data: record
}
end
|
#update ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/controllers/contacts_controller.rb', line 96
def update
@contact.assign_attributes(contact_params)
raise ActiveRecord::RecordInvalid.new(@contact) unless @contact.valid?
@contact = @contact.write_procedure(user_name: current_user.truncated_email)
render json: {
message: I18n.t('messages.contact_updated'),
redirect_to: "/app/settings/company/contacts/#{@contact.contact_id}/"
}
rescue ActiveRecord::RecordInvalid => e
render json: {
errors: e.record.errors,
message: e.record.errors.full_messages.join(', '),
redirect_to: "/app/settings/company/contacts/#{e.record.contact_id}/"
}, status: :bad_request
end
|