From ed2134aaa4b0dfd4d289a7577569c5f9d1cc05f2 Mon Sep 17 00:00:00 2001 From: Groom Book CTO Date: Tue, 17 Mar 2026 20:33:48 +0000 Subject: [PATCH] fix: resolve TypeScript errors in recurring appointments route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard against possibly-undefined results from Drizzle .returning() destructuring — use indexed access + explicit null checks instead of array destructuring for the recurring_series insert, and add an early throw when the series or first appointment row is missing. Co-Authored-By: Paperclip --- apps/api/src/routes/appointments.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/api/src/routes/appointments.ts b/apps/api/src/routes/appointments.ts index c1b3e25..b7cc938 100644 --- a/apps/api/src/routes/appointments.ts +++ b/apps/api/src/routes/appointments.ts @@ -138,14 +138,17 @@ appointmentsRouter.post( .insert(appointments) .values({ ...apptFields, startTime: start, endTime: end }) .returning(); + if (!inserted) throw new Error("Insert failed"); return inserted; } // Create recurring series - const [series] = await tx + const seriesRows = await tx .insert(recurringSeries) .values({ frequencyWeeks: recurrence.frequencyWeeks }) .returning(); + const series = seriesRows[0]; + if (!series) throw new Error("Failed to create recurring series"); const durationMs = end.getTime() - start.getTime(); const intervalMs = @@ -170,7 +173,8 @@ appointmentsRouter.post( if (i === 0) first = inserted; } - return first!; + if (!first) throw new Error("No appointments created"); + return first; }); } catch (err: unknown) { if (