export const userIsAdminOfOrg = async ({ userId, orgId }: UserOrgParams) => {
const user = await db.query.userTable.findFirst({
where: eq(userTable.id, userId),
with: {
organizationUsers: {
with: {
role: true,
},
},
},
});
if (!user) {
throw new Error("User not found");
}
const hasAccess = user.organizationUsers.some(
(orgUser) => orgUser.organizationId === orgId && orgUser.role.id === "manager",
);
if (!hasAccess) {
throw new Error("User is not admin of this organization");
}
};
export const userIsAdminOfOrg = async ({ userId, orgId }: UserOrgParams) => {
const user = await db.query.userTable.findFirst({
where: eq(userTable.id, userId),
with: {
organizationUsers: {
with: {
role: true,
},
},
},
});
if (!user) {
throw new Error("User not found");
}
const hasAccess = user.organizationUsers.some(
(orgUser) => orgUser.organizationId === orgId && orgUser.role.id === "manager",
);
if (!hasAccess) {
throw new Error("User is not admin of this organization");
}
};