updated as in the interactions api

This commit is contained in:
csawatzky 2025-04-21 16:40:30 -06:00
parent e8e32e1886
commit c617ebf868
12 changed files with 66 additions and 50 deletions

View file

@ -10,27 +10,31 @@ import { has } from "utils/types";
import { pondURL } from "./pond";
export interface IInteractionsAPIContext {
addInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteractionToComponents: (
fullComponentLocations: string[],
settings: pond.IInteractionSettings
settings: pond.IInteractionSettings,
as?: string
) => Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>;
updateInteraction: (device: number, settings: pond.IInteractionSettings) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
updateInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
updateInteractionPondSettings: (
device: number,
interaction: string,
settings: pond.IInteractionPondSettings
settings: pond.IInteractionPondSettings,
as?: string
) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>;
removeInteraction: (device: number, interaction: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean) => Promise<Interaction[]>;
removeInteraction: (device: number, interaction: string, as?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean, as?: string) => Promise<Interaction[]>;
listInteractionsByComponent: (
device: number,
component: quack.ComponentID,
demo?: boolean
demo?: boolean,
as?: string
) => Promise<Interaction[]>;
setAlertInteractions: (
alerts: pond.AlertData[]
alerts: pond.AlertData[],
as?: string
) => Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>;
}
@ -56,9 +60,9 @@ function sanitizeInteraction(interaction: pond.IInteractionSettings): pond.IInte
export default function InteractionProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, post, put, del } = useHTTP();
const [{ as }] = useGlobalState();
//const [{ as }] = useGlobalState();
const addInteraction = (device: number, settings: pond.IInteractionSettings) => {
const addInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => {
return new Promise<AxiosResponse<pond.AddInteractionResponse>>((resolve, reject) => {
post<pond.AddInteractionResponse>(
pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")),
@ -80,7 +84,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
*/
const addInteractionToComponents = (
fullComponentLocations: string[],
settings: pond.IInteractionSettings
settings: pond.IInteractionSettings,
as?: string
) => {
let url = pondURL(
"/interactions/forComponents/" +
@ -98,7 +103,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings) => {
const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, as?: string) => {
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 => {
@ -110,7 +115,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
const updateInteraction = (device: number, settings: pond.IInteractionSettings) => {
const updateInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => {
let url = pondURL(
"/devices/" +
device +
@ -133,7 +138,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const updateInteractionPondSettings = (
device: number,
interaction: string,
settings: pond.IInteractionPondSettings
settings: pond.IInteractionPondSettings,
as?: string
) => {
let url = pondURL(
"/devices/" +
@ -156,7 +162,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
})
};
const removeInteraction = (device: number, interaction: string) => {
const removeInteraction = (device: number, interaction: string, as?: string) => {
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => {
del<pond.RemoveInteractionResponse>(url).then(resp => {
@ -171,7 +177,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const listInteractionsByDevice = (
device: number | string,
demo: boolean = false
demo: boolean = false,
as?: string
): Promise<Interaction[]> => {
return new Promise((resolve, reject) => {
get(pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : ""), demo))
@ -209,7 +216,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const listInteractionsByComponent = (
device: number,
component: quack.ComponentID,
demo: boolean = false
demo: boolean = false,
as?: string
): Promise<Interaction[]> => {
return new Promise((resolve, reject) => {
get(
@ -255,7 +263,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
};
const setAlertInteractions = (
alerts: pond.AlertData[]
alerts: pond.AlertData[],
as?: string
): Promise<AxiosResponse<pond.SetAlertInteractionsResponse>> => {
let url = pondURL("/interactions/setAlerts" + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>((resolve, reject) => {