mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 22:39:34 +00:00
no message
This commit is contained in:
1 parent
bb6528e5d1
commit
52fafc6aa9
4 files changed
+61
-2
No files matched your search
@@ -22,6 +22,8 @@ class IntranetService {
|
||||
$dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get();
|
||||
|
||||
$this->insertVacationsFromIntranet($intranetVacations, $dbVacations);
|
||||
|
||||
$this->checkIfVacationsGotAprroved($intranetVacations);
|
||||
}
|
||||
|
||||
private function insertVacationsFromIntranet( Collection $intranetVacations, Collection $dbVacations ) {
|
||||
@@ -40,4 +42,25 @@ class IntranetService {
|
||||
|
||||
Blocker::insert($intranetVacationsToInsert->toArray());
|
||||
}
|
||||
|
||||
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) {
|
||||
return $item->approved === true;
|
||||
});
|
||||
|
||||
$vacationsToApprove = $approvedVacations->filter(function ($item) use ($notApprovedDBVacations) {
|
||||
return $notApprovedDBVacations->contains('intranet_id', $item->intranet_id);
|
||||
});
|
||||
|
||||
// get intranet_id from vacations to approve and update them in db
|
||||
$vacationsToApproveIds = $vacationsToApprove->map(function ($item) {
|
||||
return $item->intranet_id;
|
||||
});
|
||||
|
||||
// mass update in DB
|
||||
Blocker::whereIn('intranet_id', $vacationsToApproveIds)->update(['approved' => true]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user