mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Rename workflowsCount
to workflowCount
(no-changelog) (#13470)
This commit is contained in:
parent
6ba0128b5c
commit
6e8c401ff1
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -399,7 +399,7 @@ describe('FolderRepository', () => {
|
|||
type: expect.any(String),
|
||||
icon: null,
|
||||
},
|
||||
workflowsCount: expect.any(Number),
|
||||
workflowCount: expect.any(Number),
|
||||
tags: expect.any(Array),
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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'),
|
||||
|
@ -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'];
|
||||
|
@ -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 {
|
||||
|
@ -101,8 +101,8 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
|
|||
selections.push(...this.getParentFolderFields('parentFolder'));
|
||||
}
|
||||
|
||||
if (select?.workflowsCount) {
|
||||
query.loadRelationCountAndMap('folder.workflowsCount', 'folder.workflows');
|
||||
if (select?.workflowCount) {
|
||||
query.loadRelationCountAndMap('folder.workflowCount', 'folder.workflows');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -176,7 +176,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
|
|||
}
|
||||
|
||||
private createTagsSubQuery(
|
||||
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
|
||||
query: SelectQueryBuilder<FolderWithWorkflowCount>,
|
||||
tags: string[],
|
||||
): SelectQueryBuilder<FolderTagMapping> {
|
||||
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) {
|
||||
query.orderBy('folder.updatedAt', 'DESC');
|
||||
return;
|
||||
|
@ -207,7 +207,7 @@ export class FolderRepository extends Repository<FolderWithWorkflowsCount> {
|
|||
}
|
||||
|
||||
private applySortingByField(
|
||||
query: SelectQueryBuilder<FolderWithWorkflowsCount>,
|
||||
query: SelectQueryBuilder<FolderWithWorkflowCount>,
|
||||
field: string,
|
||||
direction: 'DESC' | 'ASC',
|
||||
): void {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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';
|
||||
|
@ -34,7 +34,7 @@ type WorkflowFolderUnionRow = {
|
|||
export type WorkflowFolderUnionFull = (
|
||||
| ListQuery.Workflow.Plain
|
||||
| ListQuery.Workflow.WithSharing
|
||||
| FolderWithWorkflowsCount
|
||||
| FolderWithWorkflowCount
|
||||
) & {
|
||||
resource: ResourceType;
|
||||
};
|
||||
|
|
|
@ -1320,7 +1320,7 @@ describe('GET /workflows?includeFolders=true', () => {
|
|||
type: ownerPersonalProject.type,
|
||||
},
|
||||
parentFolder: null,
|
||||
workflowsCount: 0,
|
||||
workflowCount: 0,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue