mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
assignee implementation
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user