mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
d747a471af
* Isolate each API entity * Improve code structure in API client and request mocks * Standardize on a request mock structure * Use helper for creating request mocks * Adds Request class to handle API requests
29 lines
747 B
JavaScript
29 lines
747 B
JavaScript
import { appendTargetTypeToTargets } from 'redux/nodes/entities/targets/helpers';
|
|
import endpoints from 'kolide/endpoints';
|
|
|
|
const defaultSelected = {
|
|
hosts: [],
|
|
labels: [],
|
|
};
|
|
|
|
export default (client) => {
|
|
return {
|
|
loadAll: (query, selected = defaultSelected) => {
|
|
const { TARGETS } = endpoints;
|
|
|
|
return client.authenticatedPost(client._endpoint(TARGETS), JSON.stringify({ query, selected }))
|
|
.then((response) => {
|
|
const { targets } = response;
|
|
|
|
return {
|
|
...response,
|
|
targets: [
|
|
...appendTargetTypeToTargets(targets.hosts, 'hosts'),
|
|
...appendTargetTypeToTargets(targets.labels, 'labels'),
|
|
],
|
|
};
|
|
});
|
|
},
|
|
};
|
|
};
|