Files
calendar/packages/lib/getOrgIdFromMemberOrTeamId.ts
T
2df2868b20 fix: cal ai webhook (#24368)
* fix: cal ai email

* fix: remove

* fix: org

* replace Cal AI with Cal.ai

* fix: use

* fix: feedback

* fix: types

* fix: types

* fix: types

* fix: tests

* Merge branch 'main' into fix/cal-ai-credits

* refactor: feedback

* refactor: imporvement

* fix: type

* refactor: feedback

* fix: tests

* fix: use pbac

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
2025-11-05 13:31:55 +04:00

79 lines
1.5 KiB
TypeScript

import { prisma, type PrismaTransaction } from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
const getOrgMemberOrTeamWhere = (memberId?: number | null, teamId?: number | null) => {
const conditions: Prisma.TeamWhereInput[] = [];
if (memberId) {
conditions.push({
AND: [
{
members: {
some: {
userId: memberId,
accepted: true,
},
},
},
{
isOrganization: true,
},
],
});
}
if (teamId) {
conditions.push({
AND: [
{
children: {
some: {
id: teamId,
},
},
},
{
isOrganization: true,
},
],
});
}
return {
OR: conditions,
};
};
export default async function getOrgIdFromMemberOrTeamId(
args: {
memberId?: number | null;
teamId?: number | null;
},
tx?: PrismaTransaction
) {
const client = tx ?? prisma;
const orgId = await client.team.findFirst({
where: getOrgMemberOrTeamWhere(args.memberId, args.teamId),
select: {
id: true,
},
});
return orgId?.id;
}
export async function getPublishedOrgIdFromMemberOrTeamId(args: {
memberId?: number | null;
teamId?: number | null;
}) {
const orgId = await prisma.team.findFirst({
where: {
...getOrgMemberOrTeamWhere(args.memberId, args.teamId),
slug: { not: null },
},
select: {
id: true,
},
});
return orgId?.id;
}