mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
Project.blob -> Project.key
This commit is contained in:
@@ -4,7 +4,7 @@ import authRegister from "./auth/register";
|
||||
import issueCreate from "./issue/create";
|
||||
import issueDelete from "./issue/delete";
|
||||
import issueUpdate from "./issue/update";
|
||||
import issuesInProject from "./issues/[projectBlob]";
|
||||
import issuesInProject from "./issues/[projectKey]";
|
||||
import issues from "./issues/all";
|
||||
import organisationAddMember from "./organisation/add-member";
|
||||
import organisationById from "./organisation/by-id";
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { createIssue, getProjectByID, getProjectByBlob } from "../../db/queries";
|
||||
import { createIssue, getProjectByID, getProjectByKey } from "../../db/queries";
|
||||
|
||||
// /issue/create?projectId=1&title=Testing&description=Description
|
||||
// OR
|
||||
// /issue/create?projectBlob=projectBlob&title=Testing&description=Description
|
||||
// /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 projectBlob = url.searchParams.get("projectBlob");
|
||||
const projectKey = url.searchParams.get("projectKey");
|
||||
|
||||
let project = null;
|
||||
if (projectId) {
|
||||
project = await getProjectByID(Number(projectId));
|
||||
} else if (projectBlob) {
|
||||
project = await getProjectByBlob(projectBlob);
|
||||
} else if (projectKey) {
|
||||
project = await getProjectByKey(projectKey);
|
||||
} else {
|
||||
return new Response("missing project blob or project id", { status: 400 });
|
||||
return new Response("missing project key or project id", { status: 400 });
|
||||
}
|
||||
if (!project) {
|
||||
return new Response(`project not found: provided ${projectId ?? projectBlob}`, { status: 404 });
|
||||
return new Response(`project not found: provided ${projectId ?? projectKey}`, { status: 404 });
|
||||
}
|
||||
|
||||
const title = url.searchParams.get("title") || "Untitled Issue";
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getIssuesWithAssigneeByProject, getProjectByBlob } from "../../db/queries";
|
||||
import { getIssuesWithAssigneeByProject, getProjectByKey } from "../../db/queries";
|
||||
|
||||
export default async function issuesInProject(req: BunRequest<"/issues/:projectBlob">) {
|
||||
const { projectBlob } = req.params;
|
||||
export default async function issuesInProject(req: BunRequest<"/issues/:projectKey">) {
|
||||
const { projectKey } = req.params;
|
||||
|
||||
const project = await getProjectByBlob(projectBlob);
|
||||
const project = await getProjectByKey(projectKey);
|
||||
if (!project) {
|
||||
return new Response(`project not found: provided ${projectBlob}`, { status: 404 });
|
||||
return new Response(`project not found: provided ${projectKey}`, { status: 404 });
|
||||
}
|
||||
const issues = await getIssuesWithAssigneeByProject(project.id);
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { createProject, getProjectByBlob, getUserById } from "../../db/queries";
|
||||
import { createProject, getProjectByKey, getUserById } from "../../db/queries";
|
||||
|
||||
// /project/create?blob=BLOB&name=Testing&creatorId=1&organisationId=1
|
||||
// /project/create?key=KEY&name=Testing&creatorId=1&organisationId=1
|
||||
export default async function projectCreate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const blob = url.searchParams.get("blob");
|
||||
const key = url.searchParams.get("key");
|
||||
const name = url.searchParams.get("name");
|
||||
const creatorId = url.searchParams.get("creatorId");
|
||||
const organisationId = url.searchParams.get("organisationId");
|
||||
|
||||
if (!blob || !name || !creatorId || !organisationId) {
|
||||
if (!key || !name || !creatorId || !organisationId) {
|
||||
return new Response(
|
||||
`missing parameters: ${!blob ? "blob " : ""}${!name ? "name " : ""}${!creatorId ? "creatorId " : ""}${!organisationId ? "organisationId" : ""}`,
|
||||
`missing parameters: ${!key ? "key " : ""}${!name ? "name " : ""}${!creatorId ? "creatorId " : ""}${!organisationId ? "organisationId" : ""}`,
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// check if project with blob already exists in the organisation
|
||||
const existingProject = await getProjectByBlob(blob);
|
||||
// check if project with key already exists in the organisation
|
||||
const existingProject = await getProjectByKey(key);
|
||||
if (existingProject?.organisationId === parseInt(organisationId, 10)) {
|
||||
return new Response(`project with blob ${blob} already exists`, { status: 400 });
|
||||
return new Response(`project with key ${key} already exists`, { status: 400 });
|
||||
}
|
||||
|
||||
const creator = await getUserById(parseInt(creatorId, 10));
|
||||
@@ -27,7 +27,7 @@ export default async function projectCreate(req: BunRequest) {
|
||||
return new Response(`creator with id ${creatorId} not found`, { status: 404 });
|
||||
}
|
||||
|
||||
const project = await createProject(blob, name, creator.id, parseInt(organisationId, 10));
|
||||
const project = await createProject(key, name, creator.id, parseInt(organisationId, 10));
|
||||
|
||||
return Response.json(project);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getProjectByBlob, getProjectByID, getUserById, updateProject } from "../../db/queries";
|
||||
import { getProjectByID, getProjectByKey, getUserById, updateProject } from "../../db/queries";
|
||||
|
||||
// /project/update?id=1&blob=NEW&name=new%20name&creatorId=1&organisationId=1
|
||||
// /project/update?id=1&key=NEW&name=new%20name&creatorId=1&organisationId=1
|
||||
export default async function projectUpdate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
const blob = url.searchParams.get("blob") || undefined;
|
||||
const key = url.searchParams.get("key") || undefined;
|
||||
const name = url.searchParams.get("name") || undefined;
|
||||
const creatorId = url.searchParams.get("creatorId") || undefined;
|
||||
const organisationId = url.searchParams.get("organisationId") || undefined;
|
||||
@@ -19,15 +19,15 @@ export default async function projectUpdate(req: BunRequest) {
|
||||
return new Response(`project with id ${id} does not exist`, { status: 404 });
|
||||
}
|
||||
|
||||
if (!blob && !name && !creatorId && !organisationId) {
|
||||
return new Response(`at least one of blob, name, creatorId, or organisationId must be provided`, {
|
||||
if (!key && !name && !creatorId && !organisationId) {
|
||||
return new Response(`at least one of key, name, creatorId, or organisationId must be provided`, {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const projectWithBlob = blob ? await getProjectByBlob(blob) : null;
|
||||
if (projectWithBlob && projectWithBlob.id !== Number(id)) {
|
||||
return new Response(`a project with blob "${blob}" already exists`, { status: 400 });
|
||||
const projectWithKey = key ? await getProjectByKey(key) : null;
|
||||
if (projectWithKey && projectWithKey.id !== Number(id)) {
|
||||
return new Response(`a project with key "${key}" already exists`, { status: 400 });
|
||||
}
|
||||
|
||||
const newCreator = creatorId ? await getUserById(Number(creatorId)) : null;
|
||||
@@ -36,8 +36,8 @@ export default async function projectUpdate(req: BunRequest) {
|
||||
}
|
||||
|
||||
const project = await updateProject(Number(id), {
|
||||
blob: blob,
|
||||
name: name,
|
||||
key,
|
||||
name,
|
||||
creatorId: newCreator?.id,
|
||||
organisationId: organisationId ? Number(organisationId) : undefined,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user