UNPKG

n8n

Version:

n8n Workflow Automation Tool

94 lines 4.93 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.EvaluationConfigController = void 0; const api_types_1 = require("@n8n/api-types"); const decorators_1 = require("@n8n/decorators"); const not_found_error_1 = require("../errors/response-errors/not-found.error"); const workflow_finder_service_1 = require("../workflows/workflow-finder.service"); const evaluation_config_service_1 = require("./evaluation-config.service"); let EvaluationConfigController = class EvaluationConfigController { constructor(service, workflowFinderService) { this.service = service; this.workflowFinderService = workflowFinderService; } async assertWorkflowAccess(workflowId, user, scope) { const workflow = await this.workflowFinderService.findWorkflowForUser(workflowId, user, [ scope, ]); if (!workflow) throw new not_found_error_1.NotFoundError('Workflow not found'); return workflow; } async list(req) { await this.assertWorkflowAccess(req.params.workflowId, req.user, 'workflow:read'); return await this.service.list(req.params.workflowId); } async get(req) { await this.assertWorkflowAccess(req.params.workflowId, req.user, 'workflow:read'); const config = await this.service.get(req.params.workflowId, req.params.configId); if (!config) throw new not_found_error_1.NotFoundError('Evaluation config not found'); return config; } async create(req) { const workflow = await this.assertWorkflowAccess(req.params.workflowId, req.user, 'workflow:update'); const dto = api_types_1.upsertEvaluationConfigSchema.parse(req.body); return await this.service.create(req.params.workflowId, workflow, req.user, dto); } async update(req) { const workflow = await this.assertWorkflowAccess(req.params.workflowId, req.user, 'workflow:update'); const dto = api_types_1.upsertEvaluationConfigSchema.parse(req.body); return await this.service.update(req.params.workflowId, req.params.configId, workflow, req.user, dto); } async delete(req) { await this.assertWorkflowAccess(req.params.workflowId, req.user, 'workflow:update'); await this.service.delete(req.params.workflowId, req.params.configId); return { success: true }; } }; exports.EvaluationConfigController = EvaluationConfigController; __decorate([ (0, decorators_1.Get)('/:workflowId/evaluation-configs'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], EvaluationConfigController.prototype, "list", null); __decorate([ (0, decorators_1.Get)('/:workflowId/evaluation-configs/:configId'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], EvaluationConfigController.prototype, "get", null); __decorate([ (0, decorators_1.Post)('/:workflowId/evaluation-configs'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], EvaluationConfigController.prototype, "create", null); __decorate([ (0, decorators_1.Put)('/:workflowId/evaluation-configs/:configId'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], EvaluationConfigController.prototype, "update", null); __decorate([ (0, decorators_1.Delete)('/:workflowId/evaluation-configs/:configId'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], EvaluationConfigController.prototype, "delete", null); exports.EvaluationConfigController = EvaluationConfigController = __decorate([ (0, decorators_1.RestController)('/workflows'), __metadata("design:paramtypes", [evaluation_config_service_1.EvaluationConfigService, workflow_finder_service_1.WorkflowFinderService]) ], EvaluationConfigController); //# sourceMappingURL=evaluation-config.controller.js.map