mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
no message
This commit is contained in:
1 parent
7320e82212
commit
8c79f045fc
6 files changed
+197
-2
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Services\Karat;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -32,9 +33,12 @@ class KaratService
|
||||
$karatUsersToInsert = $karatUsers->reject(function ($item) use ($emailsToSkip) {
|
||||
return $emailsToSkip->contains($item->email);
|
||||
})->map(function ($item) {
|
||||
$array = $item->toArray();
|
||||
$arrayToInsert = $item->toArray();
|
||||
|
||||
return $array;
|
||||
$arrayToInsert['created_at'] = Carbon::now();
|
||||
$arrayToInsert['updated_at'] = Carbon::now();
|
||||
|
||||
return $arrayToInsert;
|
||||
});
|
||||
|
||||
User::insert($karatUsersToInsert->toArray());
|
||||
@@ -48,5 +52,49 @@ class KaratService
|
||||
|
||||
}
|
||||
|
||||
public function syncClients()
|
||||
{
|
||||
$karatClients = Client::all();
|
||||
$dbClients = \App\Models\Client::all();
|
||||
|
||||
$this->insertClientsFromKarat($karatClients, $dbClients);
|
||||
|
||||
$this->removeClientsThatAreNotInKaratAnymore($karatClients, $dbClients);
|
||||
}
|
||||
|
||||
private function insertClientsFromKarat( Collection $karatClients, Collection $dbClients )
|
||||
{
|
||||
$clientsToSkip = $dbClients->pluck('code' )->intersect( $karatClients->pluck('code'));
|
||||
|
||||
$karatClientsToInsert = $karatClients->reject(function ($item) use ($clientsToSkip) {
|
||||
return $clientsToSkip->contains($item->code);
|
||||
})->map(function ($item) {
|
||||
$arrayToInsert = $item->toArray();
|
||||
|
||||
$arrayToInsert['created_at'] = Carbon::now();
|
||||
$arrayToInsert['updated_at'] = Carbon::now();
|
||||
|
||||
return $arrayToInsert;
|
||||
});
|
||||
|
||||
\App\Models\Client::insert($karatClientsToInsert->toArray());
|
||||
}
|
||||
|
||||
private function removeClientsThatAreNotInKaratAnymore( Collection $karatClients, Collection $dbClients )
|
||||
{
|
||||
dd('finish me');
|
||||
}
|
||||
|
||||
public function syncProjects()
|
||||
{
|
||||
$karatProjects = Project::all();
|
||||
$dbProjects = \App\Models\Project::all();
|
||||
|
||||
$this->insertProjectsFromKarat($karatProjects, $dbProjects);
|
||||
|
||||
$this->removeProjectsThatAreNotInKaratAnymore($karatProjects, $dbProjects);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user