mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 16:31:33 +02:00
MErge clients
This commit is contained in:
parent
d0759b1215
commit
90de7b9f96
@ -656,4 +656,84 @@ class ClientController extends BaseController
|
|||||||
//todo add an event here using the client name as reference for purge event
|
//todo add an event here using the client name as reference for purge event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param PurgeClientRequest $request
|
||||||
|
* @param Client $client
|
||||||
|
* @param string $mergeable client hashed_id
|
||||||
|
* @return Response
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/clients/{id}/{mergaeble_client_hashed_id}/merge",
|
||||||
|
* operationId="mergeClient",
|
||||||
|
* tags={"clients"},
|
||||||
|
* summary="Merges two clients",
|
||||||
|
* description="Handles merging 2 clients",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="id",
|
||||||
|
* in="path",
|
||||||
|
* description="The Client Hashed ID",
|
||||||
|
* example="D2J234DFA",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* format="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="mergeable_client_hashedid",
|
||||||
|
* in="path",
|
||||||
|
* description="The Mergeable Client Hashed ID",
|
||||||
|
* example="D2J234DFA",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* format="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Returns the client object",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit")
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function merge(PurgeClientRequest $request, Client $client, string $mergeable_client)
|
||||||
|
{
|
||||||
|
|
||||||
|
$m_client = Client::withTrashed()
|
||||||
|
->where('id', $this->decodePrimaryKey($mergeable_client))
|
||||||
|
->where('company_id', auth()->user()->company()->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if(!$m_client)
|
||||||
|
return response()->json(['message' => "Client not found"]);
|
||||||
|
|
||||||
|
$merged_client = $client->service()->merge($m_client)->save();
|
||||||
|
|
||||||
|
return $this->itemResponse($merged_client);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ Route::group(['middleware' => ['throttle:100,1', 'api_db', 'token_auth', 'locale
|
|||||||
Route::put('clients/{client}/adjust_ledger', 'ClientController@adjustLedger')->name('clients.adjust_ledger');
|
Route::put('clients/{client}/adjust_ledger', 'ClientController@adjustLedger')->name('clients.adjust_ledger');
|
||||||
Route::put('clients/{client}/upload', 'ClientController@upload')->name('clients.upload');
|
Route::put('clients/{client}/upload', 'ClientController@upload')->name('clients.upload');
|
||||||
Route::post('clients/{client}/purge', 'ClientController@purge')->name('clients.purge')->middleware('password_protected');
|
Route::post('clients/{client}/purge', 'ClientController@purge')->name('clients.purge')->middleware('password_protected');
|
||||||
|
Route::post('clients/{client}/{mergeable_client}/merge', 'ClientController@merge')->name('clients.merge')->middleware('password_protected');
|
||||||
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
||||||
|
|
||||||
Route::post('filters/{entity}', 'FilterController@index')->name('filters');
|
Route::post('filters/{entity}', 'FilterController@index')->name('filters');
|
||||||
|
Loading…
Reference in New Issue
Block a user