feat(resource): every resource is supervised by a doctor
Supervision now lives on the resource itself instead of being asked for again at booking time, so one relation answers it everywhere. The column is deliberately separate from the existing doctor_id bridge. That bridge means "this resource IS this doctor" and isPerson() uses it to pin capacity at 1; a supervised three-seat device must not become a person resource. The FK is SET NULL rather than CASCADE because deleting a doctor should not take the clinic's laser with it. Required on create and non-clearable on update, enforced in the API where it can give a Persian message. Ownership is checked through Clinic::hasDoctor so a secretary cannot put their device under a doctor of another clinic; that returns 404, not 403, keeping foreign data invisible. The 13 existing resources are backfilled deterministically: a practice resource gets its own doctor, a clinic resource gets that clinic's first doctor. Both are editable from the resource form. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Resource\Service;
|
||||
|
||||
use App\Doctor\Entity\Doctor;
|
||||
use App\Doctor\Entity\DoctorAddress;
|
||||
use App\Resource\Entity\ClinicResource;
|
||||
use App\Resource\Entity\ResourceType;
|
||||
@@ -57,9 +58,10 @@ final class ResourceService
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $data */
|
||||
public function create(DoctorAddress $address, ResourceType $type, array $data): ClinicResource
|
||||
public function create(DoctorAddress $address, ResourceType $type, array $data, Doctor $supervisor): ClinicResource
|
||||
{
|
||||
$resource = new ClinicResource($address, $type, $this->assertName($data['name'] ?? null));
|
||||
$resource->setSupervisor($supervisor);
|
||||
$this->applyOptional($resource, $data);
|
||||
|
||||
$this->em->persist($resource);
|
||||
|
||||
Reference in New Issue
Block a user