Skip to content

Commit

Permalink
Merge pull request #759 from rocket-admin/backend_refactoring
Browse files Browse the repository at this point in the history
Backend refactoring
  • Loading branch information
Artuomka authored Jul 29, 2024
2 parents 76f9c09 + 375cfc8 commit 49aa09f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export class FoundTablesWithPermissionsDs {
@ApiProperty()
display_name: string;

@ApiProperty()
@ApiProperty({ type: FoundTablePermissionsDs })
accessLevel: FoundTablePermissionsDs;
}

export class FoundPermissionsInConnectionDs {
@ApiProperty()
@ApiProperty({ type: FoundConnectionPermissionsDs })
connection: FoundConnectionPermissionsDs;

@ApiProperty()
@ApiProperty({ type: FoundConnectionGroupPermissionDs })
group: FoundConnectionGroupPermissionDs;

@ApiProperty({ isArray: true, type: FoundTablesWithPermissionsDs })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class TokenDs {
@ApiProperty()
token: string;
}
5 changes: 4 additions & 1 deletion backend/src/entities/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { UpdateMasterPasswordRequestBodyDto } from './application/dto/update-mas
import { FoundOneConnectionDs } from './application/data-structures/found-one-connection.ds.js';
import { FoundGroupResponseDto } from '../group/dto/found-group-response.dto.js';
import { FoundUserGroupsInConnectionDTO } from './application/dto/found-user-groups-in-connection.dto.js';
import { SuccessResponse } from '../../microservices/saas-microservice/data-structures/common-responce.ds.js';

@UseInterceptors(SentryInterceptor)
@Controller()
Expand Down Expand Up @@ -520,13 +521,15 @@ export class ConnectionController {
@ApiBody({ type: UpdateMasterPasswordDs })
@ApiResponse({
status: 200,
type: SuccessResponse,
description: 'Connection master password was updated.',
})
@UseGuards(ConnectionEditGuard)
@Put('/connection/encryption/update/:connectionId')
async updateConnectionMasterPwd(
@SlugUuid('connectionId') connectionId: string,
@Body() passwordData: UpdateMasterPasswordRequestBodyDto,
): Promise<boolean> {
): Promise<SuccessResponse> {
if (!connectionId) {
throw new BadRequestException(Messages.CONNECTION_ID_MISSING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { BaseType } from '../../../common/data-injection.tokens.js';
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
import { UpdateMasterPasswordDs } from '../application/data-structures/update-master-password.ds.js';
import { IUpdateMasterPassword } from './use-cases.interfaces.js';
import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js';

@Injectable()
export class UpdateConnectionMasterPasswordUseCase
extends AbstractUseCase<UpdateMasterPasswordDs, boolean>
extends AbstractUseCase<UpdateMasterPasswordDs, SuccessResponse>
implements IUpdateMasterPassword
{
constructor(
Expand All @@ -18,11 +19,11 @@ export class UpdateConnectionMasterPasswordUseCase
super();
}

protected async implementation(inputData: UpdateMasterPasswordDs): Promise<boolean> {
protected async implementation(inputData: UpdateMasterPasswordDs): Promise<SuccessResponse> {
const { connectionId, newMasterPwd, oldMasterPwd } = inputData;
let connection = await this._dbContext.connectionRepository.findAndDecryptConnection(connectionId, oldMasterPwd);
connection = Encryptor.encryptConnectionCredentials(connection, newMasterPwd);
const updatedConnection = await this._dbContext.connectionRepository.saveNewConnection(connection);
return !!updatedConnection;
return { success: !!updatedConnection };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { InTransactionEnum } from '../../../enums/index.js';
import { FoundOneConnectionDs } from '../application/data-structures/found-one-connection.ds.js';
import { FoundGroupResponseDto } from '../../group/dto/found-group-response.dto.js';
import { FoundUserGroupsInConnectionDTO } from '../application/dto/found-user-groups-in-connection.dto.js';
import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js';

export interface IFindConnections {
execute(user: CreateUserDs, inTransaction: InTransactionEnum): Promise<FoundConnectionsDs>;
Expand Down Expand Up @@ -74,7 +75,7 @@ export interface ITestConnection {
}

export interface IUpdateMasterPassword {
execute(inputData: UpdateMasterPasswordDs, inTransaction: InTransactionEnum): Promise<boolean>;
execute(inputData: UpdateMasterPasswordDs, inTransaction: InTransactionEnum): Promise<SuccessResponse>;
}

export interface IRestoreConnection {
Expand Down

0 comments on commit 49aa09f

Please sign in to comment.