feat(appointment): derive service section from service item when missing in appointment

This commit is contained in:
hamed
2026-08-08 07:14:40 +03:30
parent da07e3ad9c
commit b699476305
5 changed files with 144 additions and 22 deletions
@@ -704,7 +704,27 @@ class AppointmentController extends BaseController
return $this->error(ErrorCodes::ERR_ACCESS_DENIED, 'دسترسی ممنوع', 403);
}
return $this->success(['data' => $appointment->toArray()]);
$payload = $appointment->toArray();
/**
* نوبتِ سرویسیِ کلینیک `service_section_id` را روی خودِ نوبت نمی‌نویسد؛ فقط
* سرویس را نگه می‌دارد. ولی فرم ویرایش فهرستِ سرویس‌ها را از **بخش**
* می‌گیرد، پس بخشِ خالی یعنی فهرست سرویس هم خالی می‌ماند و سرویسِ
* ذخیره‌شده — با اینکه مقدارش درست است — بی‌برچسب و انگار انتخاب‌نشده
* دیده می‌شود.
*
* بخش از خودِ سرویس درمی‌آید و حدس نیست: `service_items.section_id` ستونِ
* NOT NULL است، پس هر سرویسی دقیقاً یک بخش دارد.
*
* عمداً اینجاست و نه در `Appointment::toArray()`: آنجا فهرستِ نوبت‌ها هم
* از همین متد می‌خواند و نباید ناگهان بخشی نشان دهد که تا امروز نداشت.
*/
if ($payload['service_section'] === null && ($item = $appointment->getServiceItem()) !== null) {
$section = $item->getSection();
$payload['service_section'] = ['uuid' => $section->getUuid(), 'name' => $section->getName()];
}
return $this->success(['data' => $payload]);
}
#[OA\Get(