mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02: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:
32
packages/backend/src/routes/project/create.ts
Normal file
32
packages/backend/src/routes/project/create.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { createProject, getUserById, getProjectByBlob } from "../../db/queries";
|
||||
|
||||
// /project/create?blob=BLOB&name=Testing&ownerId=1
|
||||
export default async function projectCreate(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const blob = url.searchParams.get("blob");
|
||||
const name = url.searchParams.get("name");
|
||||
const ownerId = url.searchParams.get("ownerId");
|
||||
|
||||
if (!blob || !name || !ownerId) {
|
||||
return new Response(
|
||||
`missing parameters: ${!blob ? "blob " : ""}${!name ? "name " : ""}${!ownerId ? "ownerId" : ""}`,
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// check if project with blob already exists
|
||||
const existingProject = await getProjectByBlob(blob);
|
||||
if (existingProject) {
|
||||
return new Response(`project with blob ${blob} already exists`, { status: 400 });
|
||||
}
|
||||
|
||||
const owner = await getUserById(parseInt(ownerId, 10));
|
||||
if (!owner) {
|
||||
return new Response(`owner with id ${ownerId} not found`, { status: 404 });
|
||||
}
|
||||
|
||||
const project = await createProject(blob, name, owner.id);
|
||||
|
||||
return Response.json(project);
|
||||
}
|
||||
Reference in New Issue
Block a user