1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Checks for same client prior to attempted merge

This commit is contained in:
David Bomba 2024-03-22 19:57:26 +11:00
parent 2dd1dd6da6
commit 0e5aa5e26e
3 changed files with 22 additions and 13 deletions

View File

@ -328,9 +328,12 @@ class ClientController extends BaseController
->first();
if (!$m_client) {
return response()->json(['message' => "Client not found"]);
return response()->json(['message' => "Client not found"], 400);
}
if($m_client->id == $client->id)
return response()->json(['message' => "Attempting to merge the same client is not possible."], 400);
$merged_client = $client->service()->merge($m_client)->save();
return $this->itemResponse($merged_client);

View File

@ -77,9 +77,6 @@ class ProjectTransformer extends EntityTransformer
{
$transformer = new InvoiceTransformer($this->serializer);
if(!$project->invoices)
return null;
return $this->includeCollection($project->invoices, $transformer, Invoice::class);
}
@ -87,10 +84,6 @@ class ProjectTransformer extends EntityTransformer
{
$transformer = new ExpenseTransformer($this->serializer);
if(!$project->expenses) {
return null;
}
return $this->includeCollection($project->expenses, $transformer, Expense::class);
}
@ -98,14 +91,9 @@ class ProjectTransformer extends EntityTransformer
{
$transformer = new QuoteTransformer($this->serializer);
if(!$project->quotes) {
return null;
}
return $this->includeCollection($project->quotes, $transformer, Quote::class);
}
public function transform(Project $project)
{
return [

View File

@ -47,6 +47,24 @@ class ProjectApiTest extends TestCase
Model::reguard();
}
public function testProjectIncludesZeroCount()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson("/api/v1/projects/{$this->project->hashed_id}?include=expenses,invoices,quotes");
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals(0, count($arr['data']['invoices']));
$this->assertEquals(0, count($arr['data']['expenses']));
$this->assertEquals(0, count($arr['data']['quotes']));
}
public function testProjectIncludes()
{
$i = Invoice::factory()->create([