n8n
Version:
n8n Workflow Automation Tool
85 lines • 4.17 kB
JavaScript
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.WorkflowHistoryService = void 0;
const sharedWorkflow_repository_1 = require("../../databases/repositories/sharedWorkflow.repository");
const workflowHistory_repository_1 = require("../../databases/repositories/workflowHistory.repository");
const typedi_1 = require("typedi");
const workflowHistoryHelper_ee_1 = require("./workflowHistoryHelper.ee");
const Logger_1 = require("../../Logger");
const shared_workflow_not_found_error_1 = require("../../errors/shared-workflow-not-found.error");
const workflow_history_version_not_found_error_1 = require("../../errors/workflow-history-version-not-found.error");
let WorkflowHistoryService = class WorkflowHistoryService {
constructor(logger, workflowHistoryRepository, sharedWorkflowRepository) {
this.logger = logger;
this.workflowHistoryRepository = workflowHistoryRepository;
this.sharedWorkflowRepository = sharedWorkflowRepository;
}
async getList(user, workflowId, take, skip) {
const workflow = await this.sharedWorkflowRepository.findWorkflowForUser(workflowId, user, [
'workflow:read',
]);
if (!workflow) {
throw new shared_workflow_not_found_error_1.SharedWorkflowNotFoundError('');
}
return await this.workflowHistoryRepository.find({
where: {
workflowId: workflow.id,
},
take,
skip,
select: ['workflowId', 'versionId', 'authors', 'createdAt', 'updatedAt'],
order: { createdAt: 'DESC' },
});
}
async getVersion(user, workflowId, versionId) {
const workflow = await this.sharedWorkflowRepository.findWorkflowForUser(workflowId, user, [
'workflow:read',
]);
if (!workflow) {
throw new shared_workflow_not_found_error_1.SharedWorkflowNotFoundError('');
}
const hist = await this.workflowHistoryRepository.findOne({
where: {
workflowId: workflow.id,
versionId,
},
});
if (!hist) {
throw new workflow_history_version_not_found_error_1.WorkflowHistoryVersionNotFoundError('');
}
return hist;
}
async saveVersion(user, workflow, workflowId) {
if ((0, workflowHistoryHelper_ee_1.isWorkflowHistoryEnabled)() && workflow.nodes && workflow.connections) {
try {
await this.workflowHistoryRepository.insert({
authors: user.firstName + ' ' + user.lastName,
connections: workflow.connections,
nodes: workflow.nodes,
versionId: workflow.versionId,
workflowId,
});
}
catch (e) {
this.logger.error(`Failed to save workflow history version for workflow ${workflowId}`, e);
}
}
}
};
exports.WorkflowHistoryService = WorkflowHistoryService;
exports.WorkflowHistoryService = WorkflowHistoryService = __decorate([
(0, typedi_1.Service)(),
__metadata("design:paramtypes", [Logger_1.Logger,
workflowHistory_repository_1.WorkflowHistoryRepository,
sharedWorkflow_repository_1.SharedWorkflowRepository])
], WorkflowHistoryService);
//# sourceMappingURL=workflowHistory.service.ee.js.map
;