Fixes for Project Filters

This commit is contained in:
David Bomba 2022-01-11 09:31:08 +11:00
parent 9910e4f997
commit b9cb231773
4 changed files with 32 additions and 3 deletions

View File

@ -112,7 +112,8 @@ class PaymentTermFilters extends QueryFilters
*/
public function entityFilter()
{
return $this->builder->company();
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
// return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
}
}

View File

@ -107,7 +107,6 @@ class ProjectFilters extends QueryFilters
$query = DB::table('projects')
->join('companies', 'companies.id', '=', 'projects.company_id')
->where('projects.company_id', '=', $company_id)
//->whereRaw('(projects.name != "" or contacts.first_name != "" or contacts.last_name != "" or contacts.email != "")') // filter out buy now invoices
->select(
'projects.id',
'projects.name',
@ -140,6 +139,8 @@ class ProjectFilters extends QueryFilters
public function entityFilter()
{
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
// return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
return $this->builder->company();
}
}

View File

@ -88,6 +88,8 @@ abstract class QueryFilters
}
}
// nlog('[Search] SQL: ' . $this->builder->toSql() . " Bindings: " . implode(', ', $this->builder->getBindings()));
return $this->builder->withTrashed();
}

View File

@ -84,10 +84,35 @@ class ProjectApiTest extends TestCase
$response->assertStatus(302);
}
}
public function testProjectPostFilters()
{
$data = [
'name' => "Sherlock",
'client_id' => $this->client->hashed_id,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/projects', $data);
$response->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/projects?filter=Sherlock');
$arr = $response->json();
$this->assertEquals(1, count($arr['data']));
}
public function testProjectPut()
{
$data = [