mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
349a88e25b
* Allow sort by more than one key * forcing 404 page where entity ids do not exist * refactored error boundary; handling 404s now * added 403 overlay; refactored auth wrappers * fixed test for maintainer * more efficient fetches; test fixes * clarify comment * clean up Co-authored-by: Tomas Touceda <chiiph@gmail.com>
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
import sendRequest from "services";
|
|
import endpoints from "fleet/endpoints";
|
|
import { INewMembersBody, IRemoveMembersBody, ITeam } from "interfaces/team";
|
|
import { ICreateTeamFormData } from "pages/admin/TeamManagementPage/components/CreateTeamModal/CreateTeamModal";
|
|
import { IEnrollSecret } from "interfaces/enroll_secret";
|
|
|
|
interface ILoadAllTeamsResponse {
|
|
teams: ITeam[];
|
|
}
|
|
|
|
interface ILoadTeamResponse {
|
|
team: ITeam;
|
|
}
|
|
|
|
interface ITeamEnrollSecretsResponse {
|
|
secrets: IEnrollSecret[];
|
|
}
|
|
|
|
interface ITeamSearchOptions {
|
|
page?: number;
|
|
perPage?: number;
|
|
globalFilter?: string;
|
|
}
|
|
|
|
interface IEditTeamFormData {
|
|
name: string;
|
|
}
|
|
|
|
export default {
|
|
create: (formData: ICreateTeamFormData) => {
|
|
const { TEAMS } = endpoints;
|
|
|
|
return sendRequest("POST", TEAMS, formData);
|
|
},
|
|
destroy: (teamId: number) => {
|
|
const { TEAMS } = endpoints;
|
|
const path = `${TEAMS}/${teamId}`;
|
|
|
|
return sendRequest("DELETE", path);
|
|
},
|
|
loadAll: ({
|
|
page = 0,
|
|
perPage = 100,
|
|
globalFilter = "",
|
|
}: ITeamSearchOptions = {}) => {
|
|
const { TEAMS } = endpoints;
|
|
|
|
// TODO: add this query param logic to client class
|
|
const pagination = `page=${page}&per_page=${perPage}`;
|
|
|
|
let searchQuery = "";
|
|
if (globalFilter !== "") {
|
|
searchQuery = `&query=${globalFilter}`;
|
|
}
|
|
|
|
const path = `${TEAMS}?${pagination}${searchQuery}`;
|
|
|
|
return sendRequest("GET", path);
|
|
},
|
|
update: (teamId: number, updateParams: IEditTeamFormData) => {
|
|
const { TEAMS } = endpoints;
|
|
const path = `${TEAMS}/${teamId}`;
|
|
|
|
return sendRequest("PATCH", path, updateParams);
|
|
},
|
|
addMembers: (teamId: number, newMembers: INewMembersBody) => {
|
|
const { TEAMS_MEMBERS } = endpoints;
|
|
const path = TEAMS_MEMBERS(teamId);
|
|
|
|
return sendRequest("PATCH", path, newMembers);
|
|
},
|
|
removeMembers: (teamId: number, removeMembers: IRemoveMembersBody) => {
|
|
const { TEAMS_MEMBERS } = endpoints;
|
|
const path = TEAMS_MEMBERS(teamId);
|
|
|
|
return sendRequest("DELETE", path, removeMembers);
|
|
},
|
|
transferHosts: (teamId: number, hostIds: number[]) => {
|
|
const { TEAMS_TRANSFER_HOSTS } = endpoints;
|
|
const path = TEAMS_TRANSFER_HOSTS(teamId);
|
|
|
|
return sendRequest("POST", path, { id: hostIds });
|
|
},
|
|
getEnrollSecrets: (teamId: number) => {
|
|
const { TEAMS_ENROLL_SECRETS } = endpoints;
|
|
const path = TEAMS_ENROLL_SECRETS(teamId);
|
|
|
|
return sendRequest("GET", path);
|
|
},
|
|
modifyEnrollSecrets: (teamId: number, secrets: IEnrollSecret[]) => {
|
|
const { TEAMS_ENROLL_SECRETS } = endpoints;
|
|
const path = TEAMS_ENROLL_SECRETS(teamId);
|
|
|
|
return sendRequest("PATCH", path, { secrets });
|
|
},
|
|
};
|