updated existing api calls

This commit is contained in:
csawatzky 2025-02-24 15:40:24 -06:00
parent ade15fdfdc
commit c74a7490d9
12 changed files with 1509 additions and 698 deletions

View file

@ -10,19 +10,19 @@ import { has } from "utils/types";
import { pondURL } from "./pond";
export interface IInteractionsAPIContext {
addInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<any>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings) => Promise<any>;
addInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteractionToComponents: (
fullComponentLocations: string[],
settings: pond.IInteractionSettings
) => Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>;
updateInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<any>;
updateInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
updateInteractionPondSettings: (
device: number,
interaction: string,
settings: pond.IInteractionPondSettings
) => Promise<any>;
removeInteraction: (device: number, interaction: string) => Promise<any>;
) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>;
removeInteraction: (device: number, interaction: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean) => Promise<Interaction[]>;
listInteractionsByComponent: (
device: number,
@ -59,10 +59,17 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const [{ as }] = useGlobalState();
const addInteraction = (device: number, settings: pond.IInteractionSettings) => {
return post(
pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")),
sanitizeInteraction(settings)
);
return new Promise<AxiosResponse<pond.AddInteractionResponse>>((resolve, reject) => {
post<pond.AddInteractionResponse>(
pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")),
sanitizeInteraction(settings)
).then(resp => {
resp.data = pond.AddInteractionResponse.fromObject(resp)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
/**
@ -75,37 +82,52 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
fullComponentLocations: string[],
settings: pond.IInteractionSettings
) => {
return post<pond.AddInteractionToComponentsResponse>(
pondURL(
"/interactions/forComponents/" +
"?componentIds=" +
fullComponentLocations.toString() +
(as ? "&as=" + as : "")
),
sanitizeInteraction(settings)
);
let url = pondURL(
"/interactions/forComponents/" +
"?componentIds=" +
fullComponentLocations.toString() +
(as ? "&as=" + as : "")
)
return new Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>((resolve, reject) => {
post<pond.AddInteractionToComponentsResponse>(url,sanitizeInteraction(settings)).then(resp => {
resp.data = pond.AddInteractionToComponentsResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings) => {
return post(
pondURL("/devices/" + device + "/interactions/multi" + (as ? "?as=" + as : "")),
settings
);
let url = pondURL("/devices/" + device + "/interactions/multi" + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>((resolve, reject) => {
post<pond.AddMultiInteractionsResponse>(url,settings).then(resp => {
resp.data = pond.AddMultiInteractionsResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
const updateInteraction = (device: number, settings: pond.IInteractionSettings) => {
return put(
pondURL(
"/devices/" +
device +
"/interactions?keys=" +
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
),
sanitizeInteraction(settings)
);
let url = pondURL(
"/devices/" +
device +
"/interactions?keys=" +
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
)
return new Promise<AxiosResponse<pond.UpdateInteractionResponse>>((resolve, reject) => {
put<pond.UpdateInteractionResponse>(url,sanitizeInteraction(settings)).then(resp => {
resp.data = pond.UpdateInteractionResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
const updateInteractionPondSettings = (
@ -113,26 +135,38 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
interaction: string,
settings: pond.IInteractionPondSettings
) => {
return put(
pondURL(
"/devices/" +
device +
"/interactions/" +
interaction +
"/interactionPondSettings?keys=" +
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
),
sanitizeInteraction(settings)
);
let url = pondURL(
"/devices/" +
device +
"/interactions/" +
interaction +
"/interactionPondSettings?keys=" +
[device] +
"&types=" +
["device"] +
(as ? "&as=" + as : "")
)
return new Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>((resolve, reject) => {
put<pond.UpdateInteractionPondSettingsResponse>(url, sanitizeInteraction(settings)).then(resp => {
resp.data = pond.UpdateInteractionPondSettingsResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
const removeInteraction = (device: number, interaction: string) => {
return del(
pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : ""))
);
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => {
del<pond.RemoveInteractionResponse>(url).then(resp => {
resp.data = pond.RemoveInteractionResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
const listInteractionsByDevice = (
@ -223,10 +257,15 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const setAlertInteractions = (
alerts: pond.AlertData[]
): Promise<AxiosResponse<pond.SetAlertInteractionsResponse>> => {
return post<pond.SetAlertInteractionsResponse>(
pondURL("/interactions/setAlerts" + (as ? "?as=" + as : "")),
{ data: alerts }
);
let url = pondURL("/interactions/setAlerts" + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>((resolve, reject) => {
post<pond.SetAlertInteractionsResponse>(url, { data: alerts }).then(resp => {
resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data)
return resolve(resp)
}).catch(err => {
return reject(err)
})
})
};
return (