From eeb0322ce125c3fd7f18373757029d841dbac50c Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:09:56 +0300 Subject: [PATCH] fix: managed users check if exist (#14649) --- .../oauth-client-users/oauth-client-users.controller.ts | 5 ----- .../oauth-clients/services/oauth-clients-users.service.ts | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-client-users/oauth-client-users.controller.ts b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-client-users/oauth-client-users.controller.ts index 9a24f04ffc..12345efa5f 100644 --- a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-client-users/oauth-client-users.controller.ts +++ b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-client-users/oauth-client-users.controller.ts @@ -76,11 +76,6 @@ export class OAuthClientUsersController { this.logger.log( `Creating user with data: ${JSON.stringify(body, null, 2)} for OAuth Client with ID ${oAuthClientId}` ); - const existingUser = await this.userRepository.findByEmail(body.email); - - if (existingUser) { - throw new BadRequestException("A user with the provided email already exists."); - } const client = await this.oauthRepository.getOAuthClient(oAuthClientId); const isPlatformManaged = true; diff --git a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts index ec2753a95d..d4fd46fb5e 100644 --- a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts +++ b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts @@ -23,7 +23,7 @@ export class OAuthClientUsersService { isPlatformManaged: boolean, organizationId?: number ) { - const existsWithEmail = await this.userExistsWithEmail(oAuthClientId, body.email); + const existsWithEmail = await this.managedUserExistsWithEmail(oAuthClientId, body.email); if (existsWithEmail) { throw new BadRequestException("User with the provided e-mail already exists."); } @@ -73,7 +73,7 @@ export class OAuthClientUsersService { }; } - async userExistsWithEmail(oAuthClientId: string, email: string) { + async managedUserExistsWithEmail(oAuthClientId: string, email: string) { const oAuthEmail = this.getOAuthUserEmail(oAuthClientId, email); const user = await this.userRepository.findByEmail(oAuthEmail); return !!user;