chore: Ability to create contact with identifiers (#2802)
This commit is contained in:
parent
d492a65c24
commit
acb39cbc8f
7 changed files with 53 additions and 11 deletions
|
@ -22,7 +22,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
|||
render json: { error: 'Specify search string with parameter q' }, status: :unprocessable_entity if params[:q].blank? && return
|
||||
|
||||
contacts = resolved_contacts.where(
|
||||
'name ILIKE :search OR email ILIKE :search OR phone_number ILIKE :search',
|
||||
'name ILIKE :search OR email ILIKE :search OR phone_number ILIKE :search OR contacts.identifier LIKE :search',
|
||||
search: "%#{params[:q]}%"
|
||||
)
|
||||
@contacts_count = contacts.count
|
||||
|
@ -108,7 +108,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
|||
end
|
||||
|
||||
def contact_params
|
||||
params.require(:contact).permit(:name, :email, :phone_number, additional_attributes: {}, custom_attributes: {})
|
||||
params.require(:contact).permit(:name, :identifier, :email, :phone_number, additional_attributes: {}, custom_attributes: {})
|
||||
end
|
||||
|
||||
def contact_custom_attributes
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module ExceptionList
|
||||
REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest,
|
||||
RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError,
|
||||
RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout, SocketError].freeze
|
||||
RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout,
|
||||
RestClient::MovedPermanently, SocketError].freeze
|
||||
SMTP_EXCEPTIONS = [
|
||||
Net::SMTPSyntaxError
|
||||
].freeze
|
||||
|
|
|
@ -188,6 +188,19 @@ RSpec.describe 'Contacts API', type: :request do
|
|||
expect(response.body).to include(contact2.email)
|
||||
expect(response.body).not_to include(contact1.email)
|
||||
end
|
||||
|
||||
it 'matches the contact respecting the identifier character casing' do
|
||||
contact_normal = create(:contact, name: 'testcontact', account: account, identifier: 'testidentifer')
|
||||
contact_special = create(:contact, name: 'testcontact', account: account, identifier: 'TestIdentifier')
|
||||
get "/api/v1/accounts/#{account.id}/contacts/search",
|
||||
params: { q: 'TestIdentifier' },
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(contact_special.identifier)
|
||||
expect(response.body).not_to include(contact_normal.identifier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -284,7 +297,7 @@ RSpec.describe 'Contacts API', type: :request do
|
|||
expect(json_response['payload']['contact']['custom_attributes']).to eq({ 'test' => 'test', 'test1' => 'test1' })
|
||||
end
|
||||
|
||||
it 'creates the contact identifier when inbox id is passed' do
|
||||
it 'creates the contact inbox when inbox id is passed' do
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/contacts", headers: admin.create_new_auth_token,
|
||||
params: valid_params.merge({ inbox_id: inbox.id })
|
||||
|
|
|
@ -5,7 +5,13 @@ properties:
|
|||
required: true
|
||||
name:
|
||||
type: string
|
||||
description: name of the contact
|
||||
email:
|
||||
type: string
|
||||
description: email of the contact
|
||||
phone_number:
|
||||
type: string
|
||||
description: phone number of the contact
|
||||
identifier:
|
||||
type: string
|
||||
description: A unique identifier for the contact in external system
|
||||
|
|
|
@ -2,7 +2,13 @@ type: object
|
|||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: name of the contact
|
||||
email:
|
||||
type: string
|
||||
description: email of the contact
|
||||
phone_number:
|
||||
type: string
|
||||
description: phone number of the contact
|
||||
identifier:
|
||||
type: string
|
||||
description: A unique identifier for the contact in external system
|
||||
|
|
|
@ -8,6 +8,7 @@ get:
|
|||
- name: q
|
||||
in: query
|
||||
type: string
|
||||
description: Search using contact `name`, `identifier`, `email` or `phone number`
|
||||
- $ref: '#/parameters/contact_sort_param'
|
||||
- $ref: '#/parameters/page'
|
||||
responses:
|
||||
|
|
|
@ -1281,7 +1281,8 @@
|
|||
{
|
||||
"name": "q",
|
||||
"in": "query",
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "Search using contact `name`, `identifier`, `email` or `phone number`"
|
||||
},
|
||||
{
|
||||
"$ref": "#/parameters/contact_sort_param"
|
||||
|
@ -3376,13 +3377,20 @@
|
|||
"required": true
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "name of the contact"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "email of the contact"
|
||||
},
|
||||
"phone_number": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "phone number of the contact"
|
||||
},
|
||||
"identifier": {
|
||||
"type": "string",
|
||||
"description": "A unique identifier for the contact in external system"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -3390,13 +3398,20 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "name of the contact"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "email of the contact"
|
||||
},
|
||||
"phone_number": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"description": "phone number of the contact"
|
||||
},
|
||||
"identifier": {
|
||||
"type": "string",
|
||||
"description": "A unique identifier for the contact in external system"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue