mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +02:00
refactor: add useApplicationsApi
This commit is contained in:
parent
38e549d879
commit
47a1a47d28
@ -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;
|
Loading…
Reference in New Issue
Block a user