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)
|
.insert(appointments)
|
||||||
.values({ ...apptFields, startTime: start, endTime: end })
|
.values({ ...apptFields, startTime: start, endTime: end })
|
||||||
.returning();
|
.returning();
|
||||||
|
if (!inserted) throw new Error("Insert failed");
|
||||||
return inserted;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create recurring series
|
// Create recurring series
|
||||||
const [series] = await tx
|
const seriesRows = await tx
|
||||||
.insert(recurringSeries)
|
.insert(recurringSeries)
|
||||||
.values({ frequencyWeeks: recurrence.frequencyWeeks })
|
.values({ frequencyWeeks: recurrence.frequencyWeeks })
|
||||||
.returning();
|
.returning();
|
||||||
|
const series = seriesRows[0];
|
||||||
|
if (!series) throw new Error("Failed to create recurring series");
|
||||||
|
|
||||||
const durationMs = end.getTime() - start.getTime();
|
const durationMs = end.getTime() - start.getTime();
|
||||||
const intervalMs =
|
const intervalMs =
|
||||||
@@ -170,7 +173,8 @@ appointmentsRouter.post(
|
|||||||
if (i === 0) first = inserted;
|
if (i === 0) first = inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return first!;
|
if (!first) throw new Error("No appointments created");
|
||||||
|
return first;
|
||||||
});
|
});
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user