fix(03): correct event-write timezone + per-user calendar identity (Gate 2 Part D)
BUG A — timed events written 4h off: EventForm sent a naive local wall-clock string with no offset; the UTC API container parsed it via new Date() as UTC, so 09:00 America/Toronto serialized to DTSTART:...090000Z. Fix: new apps/pwa/src/lib/eventDateTime.ts serializes timed events to an unambiguous UTC instant in the browser (where the operator's zone is known); all-day stays a DATE string. No backend change. BUG B — created events attached to the wrong user's calendar + duplicate calendar rows per poll: calendars had no unique key on url, and poller/sync matched calendars by url alone — so under the shared single Fastmail account (D-16) one member's collection resolved to the other member's row. Fix: composite unique(user_id, url); scope poller lookup + sync select to (userId, url); hand migration 0001 (dedup + add key), applied to the live DB. Regression tests fail against the buggy url-only predicate. API 98/98, PWA 140/140, tsc clean both packages.
This commit is contained in:
@@ -73,7 +73,16 @@ export const calendars = mysqlTable(
|
||||
lastSyncedAt: timestamp('last_synced_at'),
|
||||
isShared: boolean('is_shared').default(false).notNull(),
|
||||
},
|
||||
(t) => [index('idx_calendars_user_id').on(t.userId)],
|
||||
(t) => [
|
||||
index('idx_calendars_user_id').on(t.userId),
|
||||
// BUG B: calendar identity is (userId, url), not url alone. The two household
|
||||
// members share one Fastmail account (D-16), so the SAME collection URL is
|
||||
// polled by both credentials. Without this unique key the calendar upsert's
|
||||
// onDuplicateKeyUpdate never fired → a new row per poll, and the url-only
|
||||
// lookup resolved to the other member's row → events cached under the wrong
|
||||
// calendarId. Keying on (userId, url) makes the upsert idempotent per member.
|
||||
unique('uniq_calendar_user_url').on(t.userId, t.url),
|
||||
],
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user