refactor(core): Update workflowRepository.getMany to use query builder (no-changelog) (#13207)

This commit is contained in:
Ricardo Espinoza
2025-02-17 08:59:42 -05:00
committed by GitHub
parent d1e65a1cd5
commit 5b82f34773
3 changed files with 350 additions and 96 deletions

View File

@@ -2,6 +2,7 @@ import { Container } from '@n8n/di';
import type { IWorkflowBase } from 'n8n-workflow';
import type { TagEntity } from '@/databases/entities/tag-entity';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { TagRepository } from '@/databases/repositories/tag.repository';
import { WorkflowTagMappingRepository } from '@/databases/repositories/workflow-tag-mapping.repository';
import { generateNanoId } from '@/databases/utils/generators';
@@ -25,3 +26,27 @@ export async function createTag(attributes: Partial<TagEntity> = {}, workflow?:
return tag;
}
export async function assignTagToWorkflow(tag: TagEntity, workflow: WorkflowEntity) {
const mappingRepository = Container.get(WorkflowTagMappingRepository);
// Check if mapping already exists
const existingMapping = await mappingRepository.findOne({
where: {
tagId: tag.id,
workflowId: workflow.id,
},
});
if (existingMapping) {
return existingMapping;
}
// Create new mapping
const mapping = mappingRepository.create({
tagId: tag.id,
workflowId: workflow.id,
});
return await mappingRepository.save(mapping);
}