CEC-4523: add bulk archive to /packages (#372)

* CEC-4523: add bulk archive to /packages
This commit is contained in:
Tristan Timblin
2023-06-26 12:35:17 -04:00
committed by GitHub
parent 787bb12260
commit 60c1f414a6
6 changed files with 328 additions and 67 deletions

1
src/hooks/index.js Normal file
View File

@@ -0,0 +1 @@
export { useArchiveManifests } from "./useArchiveManifests";

View File

@@ -0,0 +1,32 @@
import manifestsAPI from "../services/manifestsAPI";
import TaskRunner from "../utils/taskRunner";
export const useArchiveManifests = (token) => {
const archive = async (ids) => {
return new Promise((resolve) => {
const taskRunner = new TaskRunner(5, ids.length);
let errorCount = 0;
const task = (id) => {
return async () => manifestsAPI.deleteManifest(id, token);
}
ids.forEach((id) => taskRunner.push(task(id))
.then((response) => {
if (response.error) {
errorCount += 1;
}
})
);
taskRunner.onComplete().then((responses) => resolve({
summary: `${ids.length - errorCount} out of ${ids.length} manifests were deleted.`,
responses,
}));
});
}
return {
archive,
};
};