* add eslint config * migrate autoLock to features * migrate teamService to features * migrate userCreationService * migrate insights services to features * migrate ProfileRepository * update imports * migrate filter segmen tests * migrate filter segment repository * migrate getBusyTimes * migrate getLocaleFromRequest * refactor csvUtils * make filename clearer * migrate getLuckyUser integration test * migrate autoLock test to features * wip * refactors * migrate useBookerUrl * migrate more * wip * Migrate eventTypeRepository * membership repository * update imports * update imports * migrate * move organization repository * update imports * update imports * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix tests * fix type checks * fix * fix * migrate * update imports * fix tests * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
|
|
import { isUsernameReservedDueToMigration } from "@calcom/lib/server/username";
|
|
import slugify from "@calcom/lib/slugify";
|
|
|
|
export async function checkRegularUsername(_username: string, currentOrgDomain?: string | null) {
|
|
const isCheckingUsernameInGlobalNamespace = !currentOrgDomain;
|
|
const username = slugify(_username);
|
|
|
|
const premium = !!process.env.NEXT_PUBLIC_IS_E2E && username.length < 5;
|
|
|
|
const profiles = currentOrgDomain
|
|
? await ProfileRepository.findManyByOrgSlugOrRequestedSlug({
|
|
orgSlug: currentOrgDomain,
|
|
usernames: [username],
|
|
})
|
|
: null;
|
|
|
|
const user = profiles?.length ? profiles[0].user : null;
|
|
|
|
if (user) {
|
|
return {
|
|
available: false as const,
|
|
premium,
|
|
message: "A user exists with that username",
|
|
};
|
|
}
|
|
|
|
const isUsernameAvailable = isCheckingUsernameInGlobalNamespace
|
|
? !(await isUsernameReservedDueToMigration(username))
|
|
: true;
|
|
|
|
return {
|
|
available: isUsernameAvailable,
|
|
premium,
|
|
};
|
|
}
|