refactor(core): Consolidate executions controllers (no-changelog) (#8349)

This commit is contained in:
Iván Ovejero
2024-01-16 16:52:21 +01:00
committed by GitHub
parent b267bf07e3
commit 7bb2d1799e
9 changed files with 64 additions and 166 deletions

View File

@@ -1,59 +1,31 @@
import express from 'express';
import type {
IExecutionFlattedResponse,
IExecutionResponse,
IExecutionsListResponse,
} from '@/Interfaces';
import * as ResponseHelper from '@/ResponseHelper';
import type { ExecutionRequest } from '@/requests';
import { EEExecutionsController } from './executions.controller.ee';
import { ExecutionRequest } from './execution.request';
import { ExecutionsService } from './executions.service';
import { Authorized, Get, Post, RestController } from '@/decorators';
import { EnterpriseExecutionsService } from './executions.service.ee';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
export const executionsController = express.Router();
executionsController.use('/', EEExecutionsController);
/**
* GET /executions
*/
executionsController.get(
'/',
ResponseHelper.send(async (req: ExecutionRequest.GetAll): Promise<IExecutionsListResponse> => {
@Authorized()
@RestController('/executions')
export class ExecutionsController {
@Get('/')
async getExecutionsList(req: ExecutionRequest.GetAll) {
return ExecutionsService.getExecutionsList(req);
}),
);
}
/**
* GET /executions/:id
*/
executionsController.get(
'/:id(\\d+)',
ResponseHelper.send(
async (
req: ExecutionRequest.Get,
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> => {
return ExecutionsService.getExecution(req);
},
),
);
@Get('/:id')
async getExecution(req: ExecutionRequest.Get) {
return isSharingEnabled()
? EnterpriseExecutionsService.getExecution(req)
: ExecutionsService.getExecution(req);
}
/**
* POST /executions/:id/retry
*/
executionsController.post(
'/:id/retry',
ResponseHelper.send(async (req: ExecutionRequest.Retry): Promise<boolean> => {
@Post('/:id/retry')
async retryExecution(req: ExecutionRequest.Retry) {
return ExecutionsService.retryExecution(req);
}),
);
}
/**
* POST /executions/delete
* INFORMATION: We use POST instead of DELETE to not run into any issues with the query data
* getting too long
*/
executionsController.post(
'/delete',
ResponseHelper.send(async (req: ExecutionRequest.Delete): Promise<void> => {
await ExecutionsService.deleteExecutions(req);
}),
);
@Post('/delete')
async deleteExecutions(req: ExecutionRequest.Delete) {
return ExecutionsService.deleteExecutions(req);
}
}