mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
7d4653baaa
relates to https://github.com/fleetdm/fleet/issues/8928 This adds a new `meta` attribute to the "GET /activities" endpoint that includes pagination metadata. This can allow clients to know if there are additional items to request. - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md) - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
40 lines
925 B
TypeScript
40 lines
925 B
TypeScript
import endpoints from "utilities/endpoints";
|
|
import { IActivity } from "interfaces/activity";
|
|
import sendRequest from "services";
|
|
import { buildQueryStringFromParams } from "utilities/url";
|
|
|
|
const DEFAULT_PAGE = 0;
|
|
const DEFAULT_PAGE_SIZE = 8;
|
|
const ORDER_KEY = "created_at";
|
|
const ORDER_DIRECTION = "desc";
|
|
|
|
export interface IActivitiesResponse {
|
|
activities: IActivity[];
|
|
meta: {
|
|
has_next_results: boolean;
|
|
has_previous_results: boolean;
|
|
};
|
|
}
|
|
|
|
export default {
|
|
loadNext: (
|
|
page = DEFAULT_PAGE,
|
|
perPage = DEFAULT_PAGE_SIZE
|
|
): Promise<IActivitiesResponse> => {
|
|
const { ACTIVITIES } = endpoints;
|
|
|
|
const queryParams = {
|
|
page,
|
|
per_page: perPage,
|
|
order_key: ORDER_KEY,
|
|
order_direction: ORDER_DIRECTION,
|
|
};
|
|
|
|
const queryString = buildQueryStringFromParams(queryParams);
|
|
|
|
const path = `${ACTIVITIES}?${queryString}`;
|
|
|
|
return sendRequest("GET", path);
|
|
},
|
|
};
|