Merge pull request #346 from groombook/fix/gro-816-portal-pets-crash
fix(GRO-816): fix PetProfiles crash from appointments response shape change
This commit was merged in pull request #346.
This commit is contained in:
@@ -102,7 +102,6 @@ portalRouter.get("/appointments", async (c) => {
|
|||||||
const db = getDb();
|
const db = getDb();
|
||||||
const clientId = c.get("portalClientId");
|
const clientId = c.get("portalClientId");
|
||||||
|
|
||||||
const now = new Date();
|
|
||||||
const allAppts = await db
|
const allAppts = await db
|
||||||
.select({
|
.select({
|
||||||
id: appointments.id,
|
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,
|
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");
|
return c.json({ appointments: appts });
|
||||||
const past = appts.filter(a => a.startTime <= now || a.status === "cancelled");
|
|
||||||
|
|
||||||
return c.json({ upcoming, past });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
portalRouter.get("/pets", async (c) => {
|
portalRouter.get("/pets", async (c) => {
|
||||||
@@ -153,7 +149,7 @@ portalRouter.get("/pets", async (c) => {
|
|||||||
const clientId = c.get("portalClientId");
|
const clientId = c.get("portalClientId");
|
||||||
|
|
||||||
const clientPets = await db.select().from(pets).where(eq(pets.clientId, clientId));
|
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) => {
|
portalRouter.get("/invoices", async (c) => {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ const RATE_LIMIT_MAX = 10;
|
|||||||
const rateLimitMap = new Map<string, { count: number; resetAt: number }>();
|
const rateLimitMap = new Map<string, { count: number; resetAt: number }>();
|
||||||
|
|
||||||
function rateLimitByIp(ip: string): { allowed: boolean; remaining: number } {
|
function rateLimitByIp(ip: string): { allowed: boolean; remaining: number } {
|
||||||
const now = Date.now();
|
|
||||||
const entry = rateLimitMap.get(ip);
|
const entry = rateLimitMap.get(ip);
|
||||||
|
const now = Date.now();
|
||||||
if (!entry || now > entry.resetAt) {
|
if (!entry || now > entry.resetAt) {
|
||||||
rateLimitMap.set(ip, { count: 1, resetAt: now + RATE_LIMIT_WINDOW_MS });
|
rateLimitMap.set(ip, { count: 1, resetAt: now + RATE_LIMIT_WINDOW_MS });
|
||||||
return { allowed: true, remaining: RATE_LIMIT_MAX - 1 };
|
return { allowed: true, remaining: RATE_LIMIT_MAX - 1 };
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ interface Appointment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AppointmentsResponse {
|
interface AppointmentsResponse {
|
||||||
upcoming: Appointment[];
|
appointments: Appointment[];
|
||||||
past: Appointment[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -46,7 +45,7 @@ function buildHeaders(sessionId: string | null): Record<string, string> {
|
|||||||
|
|
||||||
export function PetProfiles({ sessionId, readOnly }: Props) {
|
export function PetProfiles({ sessionId, readOnly }: Props) {
|
||||||
const [pets, setPets] = useState<Pet[]>([]);
|
const [pets, setPets] = useState<Pet[]>([]);
|
||||||
const [appointments, setAppointments] = useState<AppointmentsResponse>({ upcoming: [], past: [] });
|
const [appointments, setAppointments] = useState<AppointmentsResponse>({ appointments: [] });
|
||||||
const [selectedPetId, setSelectedPetId] = useState<string>("");
|
const [selectedPetId, setSelectedPetId] = useState<string>("");
|
||||||
const [activeTab, setActiveTab] = useState<"info" | "medical" | "grooming" | "history">("info");
|
const [activeTab, setActiveTab] = useState<"info" | "medical" | "grooming" | "history">("info");
|
||||||
const [editingPetId, setEditingPetId] = useState<string | null>(null);
|
const [editingPetId, setEditingPetId] = useState<string | null>(null);
|
||||||
@@ -90,7 +89,7 @@ export function PetProfiles({ sessionId, readOnly }: Props) {
|
|||||||
}, [sessionId]);
|
}, [sessionId]);
|
||||||
|
|
||||||
const selectedPet = pets.find(p => p.id === selectedPetId) ?? null;
|
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;
|
const editingPet = editingPetId ? pets.find(p => p.id === editingPetId) ?? null : null;
|
||||||
|
|
||||||
function handlePetSave(updatedPet: Pet) {
|
function handlePetSave(updatedPet: Pet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user