mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
full comments system
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from "./issue-comments";
|
||||
export * from "./issues";
|
||||
export * from "./organisations";
|
||||
export * from "./projects";
|
||||
|
||||
48
packages/backend/src/db/queries/issue-comments.ts
Normal file
48
packages/backend/src/db/queries/issue-comments.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Issue, IssueComment, type IssueCommentResponse, Project, User } from "@sprint/shared";
|
||||
import { asc, eq } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
|
||||
export async function createIssueComment(issueId: number, userId: number, body: string) {
|
||||
const [comment] = await db
|
||||
.insert(IssueComment)
|
||||
.values({
|
||||
issueId,
|
||||
userId,
|
||||
body,
|
||||
})
|
||||
.returning();
|
||||
return comment;
|
||||
}
|
||||
|
||||
export async function deleteIssueComment(id: number) {
|
||||
return await db.delete(IssueComment).where(eq(IssueComment.id, id));
|
||||
}
|
||||
|
||||
export async function getIssueCommentById(id: number) {
|
||||
const [comment] = await db.select().from(IssueComment).where(eq(IssueComment.id, id));
|
||||
return comment;
|
||||
}
|
||||
|
||||
export async function getIssueCommentsByIssueId(issueId: number): Promise<IssueCommentResponse[]> {
|
||||
const comments = await db
|
||||
.select({
|
||||
Comment: IssueComment,
|
||||
User: User,
|
||||
})
|
||||
.from(IssueComment)
|
||||
.where(eq(IssueComment.issueId, issueId))
|
||||
.innerJoin(User, eq(IssueComment.userId, User.id))
|
||||
.orderBy(asc(IssueComment.createdAt));
|
||||
|
||||
return comments;
|
||||
}
|
||||
|
||||
export async function getIssueOrganisationId(issueId: number) {
|
||||
const [result] = await db
|
||||
.select({ organisationId: Project.organisationId })
|
||||
.from(Issue)
|
||||
.innerJoin(Project, eq(Issue.projectId, Project.id))
|
||||
.where(eq(Issue.id, issueId));
|
||||
|
||||
return result?.organisationId ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user