refactor(core): Switch Tags queries from QueryBuilder to Repository API (no-changelog) (#5819)
Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f8f584c136
commit
41cdee7bc7
@@ -4,7 +4,6 @@ import type { Config } from '@/config';
|
||||
import { Delete, Get, Middleware, Patch, Post, RestController } from '@/decorators';
|
||||
import type { IDatabaseCollections, IExternalHooksClass, ITagWithCountDb } from '@/Interfaces';
|
||||
import { TagEntity } from '@db/entities/TagEntity';
|
||||
import { getTagsWithCountDb } from '@/TagHelpers';
|
||||
import { validateEntity } from '@/GenericHelpers';
|
||||
import { BadRequestError, UnauthorizedError } from '@/ResponseHelper';
|
||||
import { TagsRequest } from '@/requests';
|
||||
@@ -44,8 +43,17 @@ export class TagsController {
|
||||
async getAll(req: TagsRequest.GetAll): Promise<TagEntity[] | ITagWithCountDb[]> {
|
||||
const { withUsageCount } = req.query;
|
||||
if (withUsageCount === 'true') {
|
||||
const tablePrefix = this.config.getEnv('database.tablePrefix');
|
||||
return getTagsWithCountDb(tablePrefix);
|
||||
return this.tagsRepository
|
||||
.find({
|
||||
select: ['id', 'name', 'createdAt', 'updatedAt'],
|
||||
relations: ['workflowMappings'],
|
||||
})
|
||||
.then((tags) =>
|
||||
tags.map(({ workflowMappings, ...rest }) => ({
|
||||
...rest,
|
||||
usageCount: workflowMappings.length,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
return this.tagsRepository.find({ select: ['id', 'name', 'createdAt', 'updatedAt'] });
|
||||
|
||||
Reference in New Issue
Block a user