diff --git a/apps/api/src/routes/portal.ts b/apps/api/src/routes/portal.ts index dc556c8..a4c2b87 100644 --- a/apps/api/src/routes/portal.ts +++ b/apps/api/src/routes/portal.ts @@ -102,7 +102,6 @@ portalRouter.get("/appointments", async (c) => { const db = getDb(); const clientId = c.get("portalClientId"); - const now = new Date(); const allAppts = await db .select({ id: appointments.id, @@ -142,10 +141,7 @@ portalRouter.get("/appointments", async (c) => { staff: a.staffId ? { id: staffMap[a.staffId]?.id, name: staffMap[a.staffId]?.name } : null, })); - const upcoming = appts.filter(a => a.startTime > now && a.status !== "cancelled"); - const past = appts.filter(a => a.startTime <= now || a.status === "cancelled"); - - return c.json({ upcoming, past }); + return c.json({ appointments: appts }); }); portalRouter.get("/pets", async (c) => { @@ -153,7 +149,7 @@ portalRouter.get("/pets", async (c) => { const clientId = c.get("portalClientId"); const clientPets = await db.select().from(pets).where(eq(pets.clientId, clientId)); - return c.json(clientPets.map(p => ({ id: p.id, name: p.name, breed: p.breed, weightKg: p.weightKg, dateOfBirth: p.dateOfBirth, photoKey: p.photoKey, groomingNotes: p.groomingNotes }))); + return c.json(clientPets.map(p => ({ id: p.id, name: p.name, breed: p.breed, weight: p.weightKg, birthDate: p.dateOfBirth, photoUrl: p.photoKey, notes: p.groomingNotes }))); }); portalRouter.get("/invoices", async (c) => { diff --git a/apps/api/src/routes/setup.ts b/apps/api/src/routes/setup.ts index a84e61d..495fd66 100644 --- a/apps/api/src/routes/setup.ts +++ b/apps/api/src/routes/setup.ts @@ -9,8 +9,8 @@ const RATE_LIMIT_MAX = 10; const rateLimitMap = new Map(); function rateLimitByIp(ip: string): { allowed: boolean; remaining: number } { - const now = Date.now(); const entry = rateLimitMap.get(ip); + const now = Date.now(); if (!entry || now > entry.resetAt) { rateLimitMap.set(ip, { count: 1, resetAt: now + RATE_LIMIT_WINDOW_MS }); return { allowed: true, remaining: RATE_LIMIT_MAX - 1 }; diff --git a/apps/web/src/portal/sections/PetProfiles.tsx b/apps/web/src/portal/sections/PetProfiles.tsx index f657e6a..e9fb07b 100644 --- a/apps/web/src/portal/sections/PetProfiles.tsx +++ b/apps/web/src/portal/sections/PetProfiles.tsx @@ -27,8 +27,7 @@ interface Appointment { } interface AppointmentsResponse { - upcoming: Appointment[]; - past: Appointment[]; + appointments: Appointment[]; } interface Props { @@ -46,7 +45,7 @@ function buildHeaders(sessionId: string | null): Record { export function PetProfiles({ sessionId, readOnly }: Props) { const [pets, setPets] = useState([]); - const [appointments, setAppointments] = useState({ upcoming: [], past: [] }); + const [appointments, setAppointments] = useState({ appointments: [] }); const [selectedPetId, setSelectedPetId] = useState(""); const [activeTab, setActiveTab] = useState<"info" | "medical" | "grooming" | "history">("info"); const [editingPetId, setEditingPetId] = useState(null); @@ -90,7 +89,7 @@ export function PetProfiles({ sessionId, readOnly }: Props) { }, [sessionId]); const selectedPet = pets.find(p => p.id === selectedPetId) ?? null; - const petHistory = appointments.past.filter(a => a.pet?.id === selectedPetId); + const petHistory = appointments.appointments.filter(a => a.pet?.id === selectedPetId && new Date(a.startTime) <= new Date()); const editingPet = editingPetId ? pets.find(p => p.id === editingPetId) ?? null : null; function handlePetSave(updatedPet: Pet) {