1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Fixed ping route & added a way to find client by email address or if not exist - create a new

This commit is contained in:
Laurynas Sakalauskas 2016-01-22 10:33:38 +00:00
parent 360b59baa0
commit 0d2025c834
2 changed files with 16 additions and 3 deletions

View File

@ -82,8 +82,21 @@ class ClientApiController extends BaseAPIController
*/
public function store(CreateClientRequest $request)
{
$client = $this->clientRepo->save($request->input());
if ($request->has('filter_by_email')) {
$email = $request->get('filter_by_email');
$client = Client::whereHas('contacts', function ($query) use ($email) {
$query->where('email', $email);
})->with('contacts')->first();
if (is_null($client)) {
$client = $this->clientRepo->save($request->input());
}
} else {
$client = $this->clientRepo->save($request->input());
}
$client = Client::scope($client->public_id)
->with('country', 'contacts', 'industry', 'size', 'currency')
->first();

View File

@ -209,7 +209,7 @@ Route::group(['middleware' => 'auth'], function() {
// Route groups for API
Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
{
Route::resource('ping', 'ClientApiController@ping');
Route::get('ping', 'ClientApiController@ping');
Route::post('login', 'AccountApiController@login');
Route::get('static', 'AccountApiController@getStaticData');
Route::get('accounts', 'AccountApiController@show');