diff --git a/src/api/resolve.ts b/src/api/resolve.ts index f0ad59131..614544891 100644 --- a/src/api/resolve.ts +++ b/src/api/resolve.ts @@ -13,9 +13,17 @@ export type ApiResp = Promise< } >; -export const resolve: (promise: AxiosPromise) => ApiResp = async ( - promise -) => { +/** + * + * Takes a response from postgrest and extracts the pagination information from + * headers and adds it to the response object. + * + * https://docs.postgrest.org/en/v12/references/api/pagination_count.html + * + */ +export const resolvePostGrestRequestWithPagination: ( + promise: AxiosPromise +) => ApiResp = async (promise) => { try { const { data, headers } = await promise; const hasContentRangeHeader = !!headers["content-range"]?.trim(); diff --git a/src/api/schemaResources.ts b/src/api/schemaResources.ts index 2d7f47b50..330b354f3 100644 --- a/src/api/schemaResources.ts +++ b/src/api/schemaResources.ts @@ -12,7 +12,7 @@ import { import { AxiosResponse } from "axios"; import { AVATAR_INFO } from "../constants"; import { CanaryCheckerDB, ConfigDB, IncidentCommander } from "./axios"; -import { resolve } from "./resolve"; +import { resolvePostGrestRequestWithPagination } from "./resolve"; import { ConfigItem } from "./types/configs"; export interface SchemaResourceI { @@ -178,7 +178,7 @@ export async function getIntegrationsWithJobStatus( ) { const pagingParams = `&limit=${pageSize}&offset=${pageIndex * pageSize}`; - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( CanaryCheckerDB.get( // todo: add back created_by `integrations_with_status?order=created_at.desc&select=*&deleted_at=is.null${pagingParams}`, diff --git a/src/api/services/agents.ts b/src/api/services/agents.ts index e739391d1..bce25389e 100644 --- a/src/api/services/agents.ts +++ b/src/api/services/agents.ts @@ -1,7 +1,7 @@ import { Agent, AgentSummary } from "../../components/Agents/AgentPage"; import { AVATAR_INFO } from "../../constants"; import { AgentAPI, IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { AgentItem } from "../types/common"; export const Local = "00000000-0000-0000-0000-000000000000"; @@ -23,7 +23,7 @@ export const getAgentsList = async ( pageIndex || pageSize ? `&limit=${pageSize}&offset=${pageIndex! * pageSize!}` : ""; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/agents_summary?select=*,created_by(${AVATAR_INFO})&order=created_at.desc&${pagingParamsStr}${sortByParam}${sortOrderParam}`, { diff --git a/src/api/services/comments.ts b/src/api/services/comments.ts index e99e81aa2..5a3f1e0a5 100644 --- a/src/api/services/comments.ts +++ b/src/api/services/comments.ts @@ -1,10 +1,9 @@ import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; -import { NewComment } from "../types/incident"; -import { Comment } from "../types/incident"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; +import { Comment, NewComment } from "../types/incident"; export const getCommentsByHypothesis = (hypothesisId: string) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get( `/comments?select=*,created_by(id,name,avatar)&hypothesis_id=eq.${hypothesisId}&order=created_at.asc` ) @@ -16,7 +15,7 @@ export const createComment = async ({ hypothesisId, comment }: NewComment) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.post(`/comments`, { created_by: user.id, incident_id: incidentId, diff --git a/src/api/services/configs.ts b/src/api/services/configs.ts index 3fb445238..b38a3ed4e 100644 --- a/src/api/services/configs.ts +++ b/src/api/services/configs.ts @@ -4,7 +4,7 @@ import { } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect"; import { AnyMessageParams } from "yup/lib/types"; import { Catalog, Config, ConfigDB, IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { PaginationInfo } from "../types/common"; import { ConfigAnalysis, @@ -16,7 +16,7 @@ import { } from "../types/configs"; export const getAllConfigs = () => - resolve(ConfigDB.get(`/configs`)); + resolvePostGrestRequestWithPagination(ConfigDB.get(`/configs`)); export const getConfigsTags = async () => { const res = @@ -29,12 +29,12 @@ export const getAllConfigsMatchingQuery = (query: string) => { if (query) { url = `${url}&${query}`; } - return resolve(ConfigDB.get(url)); + return resolvePostGrestRequestWithPagination(ConfigDB.get(url)); }; export const getAllConfigsForSearchPurpose = async () => { let url = `/configs?select=id,name,config_class,type`; - const res = await resolve< + const res = await resolvePostGrestRequestWithPagination< Pick[] >(ConfigDB.get(url)); @@ -70,7 +70,7 @@ export const getConfigsSummary = async (request: ConfigSummaryRequest) => { }; export const getConfigsByIDs = async (ids: string[]) => { - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( ConfigDB.get( `/configs?id=in.(${ids.join(",")})&select=id,name,config_class,type` ) @@ -79,7 +79,7 @@ export const getConfigsByIDs = async (ids: string[]) => { }; export const getConfigsByID = async (id: string) => { - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( ConfigDB.get(`/configs?id=eq.${id}&select=id,name,config_class,type`) ); if (res.data && res.data.length > 0) { @@ -125,7 +125,7 @@ export const getAllChanges = ( queryString += `&and=(created_at.gte.${startsAt},created_at.lte.${endsAt})`; } - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/config_changes_items?order=created_at.desc${pagingParams}&select=id,change_type,summary,source,created_at,config_id,config:config_names!inner(id,name,type)${queryString}`, { @@ -138,7 +138,7 @@ export const getAllChanges = ( }; export const getConfig = (id: string) => - resolve( + resolvePostGrestRequestWithPagination( ConfigDB.get(`/config_detail?id=eq.${id}&select=*,config_scrapers(id,name)`) ); @@ -152,10 +152,14 @@ export const getConfigTagsList = () => { }; export const getConfigLabelsList = () => - resolve(ConfigDB.get(`/config_labels`)); + resolvePostGrestRequestWithPagination( + ConfigDB.get(`/config_labels`) + ); export const getConfigName = (id: string) => - resolve(ConfigDB.get(`/config_names?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + ConfigDB.get(`/config_names?id=eq.${id}`) + ); export const getConfigChanges = ( id: string, @@ -178,7 +182,7 @@ export const getConfigChanges = ( if (starts_at && ends_at) { paginationQueryParams += `&and=(created_at.gte.${starts_at},created_at.lte.${ends_at})`; } - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/config_changes?config_id=eq.${id}&order=created_at.desc${paginationQueryParams}`, { @@ -331,7 +335,9 @@ export async function getConfigsChanges({ } export const getConfigListFilteredByType = (types: string[]) => { - return resolve[]>( + return resolvePostGrestRequestWithPagination< + Pick[] + >( ConfigDB.get( `/config_items?select=id,name,type,config_class${ // if type is not provided, return all configs @@ -362,14 +368,14 @@ export const getConfigsBy = ({ const configFields = `id, type, name, config_class, deleted_at`; const deletedAt = hideDeleted ? `&deleted_at=is.null` : ""; if (topologyId) { - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/config_component_relationships?component_id=eq.${topologyId}&configs.order=name&select=*,configs!config_component_relationships_config_id_fkey(${configFields})${deletedAt}` ) ); } if (configId) { - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/config_relationships?or=(related_id.eq.${configId},config_id.eq.${configId})&configs.order=name&select=*,configs:configs!config_relationships_config_id_fkey(${configFields}),related:configs!config_relationships_related_id_fkey(${configFields})${deletedAt}` ) @@ -468,7 +474,7 @@ export const addManualComponentConfigRelationship = ( topologyId: string, configId: string ) => { - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.post(`/config_component_relationships`, { component_id: topologyId, config_id: configId, @@ -481,7 +487,7 @@ export const removeManualComponentConfigRelationship = ( topologyId: string, configId: string ) => { - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.delete( `/config_component_relationships?component_id=eq.${topologyId}&config_id=eq.${configId}&selector_id=eq.manual` ) @@ -492,7 +498,7 @@ export const searchConfigs = (type: string, input: string) => { const orCondition = input ? `&or=(name.ilike.*${input}*,external_id.ilike.*${input}*)` : ""; - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/configs?select=id,external_id,name,type,analysis,changes&type=ilike.${type}${orCondition}` ) @@ -500,7 +506,7 @@ export const searchConfigs = (type: string, input: string) => { }; export const createConfigItem = (type: string, params: {}) => - resolve( + resolvePostGrestRequestWithPagination( ConfigDB.post(`/config_item`, { type: type, ...params @@ -508,23 +514,29 @@ export const createConfigItem = (type: string, params: {}) => ); export const updateConfigItem = (id: string, params: {}) => - resolve( + resolvePostGrestRequestWithPagination( ConfigDB.patch(`/config_item?id=eq.${id}`, { ...params }) ); export const deleteConfigItem = (id: string) => - resolve(ConfigDB.delete(`/config_item?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + ConfigDB.delete(`/config_item?id=eq.${id}`) + ); // Saved Queries export const getAllSavedQueries = () => - resolve(ConfigDB.get(`/saved_query`)); + resolvePostGrestRequestWithPagination( + ConfigDB.get(`/saved_query`) + ); export const getSavedQuery = (id: string) => - resolve(ConfigDB.get(`/saved_query?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + ConfigDB.get(`/saved_query?id=eq.${id}`) + ); export const createSavedQuery = (query: string, params: any) => - resolve( + resolvePostGrestRequestWithPagination( ConfigDB.post(`/saved_query`, { query, ...params @@ -532,15 +544,19 @@ export const createSavedQuery = (query: string, params: any) => ); export const updateSavedQuery = (id: string, params: any) => - resolve(ConfigDB.patch(`/saved_query?id=eq.${id}`, { ...params })); + resolvePostGrestRequestWithPagination( + ConfigDB.patch(`/saved_query?id=eq.${id}`, { ...params }) + ); export const deleteSavedQuery = (id: string) => - resolve(ConfigDB.delete(`/saved_query?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + ConfigDB.delete(`/saved_query?id=eq.${id}`) + ); export const getConfigsByQuery = async (query: string) => { - const { data, error } = await resolve<{ results: { tags: any }[] }>( - Config.get(`/query?query=${query}`) - ); + const { data, error } = await resolvePostGrestRequestWithPagination<{ + results: { tags: any }[]; + }>(Config.get(`/query?query=${query}`)); if (error) { console.error(error); return []; @@ -618,7 +634,7 @@ export const getConfigInsights = ( pageIndex! * pageSize }`; } - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get< Pick< ConfigAnalysis, @@ -667,7 +683,7 @@ export const getTopologyRelatedInsights = async ( }`; } - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get< | { analysis_id: string; @@ -749,7 +765,7 @@ export const getAllConfigInsights = async ( : // default sort by first_observed "&order=first_observed.desc"; - return resolve( + return resolvePostGrestRequestWithPagination( ConfigDB.get( `/config_analysis_items?select=id,analysis_type,analyzer,severity,status,first_observed,last_observed,config:configs(id,name,config_class,type)${pagingParams}${queryParamsString}${sortString}`, { diff --git a/src/api/services/evidence.ts b/src/api/services/evidence.ts index 55e305ee6..875bc0e65 100644 --- a/src/api/services/evidence.ts +++ b/src/api/services/evidence.ts @@ -1,9 +1,11 @@ import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { Evidence } from "../types/evidence"; export const getEvidence = async (id: string) => - resolve(IncidentCommander.get(`/evidences?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + IncidentCommander.get(`/evidences?id=eq.${id}`) + ); export const createEvidence = async ( args: Omit @@ -25,7 +27,7 @@ export const createEvidence = async ( script } = args; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.post(`/evidences`, { config_id, config_analysis_id, @@ -46,14 +48,16 @@ export const createEvidence = async ( }; export const updateEvidence = async (id: string, params: Partial) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.patch(`/evidences?id=eq.${id}`, { ...params }) ); export const deleteEvidence = async (id: string) => - resolve(IncidentCommander.delete(`/evidences?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/evidences?id=eq.${id}`) + ); export const deleteEvidenceBulk = async (idList: string[]) => { let ids = ""; @@ -63,5 +67,7 @@ export const deleteEvidenceBulk = async (idList: string[]) => { ids += ","; } }); - return resolve(IncidentCommander.delete(`/evidences?id=in.(${ids})`)); + return resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/evidences?id=in.(${ids})`) + ); }; diff --git a/src/api/services/hypothesis.ts b/src/api/services/hypothesis.ts index 3c959cb50..92783fbde 100644 --- a/src/api/services/hypothesis.ts +++ b/src/api/services/hypothesis.ts @@ -1,5 +1,5 @@ import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { Evidence } from "../types/evidence"; import { Hypothesis, @@ -7,11 +7,11 @@ import { HypothesisStatus, NewHypothesis } from "../types/hypothesis"; -import { User } from "../types/users"; import { Comment } from "../types/incident"; +import { User } from "../types/users"; export const getAllHypothesisByIncident = (incidentId: string) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get( `/hypotheses?incident_id=eq.${incidentId}&order=created_at.asc` ) @@ -20,7 +20,7 @@ export const getAllHypothesisByIncident = (incidentId: string) => export const getHypothesis = async (id: string) => { const comments = `comments!comments_incident_id_fkey(id,created_by(id,name,avatar))`; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get(`/hypotheses?id=eq.${id}&select(*,${comments})`) ); }; @@ -30,7 +30,7 @@ export const getHypothesisResponse = async (id: string) => { "comments(id,*,created_by(id,name,avatar),responder_id(*,team_id(*)))"; const evidence = "evidences(id,*,created_by(id,name,avatar))"; - const { data, error } = await resolve< + const { data, error } = await resolvePostGrestRequestWithPagination< [ { id: string; @@ -52,14 +52,16 @@ export const getHypothesisResponse = async (id: string) => { }; export const searchHypothesis = (incidentId: string, query: string) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get( `/hypotheses?order=created_at.desc&title=ilike.*${query}*&incident_id=eq.${incidentId}` ) ); export const createHypothesis = async ({ user, ...params }: NewHypothesis) => { - const { data, error } = await resolve<[Hypothesis]>( + const { data, error } = await resolvePostGrestRequestWithPagination< + [Hypothesis] + >( IncidentCommander.post(`/hypotheses`, { ...params, created_by: user.id @@ -100,9 +102,15 @@ export const updateHypothesis = ( // NOTE: Needs to be a database transaction. Possibility of partial deletes. export const deleteHypothesis = async (id: string) => { - await resolve(IncidentCommander.delete(`/comments?hypothesis_id=eq.${id}`)); - await resolve(IncidentCommander.delete(`/evidences?hypothesis_id=eq.${id}`)); - return resolve(IncidentCommander.delete(`/hypotheses?id=eq.${id}`)); + await resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/comments?hypothesis_id=eq.${id}`) + ); + await resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/evidences?hypothesis_id=eq.${id}`) + ); + return resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/hypotheses?id=eq.${id}`) + ); }; export const deleteHypothesisBulk = async (idList: string[]) => { @@ -113,5 +121,7 @@ export const deleteHypothesisBulk = async (idList: string[]) => { ids += ","; } }); - return resolve(IncidentCommander.delete(`/hypotheses?id=in.(${ids})`)); + return resolvePostGrestRequestWithPagination( + IncidentCommander.delete(`/hypotheses?id=in.(${ids})`) + ); }; diff --git a/src/api/services/incident.ts b/src/api/services/incident.ts index e8215e8ff..c0c24ab97 100644 --- a/src/api/services/incident.ts +++ b/src/api/services/incident.ts @@ -1,7 +1,7 @@ import { stringify } from "qs"; import { AVATAR_INFO } from "../../constants"; import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { Incident, IncidentStatus, @@ -12,7 +12,7 @@ import { User } from "../types/users"; export const searchIncident = (query: string) => { const hypotheses = `hypotheses(id, type)`; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/incidents?order=created_at.desc&title=ilike.*${query}*&select=*,${hypotheses}` ) @@ -21,7 +21,7 @@ export const searchIncident = (query: string) => { export const getAllIncident = ({ limit = 10 }) => { const limitStr = limit ? `limit=${limit}` : ""; const hypotheses = `hypotheses(id, type)`; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/incidents?order=created_at.desc&${limitStr}&select=*,${hypotheses}` ) @@ -31,7 +31,7 @@ export const getAllIncident = ({ limit = 10 }) => { export const getIncident = async (id: string) => { const hypotheses = `hypotheses(*,created_by(${AVATAR_INFO}),evidences(*,created_by(${AVATAR_INFO})),comments(created_at,comment,external_created_by,responder_id(team_id(*)),created_by(id,${AVATAR_INFO}),id))`; - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( IncidentCommander.get( `/incidents?id=eq.${id}&select=*,${hypotheses},commander:commander_id(${AVATAR_INFO}),communicator_id(${AVATAR_INFO}),responders(created_by(${AVATAR_INFO}))` ) @@ -65,14 +65,14 @@ export const getIncidentsBy = async ({ if (topologyId) { params["component_id"] = `eq.${topologyId}`; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `incidents_by_component?${stringify(params)}` ) ); } else { params["config_id"] = `eq.${configId}`; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `incidents_by_config?${stringify(params)}` ) @@ -86,7 +86,9 @@ export const getIncidentsSummary = async ( const { search = "" } = params!; const searchStr = search ? `&title=ilike.*${search}*` : ""; const { search: _, ...filters } = params ?? {}; - const { data } = await resolve( + const { data } = await resolvePostGrestRequestWithPagination< + IncidentSummary[] | null + >( IncidentCommander.get( `/incident_summary?${searchStr}&order=created_at.desc`, { @@ -110,7 +112,7 @@ export const getIncidentsWithParams = async ( const searchStr = search ? `&title=ilike.*${search}*` : ""; const { search: _, ...filters } = params!; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/incidents?${searchStr}&select=*,${hypotheses},${comments},commander_id(${AVATAR_INFO}),communicator_id(${AVATAR_INFO}),${responder}&order=created_at.desc`, { @@ -147,9 +149,9 @@ export const createIncident = async ( communicator_id: user.id }; - const { data, error } = await resolve( - IncidentCommander.post(`/incidents?select=*`, params) - ); + const { data, error } = await resolvePostGrestRequestWithPagination< + Incident[] + >(IncidentCommander.post(`/incidents?select=*`, params)); if (error) { return { error }; diff --git a/src/api/services/jobsHistory.ts b/src/api/services/jobsHistory.ts index 6e8de7671..5c42bab42 100644 --- a/src/api/services/jobsHistory.ts +++ b/src/api/services/jobsHistory.ts @@ -1,7 +1,7 @@ import { tristateOutputToQueryFilterParam } from "@flanksource-ui/ui/Dropdowns/TristateReactSelect"; import { JobHistory } from "../../components/JobsHistory/JobsHistoryTable"; import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; export type GetJobsHistoryParams = { pageIndex: number; @@ -55,7 +55,7 @@ export const getJobsHistory = async ({ ? `&and=(created_at.gt.${startsAt},created_at.lt.${endsAt})` : ""; - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/job_histories?&select=*${pagingParams}${resourceTypeParam}${resourceIdParam}${nameParam}${statusParam}${sortByParam}${sortOrderParam}${rangeParam}${durationParam}`, { @@ -72,7 +72,7 @@ export type JobHistoryNames = { }; export const getJobsHistoryNames = async () => { - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( IncidentCommander.get( `/job_history_names?order=name.asc` ) diff --git a/src/api/services/notifications.ts b/src/api/services/notifications.ts index 1709d3493..3e7a56ea8 100644 --- a/src/api/services/notifications.ts +++ b/src/api/services/notifications.ts @@ -1,10 +1,10 @@ import { Notification } from "../../components/Notifications/notificationsTableColumns"; import { AVATAR_INFO } from "../../constants"; import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; export const getNotificationsSummary = async () => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/notifications_summary?select=*,person:person_id(${AVATAR_INFO}),team:team_id(id,name,icon),created_by(${AVATAR_INFO})&order=created_at.desc`, { diff --git a/src/api/services/playbooks.ts b/src/api/services/playbooks.ts index 7fb344c93..209e53851 100644 --- a/src/api/services/playbooks.ts +++ b/src/api/services/playbooks.ts @@ -2,7 +2,7 @@ import { SubmitPlaybookRunFormValues } from "@flanksource-ui/components/Playbook import { AVATAR_INFO } from "@flanksource-ui/constants"; import { ConfigDB, IncidentCommander, PlaybookAPI } from "../axios"; import { GetPlaybooksToRunParams } from "../query-hooks/playbooks"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { NewPlaybookSpec, PlaybookNames, @@ -180,7 +180,7 @@ export async function getPlaybookRuns({ ? `&playbook_id=eq.${playbookId}` : ""; - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( ConfigDB.get( `/playbook_runs?select=*,playbooks(id,name,spec,icon),component:components(id,name,icon),check:checks(id,name,icon),config:config_items(id,name,type,config_class)&&order=created_at.desc${playbookParamsString}${componentParamString}&${configParamString}${pagingParams}${statusParamString}${dateFilter}`, { diff --git a/src/api/services/properties.ts b/src/api/services/properties.ts index 2826ed9fd..264a28555 100644 --- a/src/api/services/properties.ts +++ b/src/api/services/properties.ts @@ -4,16 +4,16 @@ import { PropertyDBObject } from "../../services/permissions/permissionsService"; import { IncidentCommander, apiBase } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; export const fetchProperties = () => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get(`/properties?select=*,created_by(${AVATAR_INFO})`) ); }; export const fetchProperty = (name: string, value: string) => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.get( `/properties?select=*,created_by(${AVATAR_INFO})&name=eq.${name}&value=eq.${value}` ) @@ -21,23 +21,25 @@ export const fetchProperty = (name: string, value: string) => { }; export const fetchFeatureFlagsAPI = () => { - return resolve(apiBase.get(`/properties`)); + return resolvePostGrestRequestWithPagination( + apiBase.get(`/properties`) + ); }; export const saveProperty = (property: Partial) => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.post("/properties", property) ); }; export const updateProperty = (property: Partial) => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.patch(`/properties?name=eq.${property.name}`, property) ); }; export const deleteProperty = (property: Partial) => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.delete(`/properties?name=eq.${property.name}`) ); }; diff --git a/src/api/services/responder.ts b/src/api/services/responder.ts index 434758762..6fe51da7e 100644 --- a/src/api/services/responder.ts +++ b/src/api/services/responder.ts @@ -1,16 +1,21 @@ import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { Responder } from "../types/incident"; export const getResponder = async (ids: string[]) => - resolve(IncidentCommander.get(`/person?id=in.(${ids})`)); + resolvePostGrestRequestWithPagination( + IncidentCommander.get(`/person?id=in.(${ids})`) + ); export const saveResponder = ( params: Omit -) => resolve(IncidentCommander.post(`/responders?select=*`, params)); +) => + resolvePostGrestRequestWithPagination( + IncidentCommander.post(`/responders?select=*`, params) + ); export const getRespondersForTheIncident = async (id: string) => { - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination( IncidentCommander.get( `/responders?incident_id=eq.${id}&select=*,team:team_id(id,name,icon,spec),person:person_id(id,name,avatar)&deleted_at=is.null` ) diff --git a/src/api/services/teams.ts b/src/api/services/teams.ts index 298066c4a..73ccea014 100644 --- a/src/api/services/teams.ts +++ b/src/api/services/teams.ts @@ -1,5 +1,5 @@ import { IncidentCommander } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { Team, User } from "../types/users"; export const getTeam = async (id: string): Promise => { @@ -35,11 +35,13 @@ export const addUserToTeam = (teamId: string, userIds: string[]) => { person_id: userId }; }); - return resolve(IncidentCommander.post(`/team_members`, payload)); + return resolvePostGrestRequestWithPagination( + IncidentCommander.post(`/team_members`, payload) + ); }; export const removeUserFromTeam = (userId: string) => { - return resolve( + return resolvePostGrestRequestWithPagination( IncidentCommander.delete(`/team_members?person_id=eq.${userId}`) ); }; diff --git a/src/api/services/topology.ts b/src/api/services/topology.ts index 99aac0edd..399a7f54b 100644 --- a/src/api/services/topology.ts +++ b/src/api/services/topology.ts @@ -6,7 +6,7 @@ import { IncidentCommander, Snapshot } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { SchemaResourceI } from "../schemaResources"; import { PaginationInfo } from "../types/common"; import { @@ -182,7 +182,7 @@ export const getCheckStatuses = ( queryString = `${queryString}&limit=${pageSize}&offset=${ pageIndex * pageSize }`; - return resolve( + return resolvePostGrestRequestWithPagination( CanaryCheckerDB.get( `/check_statuses?${queryString}`, { @@ -234,7 +234,9 @@ export const getComponentTemplate = async (id: string) => { }; export const getHealthCheckSummary = async (id: string) => { - const res = await resolve( + const res = await resolvePostGrestRequestWithPagination< + HealthCheckSummary[] | null + >( IncidentCommander.get(`/checks?id=eq.${id}&select=id,name,icon,status,type`) ); if (res.data && res.data.length > 0) { @@ -244,7 +246,9 @@ export const getHealthCheckSummary = async (id: string) => { }; export const getHealthCheckDetails = async (id: string) => { - const res = await resolve[] | null>( + const res = await resolvePostGrestRequestWithPagination< + Omit[] | null + >( IncidentCommander.get( `/checks?id=eq.${id}&select=*,canaries(id,name,source),agents(id, name),components:check_component_relationships(components(id,name,icon)),configs:check_config_relationships(configs(id,name,type))` ) diff --git a/src/api/services/users.ts b/src/api/services/users.ts index a8bf508b8..276cfaf5c 100644 --- a/src/api/services/users.ts +++ b/src/api/services/users.ts @@ -1,29 +1,35 @@ import { Auth, CanaryChecker, IncidentCommander, Rback } from "../axios"; -import { resolve } from "../resolve"; +import { resolvePostGrestRequestWithPagination } from "../resolve"; import { VersionInfo } from "../types/common"; import { NewUser, PeopleRoles, RegisteredUser, User } from "../types/users"; export const getPerson = (id: string) => - resolve(IncidentCommander.get(`/people?id=eq.${id}`)); + resolvePostGrestRequestWithPagination( + IncidentCommander.get(`/people?id=eq.${id}`) + ); export const getPersons = () => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get(`/people?select=*&order=name.asc`) ); export const getPersonWithEmail = (email: string) => - resolve(IncidentCommander.get(`/people?email=eq.${email}`)); + resolvePostGrestRequestWithPagination( + IncidentCommander.get(`/people?email=eq.${email}`) + ); export const createPerson = ({ name, email, avatar }: NewUser) => - resolve(IncidentCommander.post("/people", { name, email, avatar })); + resolvePostGrestRequestWithPagination( + IncidentCommander.post("/people", { name, email, avatar }) + ); export const fetchPeopleRoles = (personIds: string[]) => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get(`/people_roles?id=in.(${personIds.toString()})`) ); export const getRegisteredUsers = () => - resolve( + resolvePostGrestRequestWithPagination( IncidentCommander.get(`/identities`).then(async (res) => { const { data: peopleRoles } = await fetchPeopleRoles( res.data.map((item: { id: string }) => item.id) @@ -57,12 +63,12 @@ export type InviteUserPayload = { }; export const inviteUser = ({ firstName, lastName, email }: InviteUserPayload) => - resolve<{ + resolvePostGrestRequestWithPagination<{ id: string; }>(Auth.post("/invite_user", { firstName, lastName, email })); export const getVersionInfo = () => - resolve( + resolvePostGrestRequestWithPagination( CanaryChecker.get("/about").then((data) => { const versionInfo: any = data.data || {}; data.data = { @@ -74,7 +80,7 @@ export const getVersionInfo = () => ); export const updateUserRole = (userId: string, roles: string[]) => { - return resolve<{ + return resolvePostGrestRequestWithPagination<{ message: string; }>( Rback.post(`/${userId}/update_role`, { @@ -84,7 +90,9 @@ export const updateUserRole = (userId: string, roles: string[]) => { }; export const deleteUser = (userId: string) => - resolve<{}>(IncidentCommander.delete(`/identities?id=eq.${userId}`)); + resolvePostGrestRequestWithPagination<{}>( + IncidentCommander.delete(`/identities?id=eq.${userId}`) + ); export type WhoamiResponse = { message: string;