mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
280e21f073
Tiny refactor that bubbles promises instead of using `return await`. Should be more consistent with the rest of the changes in https://github.com/Unleash/unleash/pull/4903
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import useAPI from '../useApi/useApi';
|
|
|
|
export interface IServiceAccountPayload {
|
|
name: string;
|
|
username: string;
|
|
rootRole: number;
|
|
}
|
|
|
|
export const useServiceAccountsApi = () => {
|
|
const { loading, makeRequest, createRequest, errors } = useAPI({
|
|
propagateErrors: true,
|
|
});
|
|
|
|
const addServiceAccount = async (
|
|
serviceAccount: IServiceAccountPayload,
|
|
) => {
|
|
const requestId = 'addServiceAccount';
|
|
const req = createRequest(
|
|
'api/admin/service-account',
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify(serviceAccount),
|
|
},
|
|
requestId,
|
|
);
|
|
|
|
const response = await makeRequest(req.caller, req.id);
|
|
return response.json();
|
|
};
|
|
|
|
const removeServiceAccount = async (serviceAccountId: number) => {
|
|
const requestId = 'removeServiceAccount';
|
|
const req = createRequest(
|
|
`api/admin/service-account/${serviceAccountId}`,
|
|
{ method: 'DELETE' },
|
|
requestId,
|
|
);
|
|
|
|
await makeRequest(req.caller, req.id);
|
|
};
|
|
|
|
const updateServiceAccount = async (
|
|
serviceAccountId: number,
|
|
serviceAccount: IServiceAccountPayload,
|
|
) => {
|
|
const requestId = 'updateServiceAccount';
|
|
const req = createRequest(
|
|
`api/admin/service-account/${serviceAccountId}`,
|
|
{
|
|
method: 'PUT',
|
|
body: JSON.stringify(serviceAccount),
|
|
},
|
|
requestId,
|
|
);
|
|
|
|
await makeRequest(req.caller, req.id);
|
|
};
|
|
|
|
return {
|
|
addServiceAccount,
|
|
updateServiceAccount,
|
|
removeServiceAccount,
|
|
errors,
|
|
loading,
|
|
};
|
|
};
|