Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Rename workflowsCount to workflowCount (no-changelog) #13470

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Project } from './project';
import { TagEntity } from './tag-entity';
import { type WorkflowEntity } from './workflow-entity';

export type FolderWithWorkflowsCount = Folder & {
workflowsCount: boolean;
export type FolderWithWorkflowCount = Folder & {
workflowCount: boolean;
};

@Entity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,21 @@ describe('FolderRepository', () => {
});
});

it('should return id, name and workflowsCount when specified', async () => {
it('should return id, name and workflowCount when specified', async () => {
const [folders] = await folderRepository.getManyAndCount({
select: {
id: true,
name: true,
workflowsCount: true,
workflowCount: true,
},
});

expect(folders).toHaveLength(2);
folders.forEach((folder) => {
expect(Object.keys(folder).sort()).toEqual(['id', 'name', 'workflowsCount']);
expect(Object.keys(folder).sort()).toEqual(['id', 'name', 'workflowCount']);
expect(folder.id).toBeDefined();
expect(folder.name).toBeDefined();
expect(folder.workflowsCount).toBeDefined();
expect(folder.workflowCount).toBeDefined();
});
});

Expand Down Expand Up @@ -399,7 +399,7 @@ describe('FolderRepository', () => {
type: expect.any(String),
icon: null,
},
workflowsCount: expect.any(Number),
workflowCount: expect.any(Number),
tags: expect.any(Array),
});
});
Expand Down
34 changes: 17 additions & 17 deletions packages/cli/src/databases/repositories/folder.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import { DataSource, Repository } from '@n8n/typeorm';

import type { ListQuery } from '@/requests';

import type { FolderWithWorkflowsCount } from '../entities/folder';
import type { FolderWithWorkflowCount } from '../entities/folder';
import { Folder } from '../entities/folder';
import { FolderTagMapping } from '../entities/folder-tag-mapping';
import { TagEntity } from '../entities/tag-entity';

@Service()
export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
export class FolderRepository extends Repository<FolderWithWorkflowCount> {
constructor(dataSource: DataSource) {
super(Folder, dataSource.manager);
}

async getManyAndCount(
options: ListQuery.Options = {},
): Promise<[FolderWithWorkflowsCount[], number]> {
): Promise<[FolderWithWorkflowCount[], number]> {
const query = this.getManyQuery(options);
return await query.getManyAndCount();
}

async getMany(options: ListQuery.Options = {}): Promise<FolderWithWorkflowsCount[]> {
async getMany(options: ListQuery.Options = {}): Promise<FolderWithWorkflowCount[]> {
const query = this.getManyQuery(options);
return await query.getMany();
}

getManyQuery(options: ListQuery.Options = {}): SelectQueryBuilder<FolderWithWorkflowsCount> {
getManyQuery(options: ListQuery.Options = {}): SelectQueryBuilder<FolderWithWorkflowCount> {
const query = this.createQueryBuilder('folder');

this.applySelections(query, options.select);
Expand All @@ -39,7 +39,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applySelections(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
select?: Record<string, boolean>,
): void {
if (select) {
Expand All @@ -49,12 +49,12 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}
}

private applyDefaultSelect(query: SelectQueryBuilder<FolderWithWorkflowsCount>): void {
private applyDefaultSelect(query: SelectQueryBuilder<FolderWithWorkflowCount>): void {
query
.leftJoinAndSelect('folder.homeProject', 'homeProject')
.leftJoinAndSelect('folder.parentFolder', 'parentFolder')
.leftJoinAndSelect('folder.tags', 'tags')
.loadRelationCountAndMap('folder.workflowsCount', 'folder.workflows')
.loadRelationCountAndMap('folder.workflowCount', 'folder.workflows')
.select([
'folder',
...this.getProjectFields('homeProject'),
Expand All @@ -64,7 +64,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applyCustomSelect(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
select?: Record<string, boolean>,
): void {
const selections = ['folder.id'];
Expand All @@ -82,7 +82,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private addRelationFields(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
selections: string[],
select?: Record<string, boolean>,
): void {
Expand Down Expand Up @@ -119,7 +119,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applyFilters(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
filter?: ListQuery.Options['filter'],
): void {
if (!filter) return;
Expand All @@ -129,7 +129,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applyBasicFilters(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
filter: ListQuery.Options['filter'],
): void {
if (filter?.folderIds && Array.isArray(filter.folderIds)) {
Expand Down Expand Up @@ -162,7 +162,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applyTagsFilter(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
tags?: string[],
): void {
if (!Array.isArray(tags) || tags.length === 0) return;
Expand All @@ -176,7 +176,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private createTagsSubQuery(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
tags: string[],
): SelectQueryBuilder<FolderTagMapping> {
return query
Expand All @@ -191,7 +191,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
});
}

private applySorting(query: SelectQueryBuilder<FolderWithWorkflowsCount>, sortBy?: string): void {
private applySorting(query: SelectQueryBuilder<FolderWithWorkflowCount>, sortBy?: string): void {
if (!sortBy) {
query.orderBy('folder.updatedAt', 'DESC');
return;
Expand All @@ -207,7 +207,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applySortingByField(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
field: string,
direction: 'DESC' | 'ASC',
): void {
Expand All @@ -219,7 +219,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
}

private applyPagination(
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
query: SelectQueryBuilder<FolderWithWorkflowCount>,
options: ListQuery.Options,
): void {
if (options?.take) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ListQuery } from '@/requests';
import { isStringArray } from '@/utils';

import { FolderRepository } from './folder.repository';
import type { Folder, FolderWithWorkflowsCount } from '../entities/folder';
import type { Folder, FolderWithWorkflowCount } from '../entities/folder';
import { TagEntity } from '../entities/tag-entity';
import { WebhookEntity } from '../entities/webhook-entity';
import { WorkflowEntity } from '../entities/workflow-entity';
Expand All @@ -34,7 +34,7 @@ type WorkflowFolderUnionRow = {
export type WorkflowFolderUnionFull = (
| ListQuery.Workflow.Plain
| ListQuery.Workflow.WithSharing
| FolderWithWorkflowsCount
| FolderWithWorkflowCount
) & {
resource: ResourceType;
};
Expand Down
Loading