mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
21 lines
859 B
TypeScript
21 lines
859 B
TypeScript
import { OrgCreateRequestSchema } from "@issue/shared";
|
|
import type { AuthedRequest } from "../../auth/middleware";
|
|
import { createOrganisationWithOwner, getOrganisationBySlug } from "../../db/queries";
|
|
import { errorResponse, parseJsonBody } from "../../validation";
|
|
|
|
export default async function organisationCreate(req: AuthedRequest) {
|
|
const parsed = await parseJsonBody(req, OrgCreateRequestSchema);
|
|
if ("error" in parsed) return parsed.error;
|
|
|
|
const { name, slug, description } = parsed.data;
|
|
|
|
const existingOrganisation = await getOrganisationBySlug(slug);
|
|
if (existingOrganisation) {
|
|
return errorResponse(`organisation with slug "${slug}" already exists`, "SLUG_TAKEN", 409);
|
|
}
|
|
|
|
const organisation = await createOrganisationWithOwner(name, slug, req.userId, description);
|
|
|
|
return Response.json(organisation);
|
|
}
|