refactor(core): Inject dependencies into workflow services (no-changelog) (#8066)

Inject dependencies into workflow services (no-changelog)

Up next:

- ~~Make workflow services injectable~~ #8033
- ~~Inject dependencies into workflow services~~ (current)
- Consolidate workflow controllers into one
- Make workflow controller injectable
- Inject dependencies into workflow controller
This commit is contained in:
Iván Ovejero
2023-12-18 16:10:30 +01:00
committed by GitHub
parent a651089a10
commit 73d400a1bf
8 changed files with 127 additions and 80 deletions
@@ -27,6 +27,7 @@ import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import { InternalServerError } from '@/errors/response-errors/internal-server.error';
import { WorkflowService } from './workflow.service';
export const EEWorkflowController = express.Router();
@@ -67,14 +68,10 @@ EEWorkflowController.put(
workflow = undefined;
// Allow owners/admins to share
if (await req.user.hasGlobalScope('workflow:share')) {
const sharedRes = await Container.get(EnterpriseWorkflowService).getSharing(
req.user,
workflowId,
{
allowGlobalScope: true,
globalScope: 'workflow:share',
},
);
const sharedRes = await Container.get(WorkflowService).getSharing(req.user, workflowId, {
allowGlobalScope: true,
globalScope: 'workflow:share',
});
workflow = sharedRes?.workflow;
}
if (!workflow) {
@@ -132,9 +129,7 @@ EEWorkflowController.get(
relations.push('tags');
}
const enterpriseWorkflowService = Container.get(EnterpriseWorkflowService);
const workflow = await enterpriseWorkflowService.get({ id: workflowId }, { relations });
const workflow = await Container.get(WorkflowService).get({ id: workflowId }, { relations });
if (!workflow) {
throw new NotFoundError(`Workflow with ID "${workflowId}" does not exist`);
@@ -147,6 +142,8 @@ EEWorkflowController.get(
);
}
const enterpriseWorkflowService = Container.get(EnterpriseWorkflowService);
enterpriseWorkflowService.addOwnerAndSharings(workflow);
await enterpriseWorkflowService.addCredentialsToWorkflow(workflow, req.user);
return workflow;
@@ -253,7 +250,7 @@ EEWorkflowController.get(
try {
const sharedWorkflowIds = await WorkflowHelpers.getSharedWorkflowIds(req.user);
const { workflows: data, count } = await Container.get(EnterpriseWorkflowService).getMany(
const { workflows: data, count } = await Container.get(WorkflowService).getMany(
sharedWorkflowIds,
req.listQueryOptions,
);
@@ -283,7 +280,7 @@ EEWorkflowController.patch(
req.user,
);
const updatedWorkflow = await Container.get(EnterpriseWorkflowService).update(
const updatedWorkflow = await Container.get(WorkflowService).update(
req.user,
safeWorkflow,
workflowId,
@@ -313,7 +310,7 @@ EEWorkflowController.post(
req.body.workflowData.nodes = safeWorkflow.nodes;
}
return Container.get(EnterpriseWorkflowService).runManually(
return Container.get(WorkflowService).runManually(
req.body,
req.user,
GenericHelpers.getSessionId(req),