Files
calendar/packages/lib/server/checkRegularUsername.ts
T
Omar LópezGitHubkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
9447f16b82 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>
2022-07-22 11:27:06 -06:00

27 lines
579 B
TypeScript

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,
};
}