mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
more project routes
This commit is contained in:
@@ -7,6 +7,10 @@ import issues from "./issues/all";
|
||||
import projectCreate from "./project/create";
|
||||
import projectUpdate from "./project/update";
|
||||
import projectDelete from "./project/delete";
|
||||
import projectsByOwner from "./project/by-owner";
|
||||
import projectsAll from "./project/all";
|
||||
import projectsWithOwners from "./project/with-owners";
|
||||
import projectWithOwner from "./project/with-owner";
|
||||
|
||||
export const routes = {
|
||||
issueCreate,
|
||||
@@ -19,4 +23,8 @@ export const routes = {
|
||||
projectCreate,
|
||||
projectUpdate,
|
||||
projectDelete,
|
||||
projectsByOwner,
|
||||
projectsAll,
|
||||
projectsWithOwners,
|
||||
projectWithOwner,
|
||||
};
|
||||
|
||||
9
packages/backend/src/routes/project/all.ts
Normal file
9
packages/backend/src/routes/project/all.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getAllProjects } from "../../db/queries";
|
||||
|
||||
// /projects/all
|
||||
export default async function projectsAll(req: BunRequest) {
|
||||
const projects = await getAllProjects();
|
||||
|
||||
return Response.json(projects);
|
||||
}
|
||||
26
packages/backend/src/routes/project/by-owner.ts
Normal file
26
packages/backend/src/routes/project/by-owner.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getProjectsByOwnerID, getUserById } from "../../db/queries";
|
||||
|
||||
// /projects/by-owner?ownerId=1
|
||||
export default async function projectsByOwner(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const ownerId = url.searchParams.get("ownerId");
|
||||
|
||||
if (!ownerId) {
|
||||
return new Response("ownerId is required", { status: 400 });
|
||||
}
|
||||
|
||||
const ownerIdNumber = Number(ownerId);
|
||||
if (!Number.isInteger(ownerIdNumber)) {
|
||||
return new Response("ownerId must be an integer", { status: 400 });
|
||||
}
|
||||
|
||||
const owner = await getUserById(ownerIdNumber);
|
||||
if (!owner) {
|
||||
return new Response(`user with id ${ownerId} not found`, { status: 404 });
|
||||
}
|
||||
|
||||
const projects = await getProjectsByOwnerID(owner.id);
|
||||
|
||||
return Response.json(projects);
|
||||
}
|
||||
24
packages/backend/src/routes/project/with-owner.ts
Normal file
24
packages/backend/src/routes/project/with-owner.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getProjectWithOwnerByID } from "../../db/queries";
|
||||
|
||||
// /project/with-owner?id=1
|
||||
export default async function projectWithOwnerByID(req: BunRequest) {
|
||||
const url = new URL(req.url);
|
||||
const id = url.searchParams.get("id");
|
||||
|
||||
if (!id) {
|
||||
return new Response("project id is required", { status: 400 });
|
||||
}
|
||||
|
||||
const projectId = Number(id);
|
||||
if (!Number.isInteger(projectId)) {
|
||||
return new Response("project id must be an integer", { status: 400 });
|
||||
}
|
||||
|
||||
const projectWithOwner = await getProjectWithOwnerByID(projectId);
|
||||
if (!projectWithOwner || !projectWithOwner.Project) {
|
||||
return new Response(`project with id ${id} not found`, { status: 404 });
|
||||
}
|
||||
|
||||
return Response.json(projectWithOwner);
|
||||
}
|
||||
9
packages/backend/src/routes/project/with-owners.ts
Normal file
9
packages/backend/src/routes/project/with-owners.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { BunRequest } from "bun";
|
||||
import { getProjectsWithOwners } from "../../db/queries";
|
||||
|
||||
// /projects/with-owners
|
||||
export default async function projectsWithOwners(req: BunRequest) {
|
||||
const projects = await getProjectsWithOwners();
|
||||
|
||||
return Response.json(projects);
|
||||
}
|
||||
Reference in New Issue
Block a user