assignee implementation

This commit is contained in:
Oliver Bryan
2025-12-14 22:08:16 +00:00
parent d70ebee7e6
commit 4314797bdf
2 changed files with 19 additions and 5 deletions

View File

@@ -1,8 +1,13 @@
import { eq, sql, and } from "drizzle-orm";
import { Issue, User } from "@issue/shared";
import { and, eq, sql } from "drizzle-orm";
import { db } from "../client";
import { Issue } from "@issue/shared";
export async function createIssue(projectId: number, title: string, description: string) {
export async function createIssue(
projectId: number,
title: string,
description: string,
assigneeId?: number,
) {
// prevents two issues with the same unique number
return await db.transaction(async (tx) => {
// raw sql for speed
@@ -22,6 +27,7 @@ export async function createIssue(projectId: number, title: string, description:
title,
description,
number: nextNumber,
assigneeId,
})
.returning();
@@ -57,3 +63,11 @@ export async function getIssueByNumber(projectId: number, number: number) {
.where(and(eq(Issue.projectId, projectId), eq(Issue.number, number)));
return issue;
}
export async function getIssuesWithAssigneeByProject(projectId: number) {
return await db
.select()
.from(Issue)
.where(eq(Issue.projectId, projectId))
.leftJoin(User, eq(Issue.assigneeId, User.id));
}

View File

@@ -1,5 +1,5 @@
import type { BunRequest } from "bun";
import { getIssuesByProject, getProjectByBlob } from "../../db/queries";
import { getIssuesWithAssigneeByProject, getProjectByBlob } from "../../db/queries";
export default async function issuesInProject(req: BunRequest<"/issues/:projectBlob">) {
const { projectBlob } = req.params;
@@ -8,7 +8,7 @@ export default async function issuesInProject(req: BunRequest<"/issues/:projectB
if (!project) {
return new Response(`project not found: provided ${projectBlob}`, { status: 404 });
}
const issues = await getIssuesByProject(project.id);
const issues = await getIssuesWithAssigneeByProject(project.id);
return Response.json(issues);
}