diff options
| author | codetorso <[email protected]> | 2024-07-20 07:17:25 +0530 |
|---|---|---|
| committer | codetorso <[email protected]> | 2024-07-20 07:17:25 +0530 |
| commit | 21fe55a96c36892fc50e8198248da825a5a4bd6f (patch) | |
| tree | 83832e20adb0e4acfa529ac624e7f2b914f7a25a /apps/web/app/actions/fetchers.ts | |
| parent | fix links (diff) | |
| download | supermemory-torso.tar.xz supermemory-torso.zip | |
for god's sake this should work ;)torso
Diffstat (limited to 'apps/web/app/actions/fetchers.ts')
| -rw-r--r-- | apps/web/app/actions/fetchers.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts index 1838ee1c..74df0b04 100644 --- a/apps/web/app/actions/fetchers.ts +++ b/apps/web/app/actions/fetchers.ts @@ -1,6 +1,6 @@ "use server"; -import { and, asc, eq, exists, inArray, not, or, sql } from "drizzle-orm"; +import { and, asc, desc, eq, exists, inArray, not, or, sql } from "drizzle-orm"; import { db } from "../../server/db"; import { canvas, @@ -228,6 +228,34 @@ export const getFullChatThread = async ( }; }; +export const getRecentChats = async (): ServerActionReturnType<ChatThread[]> => { + const data = await auth(); + + if (!data || !data.user || !data.user.id) { + redirect("/signin"); + return { error: "Not authenticated", success: false }; + } + + try { + const chatHistorys = await db.query.chatThreads.findMany({ + where: eq(chatThreads.userId, data.user.id), + orderBy: desc(chatThreads.createdAt), + limit: 4, + }); + + return { + success: true, + data: chatHistorys, + }; + } catch (e) { + return { + success: false, + error: (e as Error).message, + }; + } +}; + + export const getChatHistory = async (): ServerActionReturnType< ChatThread[] > => { |