This commit is contained in:
2025-06-05 16:46:39 +05:00
parent f408328771
commit 4bb5bde87e
6 changed files with 120 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import { error } from "elysia";
import { and, desc, eq } from "drizzle-orm";
import db from "../../db";
import { commentsTable } from "../../db/schema";
export async function getComments(sessionId: string, userId: string) {
try {
const comments = await db.query.commentsTable.findMany({
where: and(
eq(commentsTable.sessionId, sessionId),
eq(commentsTable.ownerId, userId)
),
with: {
owner: {
columns: {
fullname: true,
id: true,
},
},
},
orderBy: desc(commentsTable.createdAt),
});
return comments;
} catch (err) {
console.log((err as Error).message);
return error(500, "Internal Server Error");
}
}
export default getComments;