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

This commit is contained in:
Ricardo Espinoza
2025-02-26 07:57:30 -05:00
committed by GitHub
parent 6ba0128b5c
commit 6e8c401ff1
5 changed files with 29 additions and 29 deletions

View File

@@ -13,8 +13,8 @@ import { Project } from './project';
import { TagEntity } from './tag-entity'; import { TagEntity } from './tag-entity';
import { type WorkflowEntity } from './workflow-entity'; import { type WorkflowEntity } from './workflow-entity';
export type FolderWithWorkflowsCount = Folder & { export type FolderWithWorkflowCount = Folder & {
workflowsCount: boolean; workflowCount: boolean;
}; };
@Entity() @Entity()

View File

@@ -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({ const [folders] = await folderRepository.getManyAndCount({
select: { select: {
id: true, id: true,
name: true, name: true,
workflowsCount: true, workflowCount: true,
}, },
}); });
expect(folders).toHaveLength(2); expect(folders).toHaveLength(2);
folders.forEach((folder) => { 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.id).toBeDefined();
expect(folder.name).toBeDefined(); expect(folder.name).toBeDefined();
expect(folder.workflowsCount).toBeDefined(); expect(folder.workflowCount).toBeDefined();
}); });
}); });
@@ -399,7 +399,7 @@ describe('FolderRepository', () => {
type: expect.any(String), type: expect.any(String),
icon: null, icon: null,
}, },
workflowsCount: expect.any(Number), workflowCount: expect.any(Number),
tags: expect.any(Array), tags: expect.any(Array),
}); });
}); });

View File

