fleet/frontend/services/entities/queries.ts
RachelElysia bb11f5008f
Frontend tech debt: Clean up 409 lint warnings (#3703)
* Clean up unused variables, return types, many quick type any
2022-02-14 17:11:12 -05:00

71 lines
1.6 KiB
TypeScript

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import sendRequest from "services";
import endpoints from "fleet/endpoints";
import { IQueryFormData } from "interfaces/query";
export default {
create: ({ description, name, query, observer_can_run }: IQueryFormData) => {
const { QUERIES } = endpoints;
return sendRequest("POST", QUERIES, {
description,
name,
query,
observer_can_run,
});
},
destroy: (id: string | number) => {
const { QUERIES } = endpoints;
const path = `${QUERIES}/id/${id}`;
return sendRequest("DELETE", path);
},
load: (id: number) => {
const { QUERIES } = endpoints;
const path = `${QUERIES}/${id}`;
return sendRequest("GET", path);
},
loadAll: () => {
const { QUERIES } = endpoints;
return sendRequest("GET", QUERIES);
},
run: async ({
query,
queryId,
selected,
}: {
query: string;
queryId: number | null;
selected: any;
}) => {
const { RUN_QUERY } = endpoints;
try {
const { campaign } = await sendRequest("POST", RUN_QUERY, {
query,
query_id: queryId,
selected,
});
return {
...campaign,
hosts_count: {
successful: 0,
failed: 0,
total: 0,
},
};
} catch (error) {
console.error(error);
throw new Error("Could not run query.");
}
},
update: (id: number, updateParams: IQueryFormData) => {
const { QUERIES } = endpoints;
const path = `${QUERIES}/${id}`;
return sendRequest("PATCH", path, JSON.stringify(updateParams));
},
};