feat(user): add organization count check before user deletion

This commit is contained in:
Mauricio Siu
2025-03-01 22:14:12 -06:00
parent adeb8498f9
commit 13eccaf8d9
2 changed files with 44 additions and 0 deletions

View File

@@ -313,4 +313,18 @@ export const userRouter = createTRPCRouter({
const apiKey = await createApiKey(ctx.user.id, input);
return apiKey;
}),
checkUserOrganizations: protectedProcedure
.input(
z.object({
userId: z.string(),
}),
)
.query(async ({ input }) => {
const organizations = await db.query.member.findMany({
where: eq(member.userId, input.userId),
});
return organizations.length;
}),
});