CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
unread.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 3ef4c9d | 1 | /** |
| 2 | * Helper to fetch the unread notification count for a user. | |
| 3 | * Extracted so any handler can pass it to <Layout> without importing the route file. | |
| 4 | * Errors are swallowed — the nav must never break because of a counter. | |
| 5 | */ | |
| 6 | ||
| 7 | import { and, eq, isNull, sql } from "drizzle-orm"; | |
| 8 | import { db } from "../db"; | |
| 9 | import { notifications } from "../db/schema"; | |
| 10 | ||
| 11 | export async function getUnreadCount(userId: string): Promise<number> { | |
| 12 | try { | |
| 13 | const [row] = await db | |
| 14 | .select({ c: sql<number>`count(*)::int` }) | |
| 15 | .from(notifications) | |
| 16 | .where(and(eq(notifications.userId, userId), isNull(notifications.readAt))); | |
| 17 | return row?.c ?? 0; | |
| 18 | } catch { | |
| 19 | return 0; | |
| 20 | } | |
| 21 | } |