fix(03): WR-02 make default-calendar selection deterministic (orderBy id, limit 1)
This commit is contained in:
@@ -256,11 +256,17 @@ eventsRouter.post('/create', zValidator('json', eventFieldsSchema), async (c) =>
|
||||
}
|
||||
targetCalendarUrl = calRow.url
|
||||
} else {
|
||||
// Default to first personal calendar (D-01)
|
||||
// Default to the member's first personal calendar (D-01).
|
||||
// WR-02: add a deterministic ORDER BY + LIMIT. Without them, a member with
|
||||
// multiple personal calendars gets an arbitrary, query-to-query-unstable "first"
|
||||
// row. Ordering by id (insertion order) gives a stable default; limit(1) avoids
|
||||
// fetching the whole set just to take [0].
|
||||
const [calRow] = await db
|
||||
.select({ url: calendars.url })
|
||||
.from(calendars)
|
||||
.where(eq(calendars.userId, currentUserId))
|
||||
.orderBy(calendars.id)
|
||||
.limit(1)
|
||||
|
||||
if (!calRow) {
|
||||
return c.json({ error: 'No writable calendar found for user' }, 422)
|
||||
|
||||
Reference in New Issue
Block a user