refactor(core): Move typeorm operators from SourceControlExportService to repositories (no-changelog) (#8168)
Follow-up to: #8165
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Service } from 'typedi';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { DataSource, In, Repository } from 'typeorm';
|
||||
import { SharedCredentials } from '../entities/SharedCredentials';
|
||||
import type { User } from '../entities/User';
|
||||
|
||||
@@ -21,4 +21,13 @@ export class SharedCredentialsRepository extends Repository<SharedCredentials> {
|
||||
if (!sharedCredential) return null;
|
||||
return sharedCredential.credentials;
|
||||
}
|
||||
|
||||
async findByCredentialIds(credentialIds: string[]) {
|
||||
return this.find({
|
||||
relations: ['credentials', 'role', 'user'],
|
||||
where: {
|
||||
credentialsId: In(credentialIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,17 @@ export class SharedWorkflowRepository extends Repository<SharedWorkflow> {
|
||||
});
|
||||
return sharedWorkflows.map((sharing) => sharing.workflowId);
|
||||
}
|
||||
|
||||
async findByWorkflowIds(workflowIds: string[]) {
|
||||
return this.find({
|
||||
relations: ['role', 'user'],
|
||||
where: {
|
||||
role: {
|
||||
name: 'owner',
|
||||
scope: 'workflow',
|
||||
},
|
||||
workflowId: In(workflowIds),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async findByIds(workflowIds: string[]) {
|
||||
return this.find({ where: { id: In(workflowIds) } });
|
||||
}
|
||||
|
||||
async getActiveTriggerCount() {
|
||||
const totalTriggerCount = await this.sum('triggerCount', {
|
||||
active: true,
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
stringContainsExpression,
|
||||
} from './sourceControlHelper.ee';
|
||||
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { In } from 'typeorm';
|
||||
import type { SourceControlledFile } from './types/sourceControlledFile';
|
||||
import { VariablesService } from '../variables/variables.service.ee';
|
||||
import { TagRepository } from '@db/repositories/tag.repository';
|
||||
@@ -105,21 +104,9 @@ export class SourceControlExportService {
|
||||
try {
|
||||
sourceControlFoldersExistCheck([this.workflowExportFolder]);
|
||||
const workflowIds = candidates.map((e) => e.id);
|
||||
const sharedWorkflows = await Container.get(SharedWorkflowRepository).find({
|
||||
relations: ['role', 'user'],
|
||||
where: {
|
||||
role: {
|
||||
name: 'owner',
|
||||
scope: 'workflow',
|
||||
},
|
||||
workflowId: In(workflowIds),
|
||||
},
|
||||
});
|
||||
const workflows = await Container.get(WorkflowRepository).find({
|
||||
where: {
|
||||
id: In(workflowIds),
|
||||
},
|
||||
});
|
||||
const sharedWorkflows =
|
||||
await Container.get(SharedWorkflowRepository).findByWorkflowIds(workflowIds);
|
||||
const workflows = await Container.get(WorkflowRepository).findByIds(workflowIds);
|
||||
|
||||
// determine owner of each workflow to be exported
|
||||
const owners: Record<string, string> = {};
|
||||
@@ -241,12 +228,9 @@ export class SourceControlExportService {
|
||||
try {
|
||||
sourceControlFoldersExistCheck([this.credentialExportFolder]);
|
||||
const credentialIds = candidates.map((e) => e.id);
|
||||
const credentialsToBeExported = await Container.get(SharedCredentialsRepository).find({
|
||||
relations: ['credentials', 'role', 'user'],
|
||||
where: {
|
||||
credentialsId: In(credentialIds),
|
||||
},
|
||||
});
|
||||
const credentialsToBeExported = await Container.get(
|
||||
SharedCredentialsRepository,
|
||||
).findByCredentialIds(credentialIds);
|
||||
let missingIds: string[] = [];
|
||||
if (credentialsToBeExported.length !== credentialIds.length) {
|
||||
const foundCredentialIds = credentialsToBeExported.map((e) => e.credentialsId);
|
||||
|
||||
Reference in New Issue
Block a user