feat: enhance doctor address management by including clinic addresses and enforcing required fields
This commit is contained in:
@@ -676,9 +676,19 @@ class DoctorController extends BaseController
|
||||
return $this->error(ErrorCodes::ERR_VALIDATION_002, 'دکتر یافت نشد', 404);
|
||||
}
|
||||
|
||||
$addresses = array_map(fn(DoctorAddress $a) => $a->toArray(), $doctor->getAddresses()->toArray());
|
||||
$personalAddresses = array_map(
|
||||
fn(DoctorAddress $a) => $a->toArray(),
|
||||
$doctor->getAddresses()->toArray()
|
||||
);
|
||||
|
||||
return $this->success(['data' => $addresses]);
|
||||
$clinicAddresses = [];
|
||||
foreach ($this->clinicRepo->findByDoctor($doctor) as $clinic) {
|
||||
foreach ($this->addressRepo->findBy(['clinicId' => $clinic->getId()]) as $addr) {
|
||||
$clinicAddresses[] = $addr->toArray($clinic->getName());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success(['data' => array_merge($personalAddresses, $clinicAddresses)]);
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -109,14 +109,15 @@ class DoctorAddress
|
||||
|
||||
private function touch(): void { $this->updatedAt = time(); }
|
||||
|
||||
public function toArray(): array
|
||||
public function toArray(?string $clinicName = null): array
|
||||
{
|
||||
return [
|
||||
'id' => (string) $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'type' => $this->type,
|
||||
'clinic_id' => $this->clinicId,
|
||||
'name' => $this->name,
|
||||
'id' => (string) $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'type' => $this->type,
|
||||
'clinic_id' => $this->clinicId,
|
||||
'clinic_name' => $clinicName,
|
||||
'name' => $this->name,
|
||||
'map' => [
|
||||
'latitude' => $this->latitude !== null ? (string) $this->latitude : null,
|
||||
'longitude' => $this->longitude !== null ? (string) $this->longitude : null,
|
||||
|
||||
Reference in New Issue
Block a user