mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(organization): prevent deletion of last owned organization
This commit is contained in:
@@ -133,6 +133,18 @@ export const organizationRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ownerOrgs = await db.query.organization.findMany({
|
||||||
|
where: eq(organization.ownerId, ctx.user.id),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ownerOrgs.length <= 1) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "FORBIDDEN",
|
||||||
|
message:
|
||||||
|
"You must maintain at least one organization where you are the owner",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const result = await db
|
const result = await db
|
||||||
.delete(organization)
|
.delete(organization)
|
||||||
.where(eq(organization.id, input.organizationId));
|
.where(eq(organization.id, input.organizationId));
|
||||||
|
|||||||
Reference in New Issue
Block a user