feat(employee) : expose contractPhases on read API
This commit is contained in:
@@ -6,9 +6,11 @@ namespace App\Entity;
|
|||||||
|
|
||||||
use ApiPlatform\Metadata\ApiProperty;
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use App\Dto\Contracts\ContractPhase;
|
||||||
use App\Dto\Employees\ContractHistoryItem;
|
use App\Dto\Employees\ContractHistoryItem;
|
||||||
use App\Enum\ContractNature;
|
use App\Enum\ContractNature;
|
||||||
use App\Repository\EmployeeRepository;
|
use App\Repository\EmployeeRepository;
|
||||||
|
use App\Service\Contracts\EmployeeContractPhaseResolver;
|
||||||
use App\State\EmployeeWriteProcessor;
|
use App\State\EmployeeWriteProcessor;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@@ -428,6 +430,38 @@ class Employee
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{
|
||||||
|
* id: int,
|
||||||
|
* contractType: string,
|
||||||
|
* weeklyHours: ?int,
|
||||||
|
* isDriver: bool,
|
||||||
|
* startDate: string,
|
||||||
|
* endDate: ?string,
|
||||||
|
* periodIds: list<int>,
|
||||||
|
* isCurrent: bool
|
||||||
|
* }>
|
||||||
|
*/
|
||||||
|
#[Groups(['employee:read'])]
|
||||||
|
public function getContractPhases(): array
|
||||||
|
{
|
||||||
|
$resolver = new EmployeeContractPhaseResolver();
|
||||||
|
|
||||||
|
return array_map(
|
||||||
|
static fn (ContractPhase $phase): array => [
|
||||||
|
'id' => $phase->id,
|
||||||
|
'contractType' => $phase->contractType->value,
|
||||||
|
'weeklyHours' => $phase->weeklyHours,
|
||||||
|
'isDriver' => $phase->isDriver,
|
||||||
|
'startDate' => $phase->startDate->format('Y-m-d'),
|
||||||
|
'endDate' => $phase->endDate?->format('Y-m-d'),
|
||||||
|
'periodIds' => $phase->periodIds,
|
||||||
|
'isCurrent' => $phase->isCurrent,
|
||||||
|
],
|
||||||
|
$resolver->resolvePhases($this),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function resolveCurrentContractPeriod(): ?EmployeeContractPeriod
|
private function resolveCurrentContractPeriod(): ?EmployeeContractPeriod
|
||||||
{
|
{
|
||||||
$today = new DateTimeImmutable('today');
|
$today = new DateTimeImmutable('today');
|
||||||
|
|||||||
Reference in New Issue
Block a user