mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 06:20:21 +00:00
no message
This commit is contained in:
1 parent
939ba47759
commit
f80e658e58
1 file changed
+27
-8
@@ -3,11 +3,11 @@
|
||||
namespace App\Services\Intranet;
|
||||
|
||||
use App\Models\Blocker;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class IntranetService {
|
||||
class IntranetService
|
||||
{
|
||||
private Api $api;
|
||||
|
||||
public function __construct()
|
||||
@@ -19,20 +19,26 @@ class IntranetService {
|
||||
{
|
||||
$intranetVacations = Vacation::fromDate(Carbon::yesterday()->toDateString());
|
||||
|
||||
$dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get();
|
||||
// toto sa pouziva pre delete starych dovoleniek. je to najstarsi datum, ktory mame v produkcnej DB. ak by sme ho tam nemali, API by nevratila stare dovolenky a povazovalo by sa to za vymazanu dovolenku a tym padom by sa to chybne odstranilo z nasej DB
|
||||
$intranetVacationsFromPast = Vacation::fromDate('2023-07-27');
|
||||
|
||||
$dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get();
|
||||
|
||||
$this->insertVacationsFromIntranet($intranetVacations, $dbVacations);
|
||||
|
||||
$this->checkIfVacationsGotAprroved($intranetVacations);
|
||||
|
||||
$this->deleteVacations($intranetVacationsFromPast, $dbVacations);
|
||||
}
|
||||
|
||||
private function insertVacationsFromIntranet( Collection $intranetVacations, Collection $dbVacations ) {
|
||||
$vacationsToSkip = $dbVacations->pluck('intranet_id' )->intersect( $intranetVacations->pluck('intranet_id'));
|
||||
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 = $item->toArray();
|
||||
|
||||
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
|
||||
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
|
||||
@@ -43,8 +49,10 @@ class IntranetService {
|
||||
Blocker::insert($intranetVacationsToInsert->toArray());
|
||||
}
|
||||
|
||||
private function checkIfVacationsGotAprroved( Collection $intranetVacations ) {
|
||||
$notApprovedDBVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->where('approved', false)->get();
|
||||
private function checkIfVacationsGotAprroved(Collection $intranetVacations)
|
||||
{
|
||||
$notApprovedDBVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->where('approved',
|
||||
false)->get();
|
||||
|
||||
// filter vacations from intranet with approved parameter to be true
|
||||
$approvedVacations = $intranetVacations->filter(function ($item) {
|
||||
@@ -63,4 +71,15 @@ class IntranetService {
|
||||
// mass update in DB
|
||||
Blocker::whereIn('intranet_id', $vacationsToApproveIds)->update(['approved' => true]);
|
||||
}
|
||||
|
||||
private function deleteVacations(Collection $intranetVacations, Collection $dbVacations)
|
||||
{
|
||||
$vacationsToDelete = $dbVacations->reject(function ($item) use ($intranetVacations) {
|
||||
return $intranetVacations->pluck('intranet_id')->contains($item->intranet_id);
|
||||
});
|
||||
|
||||
$vacationsToDeleteIds = $vacationsToDelete->pluck('id');
|
||||
|
||||
Blocker::destroy($vacationsToDeleteIds->toArray());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user