fix(260607-l6l): add missing innerJoin to PATCH+DELETE event lookups

BUG 1: PATCH /:uid/edit and DELETE /:uid selected calendars.url/userId
from .from(calendarEvents) with no join, causing Drizzle to throw at
toSQL() time → 503. Added .innerJoin(calendars, ...) to both lookups,
mirroring the working GET / join idiom.

- Updated PATCH + DELETE beforeEach mocks to route through innerJoin→where
- Updated CR-01 PATCH test mock similarly
- Added regression: edit/delete lookups join calendars describe block with
  toSQL() assertions using vi.importActual (real drizzle, no DB needed)
- All 21 tests pass; typecheck clean
This commit is contained in:
Lucas Berger
2026-06-07 15:25:31 -04:00
parent 4e174e5b44
commit 28704132d0
2 changed files with 94 additions and 9 deletions
+8 -3
View File
@@ -290,8 +290,9 @@ eventsRouter.patch('/:uid/edit', zValidator('json', eventFieldsSchema), async (c
try {
// --- Look up the event and verify ownership ---
// We look up calendarEvents joined to calendars via a where condition on calendarId.
// The calendar's userId must match the current user (or be shared).
// Join calendarEvents calendars so we can read calendars.url and calendars.userId
// in the same query. Without the join, referencing calendars.* produces invalid SQL
// (Drizzle throws at toSQL() time) → 503. Mirrors the GET / join idiom at line 153.
const [eventRow] = await db
.select({
uid: calendarEvents.uid,
@@ -302,6 +303,7 @@ eventsRouter.patch('/:uid/edit', zValidator('json', eventFieldsSchema), async (c
userId: calendars.userId,
})
.from(calendarEvents)
.innerJoin(calendars, eq(calendarEvents.calendarId, calendars.id))
.where(eq(calendarEvents.uid, uid))
if (!eventRow) {
@@ -388,7 +390,9 @@ eventsRouter.delete('/:uid', async (c) => {
const uid = c.req.param('uid')
try {
// Look up the event
// Look up the event — join calendars so calendars.url / calendars.userId are accessible.
// Same innerJoin idiom as the GET / handler (line 153). Without this join, Drizzle
// throws at toSQL() time → 503.
const [eventRow] = await db
.select({
uid: calendarEvents.uid,
@@ -399,6 +403,7 @@ eventsRouter.delete('/:uid', async (c) => {
userId: calendars.userId,
})
.from(calendarEvents)
.innerJoin(calendars, eq(calendarEvents.calendarId, calendars.id))
.where(eq(calendarEvents.uid, uid))
if (!eventRow) {