mirror of
https://github.com/hex248/sprint.git
synced 2026-02-09 02:33:02 +00:00
Organisation and OrganisationMember routes
This commit is contained in:
39
packages/backend/src/routes/organisation/update.ts
Normal file
39
packages/backend/src/routes/organisation/update.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user