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
04c42c2762
commit
d69fcf328b
8 files changed
+286
-2
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Intranet;
|
||||
|
||||
use App\Models\Blocker;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class IntranetService {
|
||||
private Api $api;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->api = new Api();
|
||||
}
|
||||
|
||||
public function syncVacations()
|
||||
{
|
||||
$intranetVacations = Vacation::fromDate(Carbon::yesterday()->toDateString());
|
||||
|
||||
$dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get();
|
||||
|
||||
$this->insertVacationsFromIntranet($intranetVacations, $dbVacations);
|
||||
}
|
||||
|
||||
private function insertVacationsFromIntranet( Collection $intranetVacations, Collection $dbVacations ) {
|
||||
$vacationsToSkip = $dbVacations->pluck('intranet_id' )->intersect( $intranetVacations->pluck('intranet_id'));
|
||||
|
||||
$intranetVacationsToInsert = $intranetVacations->reject(function ($item) use ($vacationsToSkip) {
|
||||
return $vacationsToSkip->contains($item->intranet_id);
|
||||
})->map(function ($item) {
|
||||
$arrayToInsert = $item->toArray();
|
||||
|
||||
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
|
||||
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
|
||||
|
||||
return $arrayToInsert;
|
||||
});
|
||||
|
||||
Blocker::insert($intranetVacationsToInsert->toArray());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user