Voeg bewerken van sociaal ondernemer toe (naam en slug)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,3 +57,25 @@ export async function deleteTenant(formData: FormData) {
|
||||
|
||||
redirect("/tenants");
|
||||
}
|
||||
|
||||
export async function updateTenant(formData: FormData) {
|
||||
const session = await getSession();
|
||||
if (!session) redirect("/login");
|
||||
|
||||
const accountId = Number(formData.get("account_id"));
|
||||
const name = ((formData.get("name") as string) ?? "").trim();
|
||||
const slug = ((formData.get("slug") as string) ?? "").trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
||||
|
||||
if (!accountId) redirect("/tenants");
|
||||
if (!name || !slug) redirect(`/tenants/${accountId}?error=missing`);
|
||||
|
||||
const db = getPlatformDb();
|
||||
const existing = db
|
||||
.prepare("SELECT id FROM accounts WHERE slug = ? AND id != ?")
|
||||
.get(slug, accountId);
|
||||
if (existing) redirect(`/tenants/${accountId}?error=slug`);
|
||||
|
||||
db.prepare("UPDATE accounts SET name = ?, slug = ? WHERE id = ?").run(name, slug, accountId);
|
||||
|
||||
redirect("/tenants");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user