Files
n8n-enterprise-unlocked/packages/cli/src/executions/executions.controller.ts
Tomi Turtiainen 9a1cc56806 fix: Set '@typescript-eslint/return-await' rule to 'always' for node code (no-changelog) (#8363)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2024-01-17 17:08:50 +02:00

54 lines
1.9 KiB
TypeScript

import { ExecutionRequest } from './execution.request';
import { ExecutionService } from './execution.service';
import { Authorized, Get, Post, RestController } from '@/decorators';
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()
? await this.workflowSharingService.getSharedWorkflowIds(user)
: await this.workflowSharingService.getSharedWorkflowIds(user, ['owner']);
}
@Get('/')
async getExecutionsList(req: ExecutionRequest.GetAll) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.getExecutionsList(req, workflowIds);
}
@Get('/:id')
async getExecution(req: ExecutionRequest.Get) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return isSharingEnabled()
? await this.enterpriseExecutionService.getExecution(req, workflowIds)
: await this.executionService.getExecution(req, workflowIds);
}
@Post('/:id/retry')
async retryExecution(req: ExecutionRequest.Retry) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.retryExecution(req, workflowIds);
}
@Post('/delete')
async deleteExecutions(req: ExecutionRequest.Delete) {
const workflowIds = await this.getAccessibleWorkflowIds(req.user);
return await this.executionService.deleteExecutions(req, workflowIds);
}
}