Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
UNRELEASED CHANGES:

* Remove partial contacts from search results returned by the API
* Fix reset account deleting default account values
* Fix notifications not working with aysnchronous queue
* Support mysql unix socket
Expand Down
3 changes: 0 additions & 3 deletions app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class Contact extends Model
'first_name',
'middle_name',
'last_name',
'food_preferencies',
'job',
'company',
];

// The list of columns we want the Searchable trait to select.
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function searchContacts($query, $limitPerPage, $order)
]);
})->paginate($limitPerPage);
} else {
$results = Contact::search($needle, $accountId, $limitPerPage, $order);
$results = Contact::search($needle, $accountId, $limitPerPage, $order, 'and is_partial=0');
}

return $results;
Expand Down
4 changes: 2 additions & 2 deletions app/Traits/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ trait Searchable
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function scopeSearch(Builder $builder, $needle, $accountId, $limitPerPage, $sortOrder)
public function scopeSearch(Builder $builder, $needle, $accountId, $limitPerPage, $sortOrder, $whereCondition = null)
{
if ($this->searchable_columns == null) {
return;
}

$queryString = StringHelper::buildQuery($this->searchable_columns, $needle);

$builder->whereRaw('account_id = '.$accountId.' and ('.$queryString.')');
$builder->whereRaw('account_id = '.$accountId.' and ('.$queryString.') '.$whereCondition);
$builder->orderByRaw($sortOrder);
$builder->select($this->return_from_search);

Expand Down
27 changes: 0 additions & 27 deletions tests/Unit/Traits/SearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,6 @@ public function testSearchContactsThroughLastNameAndResultContainsContact()
$this->assertTrue($searchResults->contains($contact));
}

/** @test */
public function testSearchContactsThroughFoodPreferencesAndResultContainsContact()
{
$contact = factory(\App\Contact::class)->create(['food_preferencies' => 'Food Preference']);
$searchResults = $contact->search($contact->food_preferencies, $contact->account_id, 10, 'created_at desc');

$this->assertTrue($searchResults->contains($contact));
}

/** @test */
public function testSearchContactsThroughJobAndResultContainsContact()
{
$contact = factory(\App\Contact::class)->create(['job' => 'Job']);
$searchResults = $contact->search($contact->job, $contact->account_id, 10, 'created_at desc');

$this->assertTrue($searchResults->contains($contact));
}

/** @test */
public function testSearchContactsThroughCompanyAndResultContainsContact()
{
$contact = factory(\App\Contact::class)->create(['company' => 'Company']);
$searchResults = $contact->search($contact->company, $contact->account_id, 10, 'created_at desc');

$this->assertTrue($searchResults->contains($contact));
}

/** @test */
public function testFailingSearchContacts()
{
Expand Down