Skip to content

Commit b825505

Browse files
committed
remaining backend changes
1 parent 21f8b0f commit b825505

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

apps/dashboard/convex/bookmarks.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ async function findBookmark(
5353
.unique();
5454
}
5555

56+
function isPublished(event: Doc<"events">): boolean {
57+
return event.visibility !== "draft" && event.visibility !== "hidden";
58+
}
59+
5660
export const bookmark = mutation({
5761
args: { eventId: v.id("events") },
5862
handler: async (ctx, args) => {
@@ -64,6 +68,14 @@ export const bookmark = mutation({
6468
});
6569
}
6670

71+
const event = await ctx.db.get(args.eventId);
72+
if (event === null || !isPublished(event)) {
73+
throw new ConvexError({
74+
code: "EVENT_NOT_FOUND",
75+
message: "This event is not available to bookmark.",
76+
});
77+
}
78+
6779
const existing = await findBookmark(ctx, userId, args.eventId);
6880
if (existing !== null) {
6981
// Idempotent: already bookmarked.
@@ -132,6 +144,7 @@ export const myBookmarks = query({
132144
for (const row of result.page) {
133145
const event = await ctx.db.get(row.eventId);
134146
if (event === null) continue;
147+
if (!isPublished(event)) continue;
135148
const orgs = await loadOrgsForEvent(ctx, event._id);
136149
hydrated.push({ bookmark: row, event, orgs });
137150
}

apps/dashboard/convex/events.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const FEED_MIN_ITEMS = 20;
2828
// Bounded pool size when pulling recommended events to dedupe + backfill from.
2929
const RECOMMENDED_POOL_SIZE = 50;
3030
// Bounded scan sizes for the interest-personalised recommendation pass. Kept
31-
// small so the feed query stays cheap; the full ranking model lives on a
32-
// separate branch and will replace this stub.
31+
// small so the feed query stays cheap while still providing relevant backfill.
3332
const RECOMMENDED_ORG_SCAN = 100;
3433
const RECOMMENDED_EVENTS_PER_ORG = 10;
3534

@@ -303,7 +302,7 @@ export const getById = query({
303302
args: { eventId: v.id("events") },
304303
handler: async (ctx, args): Promise<HydratedEvent | null> => {
305304
const event = await ctx.db.get(args.eventId);
306-
if (event === null) {
305+
if (event === null || !isPublished(event)) {
307306
return null;
308307
}
309308
const userId = await getAuthUserId(ctx);
@@ -407,8 +406,11 @@ export const getEmailContent = query({
407406
ctx,
408407
args,
409408
): Promise<{ subject: string; paragraphs: string[] } | null> => {
409+
const userId = await getAuthUserId(ctx);
410+
if (userId === null) return null;
411+
410412
const event = await ctx.db.get(args.eventId);
411-
if (event === null) return null;
413+
if (event === null || !isPublished(event)) return null;
412414

413415
if (event.sourceMessageId !== undefined) {
414416
const msg = await ctx.db.get(event.sourceMessageId);

apps/dashboard/convex/seed.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ export const seedAll = internalMutation({
8585
isSeed: true,
8686
});
8787
summary.listservEmails += 1;
88+
} else {
89+
await ctx.db.patch(listservId, {
90+
sentAt: now,
91+
rawText: "Seed listserv parent row.",
92+
});
8893
}
8994

9095
// 2. Orgs (skip if a row with this slug already exists).

apps/extension/src/data/useEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface OrgSection {
3030
* All EventItem.id values originate from event._id in the mapper, so the
3131
* narrowing is sound even though the brand cannot be checked at runtime.
3232
*/
33-
function isEventId(id: string): id is Id<"events"> {
33+
export function isEventId(id: string): id is Id<"events"> {
3434
return id.length > 0;
3535
}
3636

@@ -139,7 +139,7 @@ export function useBookmarks(): { ids: Set<string>; events: EventItem[] } {
139139
if (result === undefined) return { ids: new Set(), events: [] };
140140

141141
const events = result.page.map(mapBookmark);
142-
const ids = new Set(result.page.map((b) => b.event._id as string));
142+
const ids = new Set<string>(result.page.map((b) => b.event._id));
143143
return { ids, events };
144144
}
145145

0 commit comments

Comments
 (0)