Organisation and OrganisationMember routes

This commit is contained in:
Oliver Bryan
2025-12-22 20:23:16 +00:00
parent 92866f1017
commit 474a929ffa
12 changed files with 307 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
import type { BunRequest } from "bun";
import { getOrganisationById, updateOrganisation } from "../../db/queries";
// /organisation/update?id=1&name=New%20Name&description=New%20Description&slug=new-slug
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;
if (!id) {
return new Response("organisation id is required", { status: 400 });
}
const organisationId = Number(id);
if (!Number.isInteger(organisationId)) {
return new Response("organisation id must be an integer", { status: 400 });
}
const existingOrganisation = await getOrganisationById(organisationId);
if (!existingOrganisation) {
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", {
status: 400,
});
}
const organisation = await updateOrganisation(organisationId, {
name,
description,
slug,
});
return Response.json(organisation);
}