UNPKG

n8n

Version:

n8n Workflow Automation Tool

83 lines 4.35 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestRunsController = void 0; const test_run_repository_ee_1 = require("../databases/repositories/test-run.repository.ee"); const decorators_1 = require("../decorators"); const not_found_error_1 = require("../errors/response-errors/not-found.error"); const middlewares_1 = require("../middlewares"); const workflows_service_1 = require("../public-api/v1/handlers/workflows/workflows.service"); const test_definition_service_ee_1 = require("./test-definition.service.ee"); let TestRunsController = class TestRunsController { constructor(testDefinitionService, testRunRepository) { this.testDefinitionService = testDefinitionService; this.testRunRepository = testRunRepository; } async getTestDefinition(req) { const { testDefinitionId } = req.params; const userAccessibleWorkflowIds = await (0, workflows_service_1.getSharedWorkflowIds)(req.user, ['workflow:read']); const testDefinition = await this.testDefinitionService.findOne(testDefinitionId, userAccessibleWorkflowIds); if (!testDefinition) throw new not_found_error_1.NotFoundError('Test definition not found'); return testDefinition; } async getMany(req) { const { testDefinitionId } = req.params; await this.getTestDefinition(req); return await this.testRunRepository.getMany(testDefinitionId, req.listQueryOptions); } async getOne(req) { const { id: testRunId, testDefinitionId } = req.params; await this.getTestDefinition(req); const testRun = await this.testRunRepository.findOne({ where: { id: testRunId, testDefinition: { id: testDefinitionId } }, }); if (!testRun) throw new not_found_error_1.NotFoundError('Test run not found'); return testRun; } async delete(req) { const { id: testRunId, testDefinitionId } = req.params; await this.getTestDefinition(req); const testRun = await this.testRunRepository.findOne({ where: { id: testRunId, testDefinition: { id: testDefinitionId } }, }); if (!testRun) throw new not_found_error_1.NotFoundError('Test run not found'); await this.testRunRepository.delete({ id: testRunId }); return { success: true }; } }; exports.TestRunsController = TestRunsController; __decorate([ (0, decorators_1.Get)('/:testDefinitionId/runs', { middlewares: middlewares_1.listQueryMiddleware }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TestRunsController.prototype, "getMany", null); __decorate([ (0, decorators_1.Get)('/:testDefinitionId/runs/:id'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TestRunsController.prototype, "getOne", null); __decorate([ (0, decorators_1.Delete)('/:testDefinitionId/runs/:id'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TestRunsController.prototype, "delete", null); exports.TestRunsController = TestRunsController = __decorate([ (0, decorators_1.RestController)('/evaluation/test-definitions'), __metadata("design:paramtypes", [test_definition_service_ee_1.TestDefinitionService, test_run_repository_ee_1.TestRunRepository]) ], TestRunsController); //# sourceMappingURL=test-runs.controller.ee.js.map