fix(booking): report the real time range for service-mode slots

adaptServiceSlots labelled its single session "زمان‌های خالی" and set end_time to
the last slot's *start* time, so the range shown was shorter than reality. It now
uses the last slot's end_time (falling back to start + total_duration_minutes) and
labels the session with the actual range.

Shift separation was requested but is not implementable from this payload: with a
flat start_times list, a gap between shifts is indistinguishable from a gap left
by a booked appointment. The normal step is duration + buffer, so any threshold
that splits shifts either splits every slot of a long service (step above the
threshold) or invents tabs around booked appointments. A fabricated tab claims a
shift that does not exist, which is worse than one correct tab. Real grouping
belongs to the server-side endpoint task 06 adds.

Also repairs three tests that had been red since adaptSlots changed shape: they
still asserted the old { morning, evening } contract while the function returns an
array of sessions. Suite goes from 4 failures to 1 (an unrelated pre-existing
getStateInfo network timeout).

Task: clinicpro/docs/new_feture/taskes/task-00b-nobat724-service-mode/
Slot-mode contract: adaptSlots untouched

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-30 15:50:22 +03:30
co-authored by Claude Opus 5
parent f3659f827e
commit d58eec1dba
2 changed files with 126 additions and 23 deletions
+35 -7
View File
@@ -14,22 +14,50 @@ export function adaptSlots(slotsResponse) {
}));
}
// حالت سرویسی: پاسخ appointment-service-slots فقط start_times دارد (همه کافی).
// آن‌ها را در یک session قالب‌بندی می‌کنیم تا مثل حالت اسلاتی رندر شوند.
/**
* حالت سرویسی: پاسخ `appointment-service-slots` فقط `start_times` مسطح می‌دهد و مرزِ
* شیفت‌ها را نمی‌گوید. یک session ساخته می‌شود تا مثل حالت اسلاتی رندر شود.
*
* ⚠️ **چرا شیفت‌ها تفکیک نمی‌شوند:** با فهرست مسطح، شکافِ بین دو شیفت از شکافِ یک نوبتِ
* اشغال‌شده قابل تفکیک نیست. گام عادی `مدت + بافر` است، و دو نوبت پشت‌سرهم شکافی
* می‌سازد که از تعطیلیِ میانِ صبح و عصر تشخیص‌پذیر نیست. هر آستانه‌ای که این دو را
* جدا کند، روی سرویس‌های بلند (گام > آستانه) هر اسلات را یک تب می‌کند و روی نوبت‌های
* اشغال، تبِ جعلی می‌سازد — یعنی اطلاعات غلط، که از یک تبِ درست بدتر است.
*
* راه درست، گروه‌بندی از سمت سرور است (endpoint چندمنبعی، تسک ۰۶). تا آن زمان یک
* session با **بازهٔ واقعی** برگردانده می‌شود.
*/
export function adaptServiceSlots(slotsResponse) {
const starts =
slotsResponse?.data?.start_times ?? slotsResponse?.start_times ?? [];
const payload = slotsResponse?.data ?? slotsResponse ?? {};
const starts = payload.start_times ?? [];
if (!starts.length) return [];
const first = starts[0];
const last = starts[starts.length - 1];
// پایانِ آخرین نوبت، نه زمانِ **شروعِ** آن — قبلاً `start_time` گذاشته می‌شد و برچسب
// بازه را کوتاه‌تر از واقعیت نشان می‌داد.
const endTime = last.end_time ?? addMinutes(last.start_time, payload.total_duration_minutes);
return [
{
start_time: starts[0].start_time,
end_time: starts[starts.length - 1].start_time,
label: "زمان‌های خالی",
start_time: first.start_time,
end_time: endTime,
label: `${first.start_time} - ${endTime}`,
slots: starts.map((s) => ({ ...s, is_available: true })),
},
];
}
/** `"09:00" + 35` → `"09:35"`. فقط fallback؛ پاسخ سرور `end_time` دارد. */
function addMinutes(time, minutes) {
const [h, m] = String(time).split(":").map(Number);
if (!Number.isFinite(h) || !Number.isFinite(m) || !Number.isFinite(minutes)) return time;
const total = h * 60 + m + minutes;
const hh = String(Math.floor(total / 60) % 24).padStart(2, "0");
const mm = String(total % 60).padStart(2, "0");
return `${hh}:${mm}`;
}
export function hasAvailable(slots) {
return Array.isArray(slots) && slots.some((slot) => slot.is_available);
}