refactor(core): Use mixins to delete redundant code between Entity classes (no-changelog) (#6616)

* db entities don't need an ID before they are inserted

* don't define constructors on entity classes, use repository.create instead

* use mixins to reduce duplicate code in db entity classes
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-07-27 11:53:37 +02:00
committed by GitHub
parent e6903a87b5
commit dc2ba743eb
16 changed files with 87 additions and 138 deletions

View File

@@ -4,7 +4,6 @@ import { audit } from '@/audit';
import { FILESYSTEM_INTERACTION_NODE_TYPES, FILESYSTEM_REPORT } from '@/audit/constants';
import { getRiskSection, saveManualTriggerWorkflow } from './utils';
import * as testDb from '../shared/testDb';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
beforeAll(async () => {
await testDb.init();
@@ -27,7 +26,7 @@ test('should report filesystem interaction nodes', async () => {
);
const promises = Object.entries(map).map(async ([nodeType, nodeId]) => {
const details = new WorkflowEntity({
const details = Db.collections.Workflow.create({
name: 'My Test Workflow',
active: false,
connections: {},

View File

@@ -9,7 +9,6 @@ import { toReportTitle } from '@/audit/utils';
import { mockInstance } from '../shared/utils/';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { NodeTypes } from '@/NodeTypes';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
const nodesAndCredentials = mockInstance(LoadNodesAndCredentials);
nodesAndCredentials.getCustomDirectories.mockReturnValue([]);
@@ -33,7 +32,7 @@ test('should report risky official nodes', async () => {
}, {});
const promises = Object.entries(map).map(async ([nodeType, nodeId]) => {
const details = new WorkflowEntity({
const details = Db.collections.Workflow.create({
name: 'My Test Workflow',
active: false,
connections: {},

View File

@@ -19,7 +19,7 @@ import { InstalledPackages } from '@db/entities/InstalledPackages';
import type { Role } from '@db/entities/Role';
import type { TagEntity } from '@db/entities/TagEntity';
import type { User } from '@db/entities/User';
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { RoleRepository } from '@db/repositories';
import type { ICredentialsDb } from '@/Interfaces';
@@ -412,7 +412,7 @@ export async function createManyWorkflows(
export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, user?: User) {
const { active, name, nodes, connections } = attributes;
const workflowEntity = new WorkflowEntity({
const workflowEntity = Db.collections.Workflow.create({
active: active ?? false,
name: name ?? 'test workflow',
nodes: nodes ?? [