Skip to content

Commit

Permalink
Merge pull request #406 from rocket-admin/backend_microservices
Browse files Browse the repository at this point in the history
reworked google/github login
  • Loading branch information
Artuomka authored Oct 23, 2023
2 parents 8318f29 + 21fb04a commit 3969d69
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/common/data-injection.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 13 additions & 0 deletions backend/src/microservices/saas-microservice/saas.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ILoginUserWithGitHub,
ILoginUserWithGoogle,
ISaaSRegisterInvitedUser,
ISaasGetUsersInfosByEmail,
ISaasRegisterUser,
IUpdateUserStripeCustomerId,
} from './use-cases/saas-use-cases.interface.js';
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -111,6 +114,16 @@ export class SaasController {
return await this.getUserInfoByEmailUseCase.execute(inputData);
}

@ApiOperation({ summary: 'Get users infos by email webhook' })
@ApiBody({ type: Array<RegisterCompanyWebhookDS> })
@ApiResponse({
status: 200,
})
@Get('/users/email/:userEmail')
async getUsersInfoByEmail(@Param('userEmail') userEmail: string): Promise<Array<UserEntity>> {
return await this.getUsersInfosByEmailUseCase.execute(userEmail);
}

@ApiOperation({ summary: 'User register webhook' })
@ApiBody({ type: SaasUsualUserRegisterDS })
@ApiResponse({
Expand Down
5 changes: 5 additions & 0 deletions backend/src/microservices/saas-microservice/saas.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, Array<UserEntity>>
implements ISaasGetUsersInfosByEmail
{
constructor(
@Inject(BaseType.GLOBAL_DB_CONTEXT)
protected _dbContext: IGlobalDatabaseContext,
) {
super();
}

protected async implementation(userEmail: string): Promise<Array<UserEntity>> {
const foundUsers: Array<UserEntity> = await this._dbContext.userRepository.findAllUsersWithEmail(userEmail);
return foundUsers.map((user) => {
delete user.password;
return user;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface IGetUserInfoByEmail {
execute(inputData: GetUserInfoByEmailDS): Promise<UserEntity>;
}

export interface ISaasGetUsersInfosByEmail {
execute(userEmail: string): Promise<UserEntity[]>;
}

export interface ISaasRegisterUser {
execute(userData: SaasUsualUserRegisterDS): Promise<FoundUserDs>;
}
Expand Down

0 comments on commit 3969d69

Please sign in to comment.