* Add OmniInstall button * Make AppCards configurable by the app itself * Make OmniInstallAppButton not redirect * Fixes * Add extendsFeature support to CLI * Move to automatic file generation approach as dynamic import checking doesnt work correctly * Use zod everywhere consistenly for metadata and fix all TS issues * Fix viewer.eventTypes endpoint. Make prisma base select and _ prefixed models consistent in expecting scalars only * Remove unnecessary zod parsing of event-types as it is making the scope of the PR huge * Fix UI TS errors * wip * Add zod types support in EventTypeAppCard.tsx * Fixes during PR review and other failing tests * Remove unused app * Fix stripe installation flow * More fixes * Fix apps and active apps count * self review * Add loading attribute to OmniInsall button * Handle empty state * Improve types * Fix stripe app installation bug * added fathom app (#4804) * added fathom app wrapper, needs script injection to public booking page * new logo * Add Fathom script support on booking pages and add it as an eventTypeapp * Add automation and analytics apps * Add missing pieces for analytics category * Rename BookingPageScripts to BookingPageTagManager Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> * Fix lint error * Fix runtime error with legayAppData being undefined * Remove duplicate automation key Co-authored-by: Peer Richelsen <peeroke@gmail.com>
103 lines
2.4 KiB
TypeScript
103 lines
2.4 KiB
TypeScript
import { Prisma, UserPlan } from "@prisma/client";
|
|
|
|
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
|
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
export type TeamWithMembers = Awaited<ReturnType<typeof getTeamWithMembers>>;
|
|
export async function getTeamWithMembers(id?: number, slug?: string) {
|
|
const userSelect = Prisma.validator<Prisma.UserSelect>()({
|
|
username: true,
|
|
email: true,
|
|
name: true,
|
|
id: true,
|
|
plan: true,
|
|
bio: true,
|
|
});
|
|
const teamSelect = Prisma.validator<Prisma.TeamSelect>()({
|
|
id: true,
|
|
name: true,
|
|
slug: true,
|
|
logo: true,
|
|
bio: true,
|
|
hideBranding: true,
|
|
members: {
|
|
select: {
|
|
user: {
|
|
select: userSelect,
|
|
},
|
|
},
|
|
},
|
|
eventTypes: {
|
|
where: {
|
|
hidden: false,
|
|
},
|
|
select: {
|
|
users: {
|
|
select: userSelect,
|
|
},
|
|
metadata: true,
|
|
...baseEventTypeSelect,
|
|
},
|
|
},
|
|
});
|
|
|
|
const team = await prisma.team.findUnique({
|
|
where: id ? { id } : { slug },
|
|
select: teamSelect,
|
|
});
|
|
|
|
if (!team) return null;
|
|
const memberships = await prisma.membership.findMany({
|
|
where: {
|
|
teamId: team.id,
|
|
},
|
|
});
|
|
|
|
const members = team.members.map((obj) => {
|
|
const membership = memberships.find((membership) => obj.user.id === membership.userId);
|
|
return {
|
|
...obj.user,
|
|
isMissingSeat: obj.user.plan === UserPlan.FREE,
|
|
role: membership?.role,
|
|
accepted: membership?.accepted,
|
|
disableImpersonation: membership?.disableImpersonation,
|
|
};
|
|
});
|
|
|
|
const eventTypes = team.eventTypes.map((eventType) => ({
|
|
...eventType,
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
|
}));
|
|
return { ...team, eventTypes, members };
|
|
}
|
|
// also returns team
|
|
export async function isTeamAdmin(userId: number, teamId: number) {
|
|
return (
|
|
(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
OR: [{ role: "ADMIN" }, { role: "OWNER" }],
|
|
},
|
|
})) || false
|
|
);
|
|
}
|
|
export async function isTeamOwner(userId: number, teamId: number) {
|
|
return !!(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
role: "OWNER",
|
|
},
|
|
}));
|
|
}
|
|
|
|
export async function isTeamMember(userId: number, teamId: number) {
|
|
return !!(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
},
|
|
}));
|
|
}
|