@@ -4,30 +4,30 @@ import { DataSource, Repository } from '@n8n/typeorm';
import type { ListQuery } from '@/requests'; import type { ListQuery } from '@/requests';
import type { FolderWithWorkflowsCount } from '../entities/folder'; import type { FolderWithWorkflowCount } from '../entities/folder';
import { Folder } from '../entities/folder'; import { Folder } from '../entities/folder';
import { FolderTagMapping } from '../entities/folder-tag-mapping'; import { FolderTagMapping } from '../entities/folder-tag-mapping';
import { TagEntity } from '../entities/tag-entity'; import { TagEntity } from '../entities/tag-entity';
@Service() @Service()
export class FolderRepository extends Repository<FolderWithWorkflowsCount> { export class FolderRepository extends Repository<FolderWithWorkflowCount> {
constructor(dataSource: DataSource) { constructor(dataSource: DataSource) {
super(Folder, dataSource.manager); super(Folder, dataSource.manager);
} }
async getManyAndCount( async getManyAndCount(
options: ListQuery.Options = {}, options: ListQuery.Options = {},
): Promise<[FolderWithWorkflowsCount[], number]> { ): Promise<[FolderWithWorkflowCount[], number]> {
const query = this.getManyQuery(options); const query = this.getManyQuery(options);
return await query.getManyAndCount(); return await query.getManyAndCount();
} }
async getMany(options: ListQuery.Options = {}): Promise<FolderWithWorkflowsCount[]> { async getMany(options: ListQuery.Options = {}): Promise<FolderWithWorkflowCount[]> {
const query = this.getManyQuery(options); const query = this.getManyQuery(options);
return await query.getMany(); return await query.getMany();
} }
getManyQuery(options: ListQuery.Options = {}): SelectQueryBuilder<FolderWithWorkflowsCount> { getManyQuery(options: ListQuery.Options = {}): SelectQueryBuilder<FolderWithWorkflowCount> {
const query = this.createQueryBuilder('folder'); const query = this.createQueryBuilder('folder');
this.applySelections(query, options.select); this.applySelections(query, options.select);
@@ -39,7 +39,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applySelections( private applySelections(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
select?: Record<string, boolean>, select?: Record<string, boolean>,
): void { ): void {
if (select) { if (select) {
@@ -49,12 +49,12 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
} }
private applyDefaultSelect(query: SelectQueryBuilder<FolderWithWorkflowsCount>): void { private applyDefaultSelect(query: SelectQueryBuilder<FolderWithWorkflowCount>): void {
query query
.leftJoinAndSelect('folder.homeProject', 'homeProject') .leftJoinAndSelect('folder.homeProject', 'homeProject')
.leftJoinAndSelect('folder.parentFolder', 'parentFolder') .leftJoinAndSelect('folder.parentFolder', 'parentFolder')
.leftJoinAndSelect('folder.tags', 'tags') .leftJoinAndSelect('folder.tags', 'tags')
.loadRelationCountAndMap('folder.workflowsCount', 'folder.workflows') .loadRelationCountAndMap('folder.workflowCount', 'folder.workflows')
.select([ .select([
'folder', 'folder',
...this.getProjectFields('homeProject'), ...this.getProjectFields('homeProject'),
@@ -64,7 +64,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applyCustomSelect( private applyCustomSelect(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
select?: Record<string, boolean>, select?: Record<string, boolean>,
): void { ): void {
const selections = ['folder.id']; const selections = ['folder.id'];
@@ -82,7 +82,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private addRelationFields( private addRelationFields(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
selections: string[], selections: string[],
select?: Record<string, boolean>, select?: Record<string, boolean>,
): void { ): void {
@@ -101,8 +101,8 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
selections.push(...this.getParentFolderFields('parentFolder')); selections.push(...this.getParentFolderFields('parentFolder'));
} }
if (select?.workflowsCount) { if (select?.workflowCount) {
query.loadRelationCountAndMap('folder.workflowsCount', 'folder.workflows'); query.loadRelationCountAndMap('folder.workflowCount', 'folder.workflows');
} }
} }
@@ -119,7 +119,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applyFilters( private applyFilters(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
filter?: ListQuery.Options['filter'], filter?: ListQuery.Options['filter'],
): void { ): void {
if (!filter) return; if (!filter) return;
@@ -129,7 +129,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applyBasicFilters( private applyBasicFilters(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
filter: ListQuery.Options['filter'], filter: ListQuery.Options['filter'],
): void { ): void {
if (filter?.folderIds && Array.isArray(filter.folderIds)) { if (filter?.folderIds && Array.isArray(filter.folderIds)) {
@@ -162,7 +162,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applyTagsFilter( private applyTagsFilter(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
tags?: string[], tags?: string[],
): void { ): void {
if (!Array.isArray(tags) || tags.length === 0) return; if (!Array.isArray(tags) || tags.length === 0) return;
@@ -176,7 +176,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private createTagsSubQuery( private createTagsSubQuery(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
tags: string[], tags: string[],
): SelectQueryBuilder<FolderTagMapping> { ): SelectQueryBuilder<FolderTagMapping> {
return query return query
@@ -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) { if (!sortBy) {
query.orderBy('folder.updatedAt', 'DESC'); query.orderBy('folder.updatedAt', 'DESC');
return; return;
@@ -207,7 +207,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applySortingByField( private applySortingByField(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
field: string, field: string,
direction: 'DESC' | 'ASC', direction: 'DESC' | 'ASC',
): void { ): void {
@@ -219,7 +219,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
} }
private applyPagination( private applyPagination(
query: SelectQueryBuilder<FolderWithWorkflowsCount>, query: SelectQueryBuilder<FolderWithWorkflowCount>,
options: ListQuery.Options, options: ListQuery.Options,
): void { ): void {
if (options?.take) { if (options?.take) {

View File

@@ -14,7 +14,7 @@ import type { ListQuery } from '@/requests';
import { isStringArray } from '@/utils'; import { isStringArray } from '@/utils';
import { FolderRepository } from './folder.repository'; 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 { TagEntity } from '../entities/tag-entity';
import { WebhookEntity } from '../entities/webhook-entity'; import { WebhookEntity } from '../entities/webhook-entity';
import { WorkflowEntity } from '../entities/workflow-entity'; import { WorkflowEntity } from '../entities/workflow-entity';
@@ -34,7 +34,7 @@ type WorkflowFolderUnionRow = {
export type WorkflowFolderUnionFull = ( export type WorkflowFolderUnionFull = (
| ListQuery.Workflow.Plain | ListQuery.Workflow.Plain
| ListQuery.Workflow.WithSharing | ListQuery.Workflow.WithSharing
| FolderWithWorkflowsCount | FolderWithWorkflowCount
) & { ) & {
resource: ResourceType; resource: ResourceType;
}; };

View File

@@ -1320,7 +1320,7 @@ describe('GET /workflows?includeFolders=true', () => {
type: ownerPersonalProject.type, type: ownerPersonalProject.type,
}, },
parentFolder: null, parentFolder: null,
workflowsCount: 0, workflowCount: 0,
}), }),
]), ]),
}); });