mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
Issue.creatorId + implementation
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Issue, User } from "@issue/shared";
|
||||
import { and, eq, sql } from "drizzle-orm";
|
||||
import { aliasedTable, and, eq, sql } from "drizzle-orm";
|
||||
import { db } from "../client";
|
||||
|
||||
export async function createIssue(
|
||||
projectId: number,
|
||||
title: string,
|
||||
description: string,
|
||||
creatorId: number,
|
||||
assigneeId?: number,
|
||||
) {
|
||||
// prevents two issues with the same unique number
|
||||
@@ -27,6 +28,7 @@ export async function createIssue(
|
||||
title,
|
||||
description,
|
||||
number: nextNumber,
|
||||
creatorId,
|
||||
assigneeId,
|
||||
})
|
||||
.returning();
|
||||
@@ -64,10 +66,18 @@ export async function getIssueByNumber(projectId: number, number: number) {
|
||||
return issue;
|
||||
}
|
||||
|
||||
export async function getIssuesWithAssigneeByProject(projectId: number) {
|
||||
export async function getIssuesWithUsersByProject(projectId: number) {
|
||||
const Creator = aliasedTable(User, "Creator");
|
||||
const Assignee = aliasedTable(User, "Assignee");
|
||||
|
||||
return await db
|
||||
.select()
|
||||
.select({
|
||||
Issue: Issue,
|
||||
Creator: Creator,
|
||||
Assignee: Assignee,
|
||||
})
|
||||
.from(Issue)
|
||||
.where(eq(Issue.projectId, projectId))
|
||||
.leftJoin(User, eq(Issue.assigneeId, User.id));
|
||||
.innerJoin(Creator, eq(Issue.creatorId, Creator.id))
|
||||
.leftJoin(Assignee, eq(Issue.assigneeId, Assignee.id));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { createIssue, getProjectByID, getProjectByKey } from "../../db/queries";
|
||||
|
||||
// /issue/create?projectId=1&title=Testing&description=Description
|
||||
// OR
|
||||
// /issue/create?projectKey=projectKey&title=Testing&description=Description
|
||||
export default async function issueCreate(req: BunRequest) {
|
||||
export default async function issueCreate(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
const projectId = url.searchParams.get("projectId");
|
||||
const projectKey = url.searchParams.get("projectKey");
|
||||
@@ -24,7 +24,7 @@ export default async function issueCreate(req: BunRequest) {
|
||||
const title = url.searchParams.get("title") || "Untitled Issue";
|
||||
const description = url.searchParams.get("description") || "";
|
||||
|
||||
const issue = await createIssue(project.id, title, description);
|
||||
const issue = await createIssue(project.id, title, description, req.userId);
|
||||
|
||||
return Response.json(issue);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { getIssuesWithAssigneeByProject, getProjectByID } from "../../db/queries";
|
||||
import { getIssuesWithUsersByProject, getProjectByID } from "../../db/queries";
|
||||
|
||||
export default async function issuesByProject(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
@@ -9,7 +9,7 @@ export default async function issuesByProject(req: AuthedRequest) {
|
||||
if (!project) {
|
||||
return new Response(`project not found: provided ${projectId}`, { status: 404 });
|
||||
}
|
||||
const issues = await getIssuesWithAssigneeByProject(project.id);
|
||||
const issues = await getIssuesWithUsersByProject(project.id);
|
||||
|
||||
return Response.json(issues);
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ export const createDemoData = async () => {
|
||||
project.id,
|
||||
`Issue ${i} in ${projectName}`,
|
||||
`This is a description for issue ${i} in ${projectName}.`,
|
||||
config.creator.id,
|
||||
assignee,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user