refactor(core): Update tag endpoints to use DTOs and injectable config (#12380)

This commit is contained in:
Ricardo Espinoza
2025-01-09 14:17:11 -05:00
committed by GitHub
parent 95f055d23a
commit b1a40a231b
26 changed files with 282 additions and 103 deletions

View File

@@ -1,29 +1,26 @@
import type { IRestApiContext, ITag } from '@/Interface';
import { makeRestApiRequest } from '@/utils/apiUtils';
import type { CreateOrUpdateTagRequestDto, RetrieveTagQueryDto } from '@n8n/api-types';
type TagsApiEndpoint = '/tags' | '/annotation-tags';
export interface ITagsApi {
getTags: (context: IRestApiContext, withUsageCount?: boolean) => Promise<ITag[]>;
createTag: (context: IRestApiContext, params: { name: string }) => Promise<ITag>;
updateTag: (context: IRestApiContext, id: string, params: { name: string }) => Promise<ITag>;
deleteTag: (context: IRestApiContext, id: string) => Promise<boolean>;
}
export function createTagsApi(endpoint: TagsApiEndpoint): ITagsApi {
export function createTagsApi(endpoint: TagsApiEndpoint) {
return {
getTags: async (context: IRestApiContext, withUsageCount = false): Promise<ITag[]> => {
return await makeRestApiRequest(context, 'GET', endpoint, { withUsageCount });
getTags: async (context: IRestApiContext, data: RetrieveTagQueryDto): Promise<ITag[]> => {
return await makeRestApiRequest(context, 'GET', endpoint, data);
},
createTag: async (context: IRestApiContext, params: { name: string }): Promise<ITag> => {
return await makeRestApiRequest(context, 'POST', endpoint, params);
createTag: async (
context: IRestApiContext,
data: CreateOrUpdateTagRequestDto,
): Promise<ITag> => {
return await makeRestApiRequest(context, 'POST', endpoint, data);
},
updateTag: async (
context: IRestApiContext,
id: string,
params: { name: string },
data: CreateOrUpdateTagRequestDto,
): Promise<ITag> => {
return await makeRestApiRequest(context, 'PATCH', `${endpoint}/${id}`, params);
return await makeRestApiRequest(context, 'PATCH', `${endpoint}/${id}`, data);
},
deleteTag: async (context: IRestApiContext, id: string): Promise<boolean> => {
return await makeRestApiRequest(context, 'DELETE', `${endpoint}/${id}`);

View File

@@ -80,10 +80,9 @@ const createTagsStore = (id: STORES.TAGS | STORES.ANNOTATION_TAGS) => {
}
loading.value = true;
const retrievedTags = await tagsApi.getTags(
rootStore.restApiContext,
Boolean(withUsageCount),
);
const retrievedTags = await tagsApi.getTags(rootStore.restApiContext, {
withUsageCount,
});
setAllTags(retrievedTags);
loading.value = false;
return retrievedTags;