n8n/packages/cli/src/executions/execution.service.ee.ts
Iván Ovejero 52f27a76ac
refactor(core): Move workflow repository to @n8n/db (#15260)
Co-authored-by: Ricardo Espinoza <ricardo@n8n.io>
2025-05-13 14:21:59 +02:00

50 lines
1.6 KiB
TypeScript

import type { WorkflowWithSharingsAndCredentials, IExecutionResponse } from '@n8n/db';
import { WorkflowRepository } from '@n8n/db';
import { Service } from '@n8n/di';
import type { IExecutionFlattedResponse } from '@/interfaces';
import { ExecutionService } from './execution.service';
import type { ExecutionRequest } from './execution.types';
import { EnterpriseWorkflowService } from '../workflows/workflow.service.ee';
@Service()
export class EnterpriseExecutionsService {
constructor(
private readonly executionService: ExecutionService,
private readonly workflowRepository: WorkflowRepository,
private readonly enterpriseWorkflowService: EnterpriseWorkflowService,
) {}
async findOne(
req: ExecutionRequest.GetOne,
sharedWorkflowIds: string[],
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> {
const execution = await this.executionService.findOne(req, sharedWorkflowIds);
if (!execution) return;
const workflow = (await this.workflowRepository.get({
id: execution.workflowId,
})) as WorkflowWithSharingsAndCredentials;
if (!workflow) return;
const workflowWithSharingsMetaData =
this.enterpriseWorkflowService.addOwnerAndSharings(workflow);
await this.enterpriseWorkflowService.addCredentialsToWorkflow(
workflowWithSharingsMetaData,
req.user,
);
execution.workflowData = {
...execution.workflowData,
homeProject: workflowWithSharingsMetaData.homeProject,
sharedWithProjects: workflowWithSharingsMetaData.sharedWithProjects,
usedCredentials: workflowWithSharingsMetaData.usedCredentials,
} as WorkflowWithSharingsAndCredentials;
return execution;
}
}