fleet/frontend/kolide/entities/targets.js
Mike Stone d747a471af Refactor API client (#1335)
* 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
2017-03-02 17:07:01 -05:00

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'),
],
};
});
},
};
};