import "../../../../../base64-CmWvODNW.mjs";
import "../../../../../types-CuW0zWDA.mjs";
import "../../../../../byline-registry-BOjqDOim.mjs";
import { a as unwrapResult, i as requireDb } from "../../../../../error-CkAseSqZ.mjs";
import { n as parseBody, t as isParseError } from "../../../../../parse-GmjecGct.mjs";
import "../../../../../redirects-DXEXBAII.mjs";
import { t as bylineFieldCreateBody } from "../../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../../status-CqJQX1QN.mjs";
import "../../../../../api/schemas/index.mjs";
import { n as requirePerm } from "../../../../../authorize-Dz88F_Fw.mjs";
import { i as handleBylineFieldList, t as handleBylineFieldCreate } from "../../../../../byline-fields-CIx_GuN4.mjs";

//#region src/astro/routes/api/admin/byline-fields/index.ts
const prerender = false;
const GET = async ({ locals }) => {
	const { emdash, user } = locals;
	const denied = requirePerm(user, "schema:read");
	if (denied) return denied;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	return unwrapResult(await handleBylineFieldList(emdash.db));
};
const POST = async ({ request, locals }) => {
	const { emdash, user } = locals;
	const denied = requirePerm(user, "schema:manage");
	if (denied) return denied;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const body = await parseBody(request, bylineFieldCreateBody);
	if (isParseError(body)) return body;
	return unwrapResult(await handleBylineFieldCreate(emdash.db, {
		slug: body.slug,
		label: body.label,
		type: body.type,
		required: body.required,
		translatable: body.translatable,
		validation: body.validation ?? null,
		sortOrder: body.sortOrder
	}), 201);
};

//#endregion
export { GET, POST, prerender };
//# sourceMappingURL=index.mjs.map