1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

refactor: add useApplicationsApi

This commit is contained in:
Youssef 2022-02-04 08:14:16 +01:00
parent 38e549d879
commit 47a1a47d28

View File

@ -0,0 +1,62 @@
import useAPI from '../useApi/useApi';
const useApplicationsApi = () => {
const { makeRequest, createRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const URI = 'api/admin/metrics/applications';
const storeApplicationMetaData = async (
appName: string,
key: string,
value: string
) => {
const data: { [key: string]: any } = {};
data[key] = value;
const path = `${URI}/${appName}`;
const req = createRequest(path, {
method: 'POST',
body: JSON.stringify(data),
});
try {
const res = await makeRequest(req.caller, req.id);
return res;
} catch (e) {
throw e;
}
};
const deleteApplication = async (appName: string) => {
const path = `${URI}/${appName}`;
const req = createRequest(path, { method: 'DELETE' });
try {
const res = await makeRequest(req.caller, req.id);
return res;
} catch (e) {
throw e;
}
};
const fetchApplicationsWithStrategyName = async (strategyName: string) => {
const path = `${URI}?strategyName=${strategyName}`;
const req = createRequest(path, { method: 'GET' });
try {
const res = await makeRequest(req.caller, req.id);
return res;
} catch (e) {
throw e;
}
};
return {
storeApplicationMetaData,
fetchApplicationsWithStrategyName,
deleteApplication,
errors,
loading,
};
};
export default useApplicationsApi;