Migrates all tRPC code to a monorepo package (#3484)

* WIP

* WIP

* Type and migration fixes

* Adds missing default import

* Fixes import

* Fixes tRPC imports in App Store

* Migrate stripe helpers

* WIP

* Type fixes

* Type fix?

* Test fixes

* Adds missing stripe packages

* Moved queries to lib instead

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Omar Lópezandkodiakhq[bot] authored and GitHub committed 2022-07-22 11:27:06 -06:00
1 parent e82bcb6dba
commit 9447f16b82
152 files changed
+1066 -724

No files matched your search

@@ -0,0 +1,26 @@
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
export async function checkRegularUsername(_username: string) {
const username = slugify(_username);
const premium = !!process.env.NEXT_PUBLIC_IS_E2E && username.length < 5;
const user = await prisma.user.findUnique({
where: { username },
select: {
username: true,
},
});
if (user) {
return {
available: false as const,
premium,
message: "A user exists with that username",
};
}
return {
available: true as const,
premium,
};
}
+6
View File
@@ -0,0 +1,6 @@
import { checkPremiumUsername } from "@calcom/ee/lib/core/checkPremiumUsername";
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
import { checkRegularUsername } from "./checkRegularUsername";
export const checkUsername = IS_SELF_HOSTED ? checkRegularUsername : checkPremiumUsername;
+1
View File
@@ -0,0 +1 @@
export * from "./teams";
@@ -0,0 +1,90 @@
import { Prisma, UserPlan } from "@prisma/client";
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
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,
},
...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,
};
});
return { ...team, 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",
},
}));
}