refactor(core): Move remaining tags logic to service (no-changelog) (#6920)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2023-08-22 12:24:43 +02:00
committed by GitHub
parent 9e3e298aca
commit 9b9b891e68
10 changed files with 192 additions and 168 deletions

View File

@@ -11,14 +11,13 @@ import { SharedWorkflow } from '@db/entities/SharedWorkflow';
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 { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
import type { ICredentialsDb, IWorkflowToImport } from '@/Interfaces';
import { replaceInvalidCredentials } from '@/WorkflowHelpers';
import { BaseCommand, UM_FIX_INSTRUCTION } from '../BaseCommand';
import { generateNanoId } from '@db/utils/generators';
import { RoleService } from '@/services/role.service';
import { TagRepository } from '@/databases/repositories';
import { TagService } from '@/services/tag.service';
function assertHasWorkflowsToImport(workflows: unknown): asserts workflows is IWorkflowToImport[] {
if (!Array.isArray(workflows)) {
@@ -66,6 +65,8 @@ export class ImportWorkflowsCommand extends BaseCommand {
private transactionManager: EntityManager;
private tagService = Container.get(TagService);
async init() {
disableAutoGeneratedIds(WorkflowEntity);
await super.init();
@@ -93,7 +94,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
const user = flags.userId ? await this.getAssignee(flags.userId) : await this.getOwner();
const credentials = await Db.collections.Credentials.find();
const tags = await Container.get(TagRepository).find();
const tags = await this.tagService.getAll();
let totalImported = 0;
@@ -133,7 +134,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
}
if (Object.prototype.hasOwnProperty.call(workflow, 'tags')) {
await setTagsForImport(transactionManager, workflow, tags);
await this.tagService.setTagsForImport(transactionManager, workflow, tags);
}
if (workflow.active) {
@@ -183,7 +184,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
}
}
if (Object.prototype.hasOwnProperty.call(workflow, 'tags')) {
await setTagsForImport(transactionManager, workflow, tags);
await this.tagService.setTagsForImport(transactionManager, workflow, tags);
}
if (workflow.active) {
this.logger.info(