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:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user