aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/actions/fetchers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/app/actions/fetchers.ts')
-rw-r--r--apps/web/app/actions/fetchers.ts30
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[]
> => {