fix(03): CR-01 preserve RRULE on edit-as-move (forward source rule to create row)

This commit is contained in:
Lucas Berger
2026-06-09 10:59:19 -04:00
parent 7a48659cae
commit 5168920eb1
4 changed files with 146 additions and 2 deletions
+22 -1
View File
@@ -31,6 +31,7 @@ import { sql } from 'drizzle-orm'
import { db } from '../db/client.js'
import { calendarEvents, calendars, users, calendarOutbox } from '../db/schema.js'
import { expandOccurrences } from '../broker/expand.js'
import { extractRruleString } from '../broker/vevent.js'
import { getAuth } from '../auth/middleware.js'
import { upsertUser, deriveDisplayName } from '../auth/user.js'
// Side-effect import: brings in the ContextVariableMap augmentation for c.get('user')
@@ -334,6 +335,7 @@ eventsRouter.patch('/:uid/edit', zValidator('json', eventFieldsSchema), async (c
calendarId: calendarEvents.calendarId,
calendarUrl: calendars.url,
userId: calendars.userId,
rawVevent: calendarEvents.rawVevent,
})
.from(calendarEvents)
.innerJoin(calendars, eq(calendarEvents.calendarId, calendars.id))
@@ -373,6 +375,25 @@ eventsRouter.patch('/:uid/edit', zValidator('json', eventFieldsSchema), async (c
const newUid = `${randomUUID()}@familysync`
const groupId = randomUUID()
// CR-01: carry the existing RRULE through the move. The edit payload omits
// `recurrence` (the occurrence contract does not expose it, D-03), and the
// create lands under a brand-new uid that the worker can never look up the
// original RRULE from. Unlike the same-calendar `update` branch — which reads
// rawVevent and re-applies the stored RRULE — the create branch has no source
// for it. Extract the RRULE from the source event here and stash it on the
// create payload so the worker re-applies it, preventing a recurring series
// from silently collapsing into a single occurrence on a calendar move.
// Only stash when the edit did NOT carry an explicit recurrence: an explicit
// value (including 'none') is a deliberate user change and must win.
const preservedRrule =
payload.recurrence === undefined
? extractRruleString(eventRow.rawVevent ?? '')
: undefined
const createPayload =
preservedRrule !== undefined
? { ...payload, _preservedRrule: preservedRrule }
: payload
await db.transaction(async (tx) => {
// Delete from old calendar
await tx.insert(calendarOutbox).values({
@@ -392,7 +413,7 @@ eventsRouter.patch('/:uid/edit', zValidator('json', eventFieldsSchema), async (c
status: 'pending',
uid: newUid,
calendarUrl: newCalendarUrl,
payload: JSON.stringify(payload),
payload: JSON.stringify(createPayload),
groupId,
})
})