CEC-4523: add bulk archive to /packages (#372)
* CEC-4523: add bulk archive to /packages
This commit is contained in:
1
src/hooks/index.js
Normal file
1
src/hooks/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { useArchiveManifests } from "./useArchiveManifests";
|
||||
32
src/hooks/useArchiveManifests.js
Normal file
32
src/hooks/useArchiveManifests.js
Normal 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user