refactor(core): Use injectable classes for db repositories (part-1) (no-changelog) (#5953)

Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-04-12 10:59:14 +02:00
committed by GitHub
parent 323e26acfd
commit 10f8c35dbb
67 changed files with 557 additions and 270 deletions

View File

@@ -3,6 +3,7 @@ import type { INode, INodeCredentialsDetails } from 'n8n-workflow';
import { jsonParse } from 'n8n-workflow';
import fs from 'fs';
import glob from 'fast-glob';
import { Container } from 'typedi';
import type { EntityManager } from 'typeorm';
import { v4 as uuid } from 'uuid';
import config from '@/config';
@@ -12,8 +13,9 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { Role } from '@db/entities/Role';
import type { User } from '@db/entities/User';
import { setTagsForImport } from '@/TagHelpers';
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
import { RoleRepository } from '@db/repositories';
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
import { replaceInvalidCredentials } from '@/WorkflowHelpers';
import { BaseCommand, UM_FIX_INSTRUCTION } from '../BaseCommand';
@@ -205,9 +207,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
}
private async initOwnerWorkflowRole() {
const ownerWorkflowRole = await Db.collections.Role.findOne({
where: { name: 'owner', scope: 'workflow' },
});
const ownerWorkflowRole = await Container.get(RoleRepository).findWorkflowOwnerRole();
if (!ownerWorkflowRole) {
throw new Error(`Failed to find owner workflow role. ${UM_FIX_INSTRUCTION}`);
@@ -236,9 +236,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
}
private async getOwner() {
const ownerGlobalRole = await Db.collections.Role.findOne({
where: { name: 'owner', scope: 'global' },
});
const ownerGlobalRole = await Container.get(RoleRepository).findGlobalOwnerRole();
const owner =
ownerGlobalRole &&