feat(organization): prevent deletion of last owned organization
Some checks failed
Auto PR to main when version changes / create-pr (push) Has been cancelled
Build Docker images / build-and-push-cloud-image (push) Has been cancelled
Build Docker images / build-and-push-schedule-image (push) Has been cancelled
Build Docker images / build-and-push-server-image (push) Has been cancelled
Dokploy Docker Build / docker-amd (push) Has been cancelled
Dokploy Docker Build / docker-arm (push) Has been cancelled
Dokploy Monitoring Build / docker-amd (push) Has been cancelled
Dokploy Monitoring Build / docker-arm (push) Has been cancelled
Dokploy Docker Build / combine-manifests (push) Has been cancelled
Dokploy Docker Build / generate-release (push) Has been cancelled
Dokploy Monitoring Build / combine-manifests (push) Has been cancelled

This commit is contained in:
Mauricio Siu 2025-03-02 22:32:56 -06:00
parent 4da4e1c17d
commit 5db7508530

View File

@ -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
.delete(organization)
.where(eq(organization.id, input.organizationId));