refactor(core): Move some typeorm operators to repositories (no-changelog) (#8139)

Moving some persistence logic to repositories to reduce circular
dependencies.
This commit is contained in:
Iván Ovejero
2023-12-22 13:35:23 +01:00
committed by GitHub
parent ab74bade05
commit c6dd935895
6 changed files with 133 additions and 118 deletions

View File

@@ -1,9 +1,8 @@
import type { DeleteResult, EntityManager } from 'typeorm';
import { In, Not } from 'typeorm';
import type { EntityManager } from 'typeorm';
import * as WorkflowHelpers from '@/WorkflowHelpers';
import { SharedWorkflow } from '@db/entities/SharedWorkflow';
import type { SharedWorkflow } from '@db/entities/SharedWorkflow';
import type { User } from '@db/entities/User';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { UserService } from '@/services/user.service';
import { WorkflowService } from './workflow.service';
import type {
@@ -48,29 +47,6 @@ export class EnterpriseWorkflowService {
return { ownsWorkflow: true, workflow };
}
async getSharings(
transaction: EntityManager,
workflowId: string,
relations = ['shared'],
): Promise<SharedWorkflow[]> {
const workflow = await transaction.findOne(WorkflowEntity, {
where: { id: workflowId },
relations,
});
return workflow?.shared ?? [];
}
async pruneSharings(
transaction: EntityManager,
workflowId: string,
userIds: string[],
): Promise<DeleteResult> {
return transaction.delete(SharedWorkflow, {
workflowId,
userId: Not(In(userIds)),
});
}
async share(
transaction: EntityManager,
workflow: WorkflowEntity,