upd
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user