Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.2 kB ยท 47 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import { and, desc, eq } from "@openstatus/db";import { MAX_CHAT_SESSIONS_PER_USER, chatSession,} from "@openstatus/db/src/schema";
import { type ServiceContext, getReadDb, tryGetActorUserId } from "../context";import { UnauthorizedError } from "../errors";
export type ChatSessionSummary = { id: number; title: string; updatedAt: Date; createdAt: Date;};
export async function listChatSessions(args: { ctx: ServiceContext;}): Promise<ChatSessionSummary[]> { const { ctx } = args; const userId = tryGetActorUserId(ctx.actor); if (userId == null) { throw new UnauthorizedError( "Chat sessions can only be listed for a known user actor.", ); }
const db = getReadDb(ctx); const rows = await db .select({ id: chatSession.id, title: chatSession.title, updatedAt: chatSession.updatedAt, createdAt: chatSession.createdAt, }) .from(chatSession) .where( and( eq(chatSession.workspaceId, ctx.workspace.id), eq(chatSession.userId, userId), ), ) .orderBy(desc(chatSession.updatedAt)) .limit(MAX_CHAT_SESSIONS_PER_USER) .all(); return rows;}