delete gym working

This commit is contained in:
dimitar committed 2026-03-19 00:44:39 +01:00
1 parent 8cac57ed67
commit ffd3aabc55
3 files changed
+20 -10

No files matched your search

+10 -6
View File
@@ -30,7 +30,7 @@ export async function DELETE(
const { userId } = await auth();
if (!userId) {
return new NextResponse("Unauthorized", { status: 401 });
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Ensure user is synced
@@ -60,9 +60,10 @@ export async function DELETE(
// Only superAdmin can delete gyms
if (!currentUser || currentUser.role !== "superAdmin") {
return new NextResponse("Forbidden - Only superAdmin can delete gyms", {
status: 403,
});
return NextResponse.json(
{ error: "Forbidden - Only superAdmin can delete gyms" },
{ status: 403 },
);
}
await ensureGymsTable();
@@ -70,7 +71,7 @@ export async function DELETE(
// Check if gym exists
const gymRows = await db.all(sql`SELECT * FROM gyms WHERE id = ${gymId}`);
if (gymRows.length === 0) {
return new NextResponse("Gym not found", { status: 404 });
return NextResponse.json({ error: "Gym not found" }, { status: 404 });
}
// Soft delete - mark as inactive
@@ -84,6 +85,9 @@ export async function DELETE(
});
} catch (error) {
log.error("Failed to delete gym", error);
return new NextResponse("Internal Server Error", { status: 500 });
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
}
}