- Fix contact sync
This commit is contained in:
parent
e16b0d2c68
commit
16091035eb
2 changed files with 5 additions and 5 deletions
|
|
@ -7,7 +7,6 @@ use App\Mail\SendFlyerFailed;
|
|||
use App\Models\AppUsers;
|
||||
use App\Models\Contacts;
|
||||
use App\Models\Data;
|
||||
use Google\Type\Date;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
|
@ -24,7 +23,7 @@ class SyncController extends Controller
|
|||
|
||||
public function getContacts(Request $request) {
|
||||
$userId = $request->userId;
|
||||
$this->syncContacts(json_decode($request->contacts), $userId);
|
||||
$this->syncContacts($request->contacts, $userId);
|
||||
return new \App\Http\Resources\ContactsCollection(\App\Models\Contacts::where('user_id', $userId)->get());
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +120,7 @@ class SyncController extends Controller
|
|||
}
|
||||
|
||||
private function syncContacts($contacts, $userId) {
|
||||
$contacts = json_decode (json_encode ($contacts), FALSE);
|
||||
foreach ($contacts as $contact) {
|
||||
if ($contact->to_delete === true) {
|
||||
$tmp = Contacts::where([
|
||||
|
|
@ -154,7 +154,7 @@ class SyncController extends Controller
|
|||
$tmp->firstname = $contact->firstname;
|
||||
$tmp->company = $contact->company;
|
||||
$tmp->address = $contact->address;
|
||||
$tmp->phone = $contact->phone;
|
||||
$tmp->phone = empty($contact->phone) ? "" : $contact->phone;
|
||||
$tmp->products = $contact->products;
|
||||
$tmp->notes = $contact->notes;
|
||||
$tmp->visits = $contact->visits;
|
||||
|
|
@ -172,7 +172,7 @@ class SyncController extends Controller
|
|||
$tmp->firstname = $contact->firstname;
|
||||
$tmp->company = $contact->company;
|
||||
$tmp->address = $contact->address;
|
||||
$tmp->phone = $contact->phone;
|
||||
$tmp->phone = empty($contact->phone) ? "" : $contact->phone;
|
||||
$tmp->products = $contact->products;
|
||||
$tmp->notes = $contact->notes;
|
||||
$tmp->visits = $contact->visits;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use Illuminate\Http\Request;
|
|||
|
||||
Route::group(['middleware' => 'api.token'], function () {
|
||||
Route::get('users', 'API\SyncController@getUsers');
|
||||
Route::get('contacts', 'API\SyncController@getContacts');
|
||||
Route::post('contacts', 'API\SyncController@getContacts');
|
||||
Route::get('directories', 'API\SyncController@getDirectories');
|
||||
Route::get('documents', 'API\SyncController@getDocuments');
|
||||
Route::get('version', 'API\SyncController@getVersion');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue