mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
/issue/create
This commit is contained in:
@@ -11,6 +11,7 @@ const main = async () => {
|
||||
port: Number(PORT),
|
||||
routes: {
|
||||
"/": () => new Response(`title: eussi\ndev-mode: ${DEV}\nport: ${PORT}`),
|
||||
"/issue/create": routes.issueCreate,
|
||||
"/issues/:projectId": routes.issues,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import issueCreate from "./issueCreate"
|
||||
import issues from "./issues";
|
||||
|
||||
export const routes = {
|
||||
issueCreate,
|
||||
issues,
|
||||
};
|
||||
|
||||
31
src/routes/issueCreate.ts
Normal file
31
src/routes/issueCreate.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { createIssue, getProjectByID, getProjectByBlob } from "../db/queries.js";
|
||||
|
||||
// /issue/create?projectId=1&title=Testing&description=Description
|
||||
// OR
|
||||
// /issue/create?projectBlob=projectBlob&title=Testing&description=Description
|
||||
export default async function issueCreate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const projectId = url.searchParams.get("projectId");
|
||||
const projectBlob = url.searchParams.get("projectBlob");
|
||||
|
||||
let project = null;
|
||||
if (projectId) {
|
||||
project = await getProjectByID(Number(projectId));
|
||||
} else if (projectBlob) {
|
||||
project = await getProjectByBlob(projectBlob);
|
||||
} else {
|
||||
return new Response("missing project blob or project id", { status: 400 });
|
||||
}
|
||||
if (!project) {
|
||||
return new Response(`project not found: provided ${projectId ?? projectBlob}`, { 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user