-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Create UserCreationService
and use in API V1 create user endpoint
#19150
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
identityProvider?: IdentityProvider; | ||
} | ||
|
||
export class UserCreationService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what we are looking for with application services coordinating these calls. Very nice.
const password = createHash("md5").update(`${email}${process.env.CALENDSO_ENCRYPTION_KEY}`).digest("hex"); | ||
const hashedPassword = await hashPassword(password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this business logic to the service
const t = await getTranslation("en", "common"); | ||
const availability = getAvailabilityFromSchedule(DEFAULT_SCHEDULE); | ||
|
||
return await prisma.user.create({ | ||
data: { | ||
username: slugify(username), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also moving this business logic to the service
locked: boolean; | ||
} | ||
) { | ||
const organizationId = data.organizationId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to get organizationId
like this because typescript may see organizationId
as a part of the ...rest
below
import slugify from "../../slugify"; | ||
import { UserRepository } from "../repository/user"; | ||
|
||
interface CreateUserInput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the service I don't want any dependence on Prisma so I'm declaring the input here. When calling the UserRepository
the type is Prisma.UserCreateInput
so it'll throw an type error if this input is misalligned with what Prisma expects.
static async createUser(data: CreateUserInput) { | ||
const { email, password, username } = data; | ||
|
||
const shouldLockByDefault = await checkIfEmailIsBlockedInWatchlistController(email); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're introducing this service, we'll check the watchlist for any blocked emails/domains whenever we create a new user.
const { locked, ...rest } = user; | ||
|
||
return rest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't return the locked status back to the user
@@ -90,6 +90,7 @@ export class OrganizationRepository { | |||
email: owner.email, | |||
username: ownerUsernameInOrg, | |||
organizationId: organization.id, | |||
locked: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll check the new org owner against the watch list in this PR #19201
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (02/10/25)1 reviewer was added to this PR based on Keith Williams's automation. |
E2E results are ready! |
What does this PR do?
UserCreationService
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist