refactor: Consolidate WorkflowService.getMany() (no-changelog) (#6892)

In scope:

- Consolidate `WorkflowService.getMany()`.
- Support non-entity field `ownedBy` for `select`.
- Support `tags` for `filter`.
- Move `addOwnerId` to `OwnershipService`.
- Remove unneeded check for `filter.id`.
- Simplify DTO validation for `filter` and `select`.
- Expand tests for `GET /workflows`.

Workflow list query DTOs:

```
filter → name, active, tags
select → id, name, active, tags, createdAt, updatedAt, versionId, ownedBy
```

Out of scope:

- Migrate `shared_workflow.roleId` and `shared_credential.roleId` to
string IDs.
- Refactor `WorkflowHelpers.getSharedWorkflowIds()`.
This commit is contained in:
Iván Ovejero
2023-08-22 13:19:37 +02:00
committed by GitHub
parent f32e993227
commit 2cfa6d344e
20 changed files with 686 additions and 318 deletions

View File

@@ -35,7 +35,7 @@ import type { ExecutionData } from '@db/entities/ExecutionData';
import { generateNanoId } from '@db/utils/generators';
import { RoleService } from '@/services/role.service';
import { VariablesService } from '@/environments/variables/variables.service';
import { TagRepository } from '@/databases/repositories';
import { TagRepository, WorkflowTagMappingRepository } from '@/databases/repositories';
import { separate } from '@/utils';
export type TestDBType = 'postgres' | 'mysql';
@@ -119,6 +119,7 @@ export async function truncate(collections: CollectionName[]) {
if (tag) {
await Container.get(TagRepository).delete({});
await Container.get(WorkflowTagMappingRepository).delete({});
}
for (const collection of rest) {
@@ -389,14 +390,24 @@ export async function createWaitingExecution(workflow: WorkflowEntity) {
// Tags
// ----------------------------------
export async function createTag(attributes: Partial<TagEntity> = {}) {
export async function createTag(attributes: Partial<TagEntity> = {}, workflow?: WorkflowEntity) {
const { name } = attributes;
return Container.get(TagRepository).save({
const tag = await Container.get(TagRepository).save({
id: generateNanoId(),
name: name ?? randomName(),
...attributes,
});
if (workflow) {
const mappingRepository = Container.get(WorkflowTagMappingRepository);
const mapping = mappingRepository.create({ tagId: tag.id, workflowId: workflow.id });
await mappingRepository.save(mapping);
}
return tag;
}
// ----------------------------------