fleet/frontend/services/entities/activities.ts
Gabriel Hernandez 7d4653baaa
add attribute to GET /activities endpoint with pagination metadata (#9279)
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
2023-01-18 12:57:11 +00:00

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