mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
update issue assignee full implementation
This commit is contained in:
@@ -41,7 +41,10 @@ export async function deleteIssue(id: number) {
|
||||
return await db.delete(Issue).where(eq(Issue.id, id));
|
||||
}
|
||||
|
||||
export async function updateIssue(id: number, updates: { title?: string; description?: string }) {
|
||||
export async function updateIssue(
|
||||
id: number,
|
||||
updates: { title?: string; description?: string; assigneeId?: number | null },
|
||||
) {
|
||||
return await db.update(Issue).set(updates).where(eq(Issue.id, id)).returning();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { updateIssue } from "../../db/queries";
|
||||
|
||||
// /issue/update?id=1&title=Testing&description=Description
|
||||
// /issue/update?id=1&title=Testing&description=Description&assigneeId=2
|
||||
// assigneeId can be "null" to unassign
|
||||
export default async function issueUpdate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
@@ -11,13 +12,24 @@ export default async function issueUpdate(req: BunRequest) {
|
||||
|
||||
const title = url.searchParams.get("title") || undefined;
|
||||
const description = url.searchParams.get("description") || undefined;
|
||||
if (!title && !description) {
|
||||
const assigneeIdParam = url.searchParams.get("assigneeId");
|
||||
|
||||
// Parse assigneeId: "null" means unassign, number means assign, undefined means no change
|
||||
let assigneeId: number | null | undefined;
|
||||
if (assigneeIdParam === "null") {
|
||||
assigneeId = null;
|
||||
} else if (assigneeIdParam) {
|
||||
assigneeId = Number(assigneeIdParam);
|
||||
}
|
||||
|
||||
if (!title && !description && assigneeId === undefined) {
|
||||
return new Response("no updates provided", { status: 400 });
|
||||
}
|
||||
|
||||
const issue = await updateIssue(Number(id), {
|
||||
title,
|
||||
description,
|
||||
assigneeId,
|
||||
});
|
||||
|
||||
return Response.json(issue);
|
||||
|
||||
Reference in New Issue
Block a user