mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
Add 'packages/backend/' from commit 'acce648ee5e7e3a3006451e637c0db654820cc48'
git-subtree-dir: packages/backend git-subtree-mainline:d0babd62afgit-subtree-split:acce648ee5
This commit is contained in:
30
packages/backend/src/routes/issue/create.ts
Normal file
30
packages/backend/src/routes/issue/create.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { createIssue, getProjectByID, getProjectByBlob } from "../../db/queries";
|
||||
|
||||
// /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);
|
||||
}
|
||||
18
packages/backend/src/routes/issue/delete.ts
Normal file
18
packages/backend/src/routes/issue/delete.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { deleteIssue } from "../../db/queries";
|
||||
|
||||
// /issue/delete?id=1
|
||||
export default async function issueDelete(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
if (!id) {
|
||||
return new Response("missing issue id", { status: 400 });
|
||||
}
|
||||
|
||||
const result = await deleteIssue(Number(id));
|
||||
if (result.rowCount === 0) {
|
||||
return new Response(`no issue with id ${id} found`, { status: 404 });
|
||||
}
|
||||
|
||||
return new Response(`issue with id ${id} deleted`, { status: 200 });
|
||||
}
|
||||
24
packages/backend/src/routes/issue/update.ts
Normal file
24
packages/backend/src/routes/issue/update.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { updateIssue } from "../../db/queries";
|
||||
|
||||
// /issue/update?id=1&title=Testing&description=Description
|
||||
export default async function issueUpdate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
if (!id) {
|
||||
return new Response("missing issue id", { status: 400 });
|
||||
}
|
||||
|
||||
const title = url.searchParams.get("title") || undefined;
|
||||
const description = url.searchParams.get("description") || undefined;
|
||||
if (!title && !description) {
|
||||
return new Response("no updates provided", { status: 400 });
|
||||
}
|
||||
|
||||
const issue = await updateIssue(Number(id), {
|
||||
title,
|
||||
description,
|
||||
});
|
||||
|
||||
return Response.json(issue);
|
||||
}
|
||||
Reference in New Issue
Block a user