32 lines
843 B
PHP
32 lines
843 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Dto\OrderDto;
|
|
use App\Models\Customer;
|
|
use App\Models\Order;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
|
|
class OrderService
|
|
{
|
|
public function isOrderOwnedBy(Order | OrderDto $order, Customer $customer): bool
|
|
{
|
|
/** @var \Domain\Models\ValueObjects\Matricule|string|null $employeeMatricule */
|
|
$employeeMatricule = $customer->employee()->value('matricule');
|
|
|
|
if ($employeeMatricule === null) {
|
|
return false;
|
|
}
|
|
|
|
$matriculeValue = $employeeMatricule instanceof Matricule
|
|
? $employeeMatricule->value
|
|
: (string) $employeeMatricule;
|
|
|
|
return Order::query()
|
|
->where('id', (string) $order->id)
|
|
->where('employee_matricule', $matriculeValue)
|
|
->exists();
|
|
}
|
|
}
|