diff --git a/backend/src/common/data-injection.tokens.ts b/backend/src/common/data-injection.tokens.ts index ba419909..81394629 100644 --- a/backend/src/common/data-injection.tokens.ts +++ b/backend/src/common/data-injection.tokens.ts @@ -116,6 +116,7 @@ export enum UseCaseType { SAAS_ADD_COMPANY_ID_TO_USER = 'SAAS_ADD_COMPANY_ID_TO_USER', SAAS_REMOVE_COMPANY_ID_FROM_USER = 'SAAS_REMOVE_COMPANY_ID_FROM_USER', SAAS_REGISTER_INVITED_USER = 'SAAS_REGISTER_INVITED_USER', + SAAS_SAAS_GET_USERS_INFOS_BY_EMAIL = 'SAAS_SAAS_GET_USERS_INFOS_BY_EMAIL', INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP', VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP = 'VERIFY_INVITE_USER_IN_COMPANY_AND_CONNECTION_GROUP', diff --git a/backend/src/microservices/saas-microservice/saas.controller.ts b/backend/src/microservices/saas-microservice/saas.controller.ts index fedb4589..655e2dd5 100644 --- a/backend/src/microservices/saas-microservice/saas.controller.ts +++ b/backend/src/microservices/saas-microservice/saas.controller.ts @@ -10,6 +10,7 @@ import { ILoginUserWithGitHub, ILoginUserWithGoogle, ISaaSRegisterInvitedUser, + ISaasGetUsersInfosByEmail, ISaasRegisterUser, IUpdateUserStripeCustomerId, } from './use-cases/saas-use-cases.interface.js'; @@ -40,6 +41,8 @@ export class SaasController { private readonly getUserInfoUseCase: IGetUserInfo, @Inject(UseCaseType.SAAS_GET_USER_INFO_BY_EMAIL) private readonly getUserInfoByEmailUseCase: IGetUserInfoByEmail, + @Inject(UseCaseType.SAAS_SAAS_GET_USERS_INFOS_BY_EMAIL) + private readonly getUsersInfosByEmailUseCase: ISaasGetUsersInfosByEmail, @Inject(UseCaseType.SAAS_USUAL_REGISTER_USER) private readonly usualRegisterUserUseCase: ISaasRegisterUser, @Inject(UseCaseType.SAAS_LOGIN_USER_WITH_GOOGLE) @@ -111,6 +114,16 @@ export class SaasController { return await this.getUserInfoByEmailUseCase.execute(inputData); } + @ApiOperation({ summary: 'Get users infos by email webhook' }) + @ApiBody({ type: Array }) + @ApiResponse({ + status: 200, + }) + @Get('/users/email/:userEmail') + async getUsersInfoByEmail(@Param('userEmail') userEmail: string): Promise> { + return await this.getUsersInfosByEmailUseCase.execute(userEmail); + } + @ApiOperation({ summary: 'User register webhook' }) @ApiBody({ type: SaasUsualUserRegisterDS }) @ApiResponse({ diff --git a/backend/src/microservices/saas-microservice/saas.module.ts b/backend/src/microservices/saas-microservice/saas.module.ts index 21ab1f46..bef4270c 100644 --- a/backend/src/microservices/saas-microservice/saas.module.ts +++ b/backend/src/microservices/saas-microservice/saas.module.ts @@ -14,6 +14,7 @@ import { UpdateUserStripeCustomerIdUseCase } from './use-cases/UpdateUserStripeC import { AddCompanyIdToUserUseCase } from './use-cases/add-company-id-to-user-use.case.js'; import { RemoveCompanyIdFromUserUseCase } from './use-cases/remove-company-id-from-user.use.case.js'; import { SaasRegisterInvitedUserUseCase } from './use-cases/register-invited-user-use.case.js'; +import { GetUsersInfosByEmailUseCase } from './use-cases/get-users-infos-by-email.use.case.js'; @Module({ imports: [], @@ -66,6 +67,10 @@ import { SaasRegisterInvitedUserUseCase } from './use-cases/register-invited-use provide: UseCaseType.SAAS_REGISTER_INVITED_USER, useClass: SaasRegisterInvitedUserUseCase, }, + { + provide: UseCaseType.SAAS_SAAS_GET_USERS_INFOS_BY_EMAIL, + useClass: GetUsersInfosByEmailUseCase, + }, ], controllers: [SaasController], exports: [], diff --git a/backend/src/microservices/saas-microservice/use-cases/get-users-infos-by-email.use.case.ts b/backend/src/microservices/saas-microservice/use-cases/get-users-infos-by-email.use.case.ts new file mode 100644 index 00000000..4dfd057d --- /dev/null +++ b/backend/src/microservices/saas-microservice/use-cases/get-users-infos-by-email.use.case.ts @@ -0,0 +1,26 @@ +import { Inject } from '@nestjs/common'; +import AbstractUseCase from '../../../common/abstract-use.case.js'; +import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; +import { BaseType } from '../../../common/data-injection.tokens.js'; +import { UserEntity } from '../../../entities/user/user.entity.js'; +import { ISaasGetUsersInfosByEmail } from './saas-use-cases.interface.js'; + +export class GetUsersInfosByEmailUseCase + extends AbstractUseCase> + implements ISaasGetUsersInfosByEmail +{ + constructor( + @Inject(BaseType.GLOBAL_DB_CONTEXT) + protected _dbContext: IGlobalDatabaseContext, + ) { + super(); + } + + protected async implementation(userEmail: string): Promise> { + const foundUsers: Array = await this._dbContext.userRepository.findAllUsersWithEmail(userEmail); + return foundUsers.map((user) => { + delete user.password; + return user; + }); + } +} diff --git a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts index d1384f8b..639c0b48 100644 --- a/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts +++ b/backend/src/microservices/saas-microservice/use-cases/saas-use-cases.interface.ts @@ -24,6 +24,10 @@ export interface IGetUserInfoByEmail { execute(inputData: GetUserInfoByEmailDS): Promise; } +export interface ISaasGetUsersInfosByEmail { + execute(userEmail: string): Promise; +} + export interface ISaasRegisterUser { execute(userData: SaasUsualUserRegisterDS): Promise; }