full status implementation

This commit is contained in:
Oliver Bryan
2026-01-10 16:26:57 +00:00
parent fb96486da8
commit 364e4e0f64
22 changed files with 711 additions and 126 deletions

View File

@@ -1,13 +1,29 @@
import type { BunRequest } from "bun";
import { getOrganisationById, updateOrganisation } from "../../db/queries";
// /organisation/update?id=1&name=New%20Name&description=New%20Description&slug=new-slug
// /organisation/update?id=1&name=New%20Name&description=New%20Description&slug=new-slug&statuses=["TO DO","IN PROGRESS"]
export default async function organisationUpdate(req: BunRequest) {
const url = new URL(req.url);
const id = url.searchParams.get("id");
const name = url.searchParams.get("name") || undefined;
const description = url.searchParams.get("description") || undefined;
const slug = url.searchParams.get("slug") || undefined;
const statusesParam = url.searchParams.get("statuses");
let statuses: string[] | undefined;
if (statusesParam) {
try {
statuses = JSON.parse(statusesParam);
if (!Array.isArray(statuses) || !statuses.every((s) => typeof s === "string")) {
return new Response("statuses must be an array of strings", { status: 400 });
}
if (statuses.length === 0) {
return new Response("statuses must have at least one status", { status: 400 });
}
} catch {
return new Response("invalid statuses format (must be JSON array)", { status: 400 });
}
}
if (!id) {
return new Response("organisation id is required", { status: 400 });
@@ -23,8 +39,8 @@ export default async function organisationUpdate(req: BunRequest) {
return new Response(`organisation with id ${id} does not exist`, { status: 404 });
}
if (!name && !description && !slug) {
return new Response("at least one of name, description, or slug must be provided", {
if (!name && !description && !slug && !statuses) {
return new Response("at least one of name, description, slug, or statuses must be provided", {
status: 400,
});
}
@@ -33,6 +49,7 @@ export default async function organisationUpdate(req: BunRequest) {
name,
description,
slug,
statuses,
});
return Response.json(organisation);