fix: resolve TypeScript errors in recurring appointments route

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 <noreply@paperclip.ing>
This commit is contained in:
Groom Book CTO
2026-03-17 20:33:48 +00:00
parent 78d6368ad4
commit ed2134aaa4
+6 -2
View File
@@ -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 (