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
|
||||
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()
|
||||
// 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 }>> => {
|
||||
const withUsageCount = req.query.withUsageCount === 'true';
|
||||
|
||||
if (withUsageCount) {
|
||||
return await getConnection().createQueryBuilder()
|
||||
.select('tag_entity.id', 'id')
|
||||
.addSelect('tag_entity.name', 'name')
|
||||
.addSelect('COUNT(workflow_entity.id)', 'usageCount')
|
||||
|
@ -771,6 +774,14 @@ class App {
|
|||
.leftJoin('workflow_entity', 'workflow_entity', 'workflows_tags.workflowId = workflow_entity.id')
|
||||
.groupBy('tag_entity.id')
|
||||
.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
|
||||
|
|
Loading…
Reference in a new issue