feat: download test cases csv (#219)

This commit is contained in:
kimatata
2025-05-06 10:05:37 +09:00
committed by GitHub
parent a05b39604a
commit c2ef8d4c7b
11 changed files with 120 additions and 7 deletions

View File

@@ -132,4 +132,33 @@ async function deleteCases(jwt: string, deleteCaseIds: number[], projectId: numb
}
}
export { fetchCase, fetchCases, updateCase, createCase, deleteCases };
async function csvDownload(jwt: string, folderId: number) {
const url = `${apiServer}/cases/download?folderId=${folderId}&type=csv`;
try {
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${jwt}`,
},
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const blob = await response.blob();
const objectUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = objectUrl;
a.download = `folder_${folderId}.csv`;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(objectUrl);
} catch (error: any) {
console.error('Error fetching data:', error.message);
}
}
export { fetchCase, fetchCases, updateCase, createCase, deleteCases, csvDownload };