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

@@ -3,6 +3,8 @@ import { CacheService } from './cache.service';
import { SharedWorkflowRepository, UserRepository } from '@/databases/repositories';
import type { User } from '@/databases/entities/User';
import { RoleService } from './role.service';
import type { ListQuery } from '@/requests';
import type { Role } from '@/databases/entities/Role';
@Service()
export class OwnershipService {
@@ -34,4 +36,17 @@ export class OwnershipService {
return sharedWorkflow.user;
}
addOwnedBy(
workflow: ListQuery.Workflow.WithSharing,
workflowOwnerRole: Role,
): ListQuery.Workflow.WithOwnership {
const { shared, ...rest } = workflow;
const ownerId = shared?.find((s) => s.roleId.toString() === workflowOwnerRole.id)?.userId;
return Object.assign(rest, {
ownedBy: ownerId ? { id: ownerId } : null,
});
}
}