mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
refactor(core): Update tag endpoints to use DTOs and injectable config (#12380)
This commit is contained in:
@@ -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}`);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user