no message

This commit is contained in:
StudioTem committed 2023-12-12 15:24:10 +01:00
1 parent bb6528e5d1
commit 52fafc6aa9
4 files changed
+61 -2

No files matched your search

@@ -22,6 +22,7 @@ class BlockerResource extends JsonResource
'end' => $this->end, 'end' => $this->end,
'type' => $this->type, 'type' => $this->type,
'color' => $this->color, 'color' => $this->color,
'approved' => $this->approved,
]; ];
} }
} }
@@ -22,6 +22,8 @@ class IntranetService {
$dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get(); $dbVacations = Blocker::whereIn('type', ['vacation', 'home_office', 'free_day'])->get();
$this->insertVacationsFromIntranet($intranetVacations, $dbVacations); $this->insertVacationsFromIntranet($intranetVacations, $dbVacations);
$this->checkIfVacationsGotAprroved($intranetVacations);
} }
private function insertVacationsFromIntranet( Collection $intranetVacations, Collection $dbVacations ) { private function insertVacationsFromIntranet( Collection $intranetVacations, Collection $dbVacations ) {
@@ -40,4 +42,25 @@ class IntranetService {
Blocker::insert($intranetVacationsToInsert->toArray()); 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]);
}
} }
+5 -2
View File
@@ -13,8 +13,9 @@ class Vacation extends Api {
public $end_date; public $end_date;
public $type; public $type;
public $name; public $name;
public $approved;
public function __construct($intranet_id, $ldap_username, $start_date, $end_date, $type, $halfday) { public function __construct($intranet_id, $ldap_username, $start_date, $end_date, $type, $halfday, $approved) {
$startend = $this->getStartEndDate($start_date, $end_date, $halfday, $ldap_username); $startend = $this->getStartEndDate($start_date, $end_date, $halfday, $ldap_username);
$this->intranet_id = $intranet_id; $this->intranet_id = $intranet_id;
@@ -23,13 +24,14 @@ class Vacation extends Api {
$this->end_date = (isset($startend['end'])) ? $startend['end'] : null; $this->end_date = (isset($startend['end'])) ? $startend['end'] : null;
$this->type = $type; $this->type = $type;
$this->name = $this->getVacationName($type); $this->name = $this->getVacationName($type);
$this->approved = $approved;
} }
public static function fromDate($date) { public static function fromDate($date) {
$vacations = self::getVacations($date); $vacations = self::getVacations($date);
return collect(array_map(function($vacation) { return collect(array_map(function($vacation) {
return new Vacation( $vacation['id'], $vacation['user']['ldap_username'], $vacation['start_date'], $vacation['end_date'], $vacation['vacation_type']['name'], $vacation['halfday_position']); return new Vacation( $vacation['id'], $vacation['user']['ldap_username'], $vacation['start_date'], $vacation['end_date'], $vacation['vacation_type']['name'], $vacation['halfday_position'], $vacation['approved']);
}, $vacations))->reject(function($vacation) { }, $vacations))->reject(function($vacation) {
return $vacation->user_id === null; return $vacation->user_id === null;
}); });
@@ -43,6 +45,7 @@ class Vacation extends Api {
'end' => date('Y-m-d H:i:s', strtotime($this->end_date)), 'end' => date('Y-m-d H:i:s', strtotime($this->end_date)),
'type' => $this->type, 'type' => $this->type,
'name' => $this->name, 'name' => $this->name,
'approved' => $this->approved,
]; ];
} }
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('blockers', function (Blueprint $table) {
$table->boolean('approved')->after('end')->nullable()->default(NULL);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('blockers', function (Blueprint $table) {
//
});
}
};