refactor(core): Continue moving typeorm operators to repositories (no-changelog) (#8212)

Follow-up to: https://github.com/n8n-io/n8n/pull/8186
This commit is contained in:
Iván Ovejero
2024-01-05 13:06:24 +01:00
committed by GitHub
parent bed04ec122
commit 23a4ac96c0
10 changed files with 69 additions and 47 deletions

View File

@@ -15,7 +15,6 @@ import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
import { RoleService } from '@/services/role.service';
import type { EntityManager } from 'typeorm';
import { UserRepository } from '@/databases/repositories/user.repository';
@Service()
@@ -46,13 +45,6 @@ export class EnterpriseWorkflowService {
return { ownsWorkflow: true, workflow };
}
async share(transaction: EntityManager, workflow: WorkflowEntity, shareWithIds: string[]) {
const users = await this.userRepository.getByIds(transaction, shareWithIds);
const role = await this.roleService.findWorkflowEditorRole();
await this.sharedWorkflowRepository.share(transaction, workflow, users, role.id);
}
addOwnerAndSharings(workflow: WorkflowWithSharingsAndCredentials): void {
workflow.ownedBy = null;
workflow.sharedWith = [];

View File

@@ -35,6 +35,7 @@ import { WorkflowRepository } from '@/databases/repositories/workflow.repository
import type { RoleNames } from '@/databases/entities/Role';
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
import { CredentialsService } from '../credentials/credentials.service';
import { UserRepository } from '@/databases/repositories/user.repository';
export const workflowsController = express.Router();
@@ -428,7 +429,10 @@ workflowsController.put(
);
if (newShareeIds.length) {
await Container.get(EnterpriseWorkflowService).share(trx, workflow!, newShareeIds);
const users = await Container.get(UserRepository).getByIds(trx, newShareeIds);
const role = await Container.get(RoleService).findWorkflowEditorRole();
await Container.get(SharedWorkflowRepository).share(trx, workflow!, users, role.id);
}
});