Files
cal.diy/packages/features/users/services/userCreationService.ts
T
Benny Joo ff38d6c7db refactor: Remove circular deps between @calcom/lib and @calcom/features [1] (#24399)
* 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
2025-10-13 12:01:02 -03:00

56 lines
1.8 KiB
TypeScript

import { checkIfEmailIsBlockedInWatchlistController } from "@calcom/features/watchlist/operations/check-if-email-in-watchlist.controller";
import { hashPassword } from "@calcom/lib/auth/hashPassword";
import logger from "@calcom/lib/logger";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import type { CreationSource, UserPermissionRole, IdentityProvider } from "@calcom/prisma/enums";
interface CreateUserInput {
email: string;
username: string;
name?: string | null;
password?: string;
brandColor?: string;
darkBrandColor?: string;
hideBranding?: boolean;
weekStart?: string;
timeZone?: string;
theme?: string | null;
timeFormat?: number;
locale?: string;
avatar?: string;
organizationId?: number | null;
creationSource: CreationSource;
role?: UserPermissionRole;
emailVerified?: Date;
identityProvider?: IdentityProvider;
}
const log = logger.getSubLogger({ prefix: ["[userCreationService]"] });
export class UserCreationService {
static async createUser({ data }: { data: CreateUserInput }) {
const { email, password, username } = data;
const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController(email);
const hashedPassword = password ? await hashPassword(password) : null;
const userRepo = new UserRepository(prisma);
const user = await userRepo.create({
...data,
username: slugify(username),
...(hashedPassword && { hashedPassword }),
organizationId: data?.organizationId ?? null,
locked: shouldLockByDefault,
});
log.info(`Created user: ${user.id} with locked status of ${user.locked}`);
const { locked, ...restUser } = user;
return restUser;
}
}