From 98f5bc03473d677e83aead6cc7631aa97a01e017 Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Wed, 15 Apr 2026 10:31:00 +0530 Subject: [PATCH] fix(ai-chat): use correct Clinic schema in knowledge-base query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Clinic entity has never had weekdayHours / saturdayHours / sundayHours. Schema uses 7 booleans (openMonday..openSunday) + a single opensAt/closesAt pair, and requiredDocuments is a RELATION (ClinicRequiredDocumentConnection), not a scalar TEXT. Query was failing silently since 2026-03-18 — AI chat knowledge base was missing clinic info for a month. Fix: - Query the real fields: openMonday..openSunday, opensAt, closesAt - Render "Open: Mon, Tue, ... HH:MM–HH:MM" + "Closed: Sat, Sun" - Walk requiredDocuments.edges for documentType list instead of treating it as a string Co-Authored-By: Claude Opus 4.6 (1M context) --- src/ai/ai-chat.controller.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ai/ai-chat.controller.ts b/src/ai/ai-chat.controller.ts index d6c66e7..84c3f9c 100644 --- a/src/ai/ai-chat.controller.ts +++ b/src/ai/ai-chat.controller.ts @@ -567,16 +567,23 @@ export class AiChatController { `{ clinics(first: 20) { edges { node { id name clinicName addressCustom { addressStreet1 addressCity addressState addressPostcode } - weekdayHours saturdayHours sundayHours + openMonday openTuesday openWednesday openThursday openFriday openSaturday openSunday + opensAt closesAt status walkInAllowed onlineBooking - cancellationWindowHours arriveEarlyMin requiredDocuments + cancellationWindowHours arriveEarlyMin acceptsCash acceptsCard acceptsUpi + requiredDocuments { edges { node { documentType notes } } } } } } }`, undefined, auth, ); const clinics = clinicData.clinics.edges.map((e: any) => e.node); if (clinics.length) { sections.push('## CLINICS & TIMINGS'); + const dayFlags: Array<[string, string]> = [ + ['Mon', 'openMonday'], ['Tue', 'openTuesday'], ['Wed', 'openWednesday'], + ['Thu', 'openThursday'], ['Fri', 'openFriday'], + ['Sat', 'openSaturday'], ['Sun', 'openSunday'], + ]; for (const c of clinics) { const name = c.clinicName ?? c.name; const addr = c.addressCustom @@ -584,9 +591,15 @@ export class AiChatController { : ''; sections.push(`### ${name}`); if (addr) sections.push(` Address: ${addr}`); - if (c.weekdayHours) sections.push(` Mon–Fri: ${c.weekdayHours}`); - if (c.saturdayHours) sections.push(` Saturday: ${c.saturdayHours}`); - sections.push(` Sunday: ${c.sundayHours ?? 'Closed'}`); + const openDays = dayFlags.filter(([, flag]) => c[flag]).map(([label]) => label); + if (openDays.length) { + const hours = c.opensAt && c.closesAt ? ` ${c.opensAt}–${c.closesAt}` : ''; + sections.push(` Open: ${openDays.join(', ')}${hours}`); + } + const closedDays = dayFlags.filter(([, flag]) => !c[flag]).map(([label]) => label); + if (closedDays.length) { + sections.push(` Closed: ${closedDays.join(', ')}`); + } if (c.walkInAllowed) sections.push(` Walk-ins: Accepted`); } @@ -594,7 +607,8 @@ export class AiChatController { const rules: string[] = []; if (rulesClinic.cancellationWindowHours) rules.push(`Free cancellation up to ${rulesClinic.cancellationWindowHours}h before`); if (rulesClinic.arriveEarlyMin) rules.push(`Arrive ${rulesClinic.arriveEarlyMin}min early`); - if (rulesClinic.requiredDocuments) rules.push(`First-time patients bring ${rulesClinic.requiredDocuments}`); + const docs = rulesClinic.requiredDocuments?.edges?.map((e: any) => e.node?.documentType).filter(Boolean) ?? []; + if (docs.length) rules.push(`First-time patients bring: ${docs.join(', ')}`); if (rulesClinic.walkInAllowed) rules.push('Walk-ins accepted'); if (rulesClinic.onlineBooking) rules.push('Online booking available'); if (rules.length) {