mirror of
https://github.com/hex248/sprint.git
synced 2026-02-09 02:33:02 +00:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import type { BunRequest } from "bun";
|
|
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) {
|
|
const url = new URL(req.url);
|
|
const projectId = url.searchParams.get("projectId");
|
|
const projectKey = url.searchParams.get("projectKey");
|
|
|
|
let project = null;
|
|
if (projectId) {
|
|
project = await getProjectByID(Number(projectId));
|
|
} else if (projectKey) {
|
|
project = await getProjectByKey(projectKey);
|
|
} else {
|
|
return new Response("missing project key or project id", { status: 400 });
|
|
}
|
|
if (!project) {
|
|
return new Response(`project not found: provided ${projectId ?? projectKey}`, { status: 404 });
|
|
}
|
|
|
|
const title = url.searchParams.get("title") || "Untitled Issue";
|
|
const description = url.searchParams.get("description") || "";
|
|
|
|
const issue = await createIssue(project.id, title, description);
|
|
|
|
return Response.json(issue);
|
|
}
|