mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Make usage count optional in GET /tags
This commit is contained in:
parent
fded7b9ce7
commit
5047c10ee3
|
@ -760,9 +760,12 @@ class App {
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Retrieves all tags
|
// Retrieves all tags, with or without usage count
|
||||||
this.app.get(`/${this.restEndpoint}/tags`, ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<Array<{ id: number, name: string, usageCount: number }>> => {
|
this.app.get(`/${this.restEndpoint}/tags`, ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<Array<{ id: number, name: string, usageCount?: number }>> => {
|
||||||
return await getConnection().createQueryBuilder()
|
const withUsageCount = req.query.withUsageCount === 'true';
|
||||||
|
|
||||||
|
if (withUsageCount) {
|
||||||
|
return await getConnection().createQueryBuilder()
|
||||||
.select('tag_entity.id', 'id')
|
.select('tag_entity.id', 'id')
|
||||||
.addSelect('tag_entity.name', 'name')
|
.addSelect('tag_entity.name', 'name')
|
||||||
.addSelect('COUNT(workflow_entity.id)', 'usageCount')
|
.addSelect('COUNT(workflow_entity.id)', 'usageCount')
|
||||||
|
@ -771,6 +774,14 @@ class App {
|
||||||
.leftJoin('workflow_entity', 'workflow_entity', 'workflows_tags.workflowId = workflow_entity.id')
|
.leftJoin('workflow_entity', 'workflow_entity', 'workflows_tags.workflowId = workflow_entity.id')
|
||||||
.groupBy('tag_entity.id')
|
.groupBy('tag_entity.id')
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
|
}
|
||||||
|
|
||||||
|
return await getConnection().createQueryBuilder()
|
||||||
|
.select('tag_entity.id', 'id')
|
||||||
|
.addSelect('tag_entity.name', 'name')
|
||||||
|
.from('tag_entity', 'tag_entity')
|
||||||
|
.groupBy('tag_entity.id')
|
||||||
|
.getRawMany();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Creates a tag
|
// Creates a tag
|
||||||
|
|
Loading…
Reference in a new issue