feat(tags): Test case tag editing UI and tag settings UI (#322)
This commit is contained in:
28
frontend/utils/caseTagsControls.ts
Normal file
28
frontend/utils/caseTagsControls.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { logError } from './errorHandler';
|
||||
import Config from '@/config/config';
|
||||
const apiServer = Config.apiServer;
|
||||
|
||||
export async function updateCaseTags(jwt: string, caseId: number, tagIds: number[], projectId: string) {
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify({ tagIds }),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/casetags/update?projectId=${projectId}?&caseId=${caseId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data || [];
|
||||
} catch (error: unknown) {
|
||||
logError('Error updating case tags:', error);
|
||||
}
|
||||
}
|
||||
104
frontend/utils/tagsControls.ts
Normal file
104
frontend/utils/tagsControls.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { logError } from './errorHandler';
|
||||
import Config from '@/config/config';
|
||||
const apiServer = Config.apiServer;
|
||||
|
||||
async function fetchTags(jwt: string, projectId: string) {
|
||||
const fetchOptions = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
};
|
||||
|
||||
const url = `${apiServer}/tags?projectId=${projectId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data || [];
|
||||
} catch (error: unknown) {
|
||||
logError('Error fetching case tags', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function createTag(jwt: string, projectId: string, tagName: string) {
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify({ name: tagName }),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/tags?projectId=${projectId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: unknown) {
|
||||
logError('Error creating case tag', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function updateTag(jwt: string, projectId: string, tagId: number, tagName: string) {
|
||||
const fetchOptions = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify({ name: tagName }),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/tags/${tagId}?projectId=${projectId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: unknown) {
|
||||
logError('Error updating case tag', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTag(jwt: string, projectId: string, tagId: number) {
|
||||
const fetchOptions = {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
};
|
||||
|
||||
const url = `${apiServer}/tags/${tagId}?projectId=${projectId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
logError('Error deleting case tag', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export { fetchTags, createTag, updateTag, deleteTag };
|
||||
Reference in New Issue
Block a user