refactor(core): Use DI in execution services (no-changelog) (#8358)

This commit is contained in:
Iván Ovejero
2024-01-17 15:42:19 +01:00
committed by GitHub
parent 01280815c9
commit 2eb829a6b4
9 changed files with 101 additions and 106 deletions

View File

@@ -1,31 +1,53 @@
import { ExecutionRequest } from './execution.request';
import { ExecutionsService } from './executions.service';
import { ExecutionService } from './execution.service';
import { Authorized, Get, Post, RestController } from '@/decorators';
import { EnterpriseExecutionsService } from './executions.service.ee';
import { EnterpriseExecutionsService } from './execution.service.ee';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { WorkflowSharingService } from '@/workflows/workflowSharing.service';
import type { User } from '@/databases/entities/User';
@Authorized()
@RestController('/executions')
export class ExecutionsController {
constructor(
private readonly executionService: ExecutionService,
private readonly enterpriseExecutionService: EnterpriseExecutionsService,
private readonly workflowSharingService: WorkflowSharingService,
) {}
private async getAccessibleWorkflowIds(user: User) {
return isSharingEnabled()
? this.workflowSharingService.getSharedWorkflowIds(user)
: this.workflowSharingService.getSharedWorkflowIds(user, ['owner']);
}
@Get('/')
async getExecutionsList(req: ExecutionRequest.GetAll) {
return ExecutionsService.getExecutionsList(req);
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return this.executionService.getExecutionsList(req, workflowIds);
}
@Get('/:id')
async getExecution(req: ExecutionRequest.Get) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return isSharingEnabled()
? EnterpriseExecutionsService.getExecution(req)
: ExecutionsService.getExecution(req);
? this.enterpriseExecutionService.getExecution(req, workflowIds)
: this.executionService.getExecution(req, workflowIds);
}
@Post('/:id/retry')
async retryExecution(req: ExecutionRequest.Retry) {
return ExecutionsService.retryExecution(req);
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return this.executionService.retryExecution(req, workflowIds);
}
@Post('/delete')
async deleteExecutions(req: ExecutionRequest.Delete) {
return ExecutionsService.deleteExecutions(req);
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return this.executionService.deleteExecutions(req, workflowIds);
}
}