Skip to content

Commit 1439d8f

Browse files
committed
reorganize class to make diff more readable
1 parent e25b5f9 commit 1439d8f

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

packages/cli/src/commands/import/credentials.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,40 @@ export class ImportCredentialsCommand extends BaseCommand {
8585
this.reportSuccess(credentials.length);
8686
}
8787

88+
async catch(error: Error) {
89+
this.logger.error(
90+
'An error occurred while importing credentials. See log messages for details.',
91+
);
92+
this.logger.error(error.message);
93+
}
94+
95+
private reportSuccess(total: number) {
96+
this.logger.info(
97+
`Successfully imported ${total} ${total === 1 ? 'credential.' : 'credentials.'}`,
98+
);
99+
}
100+
101+
private async storeCredential(credential: Partial<CredentialsEntity>, user: User) {
102+
const result = await this.transactionManager.upsert(CredentialsEntity, credential, ['id']);
103+
104+
const sharingExists = await this.transactionManager.existsBy(SharedCredentials, {
105+
credentialsId: credential.id,
106+
role: 'credential:owner',
107+
});
108+
109+
if (!sharingExists) {
110+
await this.transactionManager.upsert(
111+
SharedCredentials,
112+
{
113+
credentialsId: result.identifiers[0].id as string,
114+
userId: user.id,
115+
role: 'credential:owner',
116+
},
117+
['credentialsId', 'userId'],
118+
);
119+
}
120+
}
121+
88122
private async checkRelations(credentials: ICredentialsEncrypted[], userId?: string) {
89123
if (!userId) {
90124
return {
@@ -163,40 +197,6 @@ export class ImportCredentialsCommand extends BaseCommand {
163197
});
164198
}
165199

166-
async catch(error: Error) {
167-
this.logger.error(
168-
'An error occurred while importing credentials. See log messages for details.',
169-
);
170-
this.logger.error(error.message);
171-
}
172-
173-
private reportSuccess(total: number) {
174-
this.logger.info(
175-
`Successfully imported ${total} ${total === 1 ? 'credential.' : 'credentials.'}`,
176-
);
177-
}
178-
179-
private async storeCredential(credential: Partial<CredentialsEntity>, user: User) {
180-
const result = await this.transactionManager.upsert(CredentialsEntity, credential, ['id']);
181-
182-
const sharingExists = await this.transactionManager.existsBy(SharedCredentials, {
183-
credentialsId: credential.id,
184-
role: 'credential:owner',
185-
});
186-
187-
if (!sharingExists) {
188-
await this.transactionManager.upsert(
189-
SharedCredentials,
190-
{
191-
credentialsId: result.identifiers[0].id as string,
192-
userId: user.id,
193-
role: 'credential:owner',
194-
},
195-
['credentialsId', 'userId'],
196-
);
197-
}
198-
}
199-
200200
private async getOwner() {
201201
const owner = await Container.get(UserRepository).findOneBy({ role: 'global:owner' });
202202
if (!owner) {

packages/cli/src/commands/import/workflow.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { ApplicationError, jsonParse } from 'n8n-workflow';
44
import fs from 'fs';
55
import glob from 'fast-glob';
66

7+
import { UM_FIX_INSTRUCTION } from '@/constants';
78
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
89
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
910
import { generateNanoId } from '@db/utils/generators';
11+
import { UserRepository } from '@/databases/repositories/user.repository';
1012
import { WorkflowRepository } from '@db/repositories/workflow.repository';
1113
import type { IWorkflowToImport } from '@/Interfaces';
1214
import { ImportService } from '@/services/import.service';
1315
import { BaseCommand } from '../BaseCommand';
1416
import { SharedWorkflowRepository } from '@/databases/repositories/sharedWorkflow.repository';
15-
import { UserRepository } from '@/databases/repositories/user.repository';
16-
import { UM_FIX_INSTRUCTION } from '@/constants';
1717

1818
function assertHasWorkflowsToImport(workflows: unknown): asserts workflows is IWorkflowToImport[] {
1919
if (!Array.isArray(workflows)) {
@@ -127,13 +127,13 @@ export class ImportWorkflowsCommand extends BaseCommand {
127127
};
128128
}
129129

130-
private async getWorkflowOwner(workflow: WorkflowEntity) {
131-
const sharing = await Container.get(SharedWorkflowRepository).findOneBy({
132-
workflowId: workflow.id,
133-
role: 'workflow:owner',
134-
});
130+
async catch(error: Error) {
131+
this.logger.error('An error occurred while importing workflows. See log messages for details.');
132+
this.logger.error(error.message);
133+
}
135134

136-
return sharing?.userId;
135+
private reportSuccess(total: number) {
136+
this.logger.info(`Successfully imported ${total} ${total === 1 ? 'workflow.' : 'workflows.'}`);
137137
}
138138

139139
private async getOwner() {
@@ -145,6 +145,15 @@ export class ImportWorkflowsCommand extends BaseCommand {
145145
return owner;
146146
}
147147

148+
private async getWorkflowOwner(workflow: WorkflowEntity) {
149+
const sharing = await Container.get(SharedWorkflowRepository).findOneBy({
150+
workflowId: workflow.id,
151+
role: 'workflow:owner',
152+
});
153+
154+
return sharing?.userId;
155+
}
156+
148157
private async workflowExists(workflow: WorkflowEntity) {
149158
return await Container.get(WorkflowRepository).existsBy({ id: workflow.id });
150159
}
@@ -180,13 +189,4 @@ export class ImportWorkflowsCommand extends BaseCommand {
180189
return workflowInstances;
181190
}
182191
}
183-
184-
async catch(error: Error) {
185-
this.logger.error('An error occurred while importing workflows. See log messages for details.');
186-
this.logger.error(error.message);
187-
}
188-
189-
private reportSuccess(total: number) {
190-
this.logger.info(`Successfully imported ${total} ${total === 1 ? 'workflow.' : 'workflows.'}`);
191-
}
192192
}

0 commit comments

Comments
 (0)