@tapis/tapisui-api
Version:
Typescript library for making api calls with react query
39 lines (38 loc) • 1.22 kB
JavaScript
import { Workflows } from '@tapis/tapis-typescript';
import { apiGenerator, errorDecoder } from '../../utils';
const listAll = async (params, basePath, jwt) => {
const api = apiGenerator(Workflows, Workflows.ArchivesApi, basePath, jwt);
const resps = await Promise.all(params.groupIds.map((groupId) => {
try {
return errorDecoder(() => api.listArchives({ groupId }));
}
catch (e) {
throw e;
}
}));
let archives = [];
// Add every archive from each response to the list
resps.map((resp) => resp.result.map((archive) => archives.push(archive)));
const last = resps[resps.length - 1];
const hasNullResults = resps.some((resp) => {
return resp.result === null;
});
if (hasNullResults) {
return {
status: 'failure',
message: 'Failed to list all Archives',
metadata: last.metadata,
result: [],
version: last.version,
};
}
let respAll = {
status: last.status,
message: last.message,
metadata: last.metadata,
result: archives,
version: last.version,
};
return respAll;
};
export default listAll;