updated as in the objectHeaterApi

This commit is contained in:
csawatzky 2025-04-21 14:39:04 -06:00
parent 59356aad27
commit 29902bc40b
6 changed files with 25 additions and 22 deletions

View file

@ -122,7 +122,7 @@ export default function SiteDrawer(props: Props) {
"write",
"grant",
"revoke"
])
], as)
.then(resp => {
setLinkDrawer(false);
reLoadSites();
@ -184,7 +184,7 @@ export default function SiteDrawer(props: Props) {
return (
<React.Fragment>
{/* {deviceLinkDrawer()} */}
{deviceLinkDrawer()}
<DisplayDrawer
open={open}
onClose={closeDrawer}

View file

@ -138,7 +138,7 @@ export default function ObjectHeaterSettings(props: Props) {
settings.airCirculation = airCirculation;
settings.mutations = linearMutations;
objectHeaterAPI
.updateObjectHeater(heater.key, heaterName, settings)
.updateObjectHeater(heater.key, heaterName, settings, as)
.then(resp => {
openSnack("Heater update");
let updatedHeater = heater;
@ -161,7 +161,7 @@ export default function ObjectHeaterSettings(props: Props) {
mutations: linearMutations
});
objectHeaterAPI
.addObjectHeater(heaterName, settings)
.addObjectHeater(heaterName, settings, as)
.then(resp => {
openSnack("New heater added");
let newHeater = ObjectHeater.create(
@ -178,7 +178,7 @@ export default function ObjectHeaterSettings(props: Props) {
const removeHeater = () => {
if (heater) {
objectHeaterAPI
.removeObjectHeater(heater.key)
.removeObjectHeater(heater.key, as)
.then(resp => {
openSnack("Heater Removed");
setRemoveDialog(false);

View file

@ -140,7 +140,7 @@ export default function Heater() {
} else {
//if the heater was not carried from the heaters page, ie. page was reloaded, we will need to load the heater from the backend
heaterAPI
.getObjectHeater(heaterID)
.getObjectHeater(heaterID, as)
.then(resp => {
let h = ObjectHeater.any(resp.data.heater);
setHeater(h);
@ -192,7 +192,7 @@ export default function Heater() {
let deviceID = displayDevice.device?.settings?.deviceId;
if (deviceID) {
heaterAPI
.updateLink(heater.key, "objectHeater", deviceID.toString(), "device", [])
.updateLink(heater.key, "objectHeater", deviceID.toString(), "device", [], as)
.then(resp => {
if (deviceID) {
devices.delete(deviceID.toString());
@ -205,7 +205,7 @@ export default function Heater() {
let updatedHeater = heater;
updatedHeater.settings.mutations = [];
heaterAPI
.updateObjectHeater(heater.key, heater.name, updatedHeater.settings)
.updateObjectHeater(heater.key, heater.name, updatedHeater.settings, as)
.then(resp => {
setHeater(updatedHeater);
setDisplayedMutations([...updatedHeater.settings.mutations]);
@ -234,7 +234,7 @@ export default function Heater() {
"write",
"grant",
"revoke"
])
], as)
.then(resp => {
if (deviceID) {
devices.set(deviceID.toString(), dev);

View file

@ -155,7 +155,7 @@ export default function Heaters() {
"write",
"grant",
"revoke"
])
], as)
.then(resp => {
if (deviceID) {
devices.set(deviceID.toString(), dev);

View file

@ -178,7 +178,7 @@ export default function Site() {
"write",
"grant",
"revoke"
])
], as)
.then(resp => {
if (deviceID) {
devices.set(deviceID.toString(), dev);

View file

@ -9,9 +9,10 @@ import { pondURL } from "./pond";
export interface IObjectHeaterAPIContext {
addObjectHeater: (
name: string,
heater: pond.ObjectHeaterSettings
heater: pond.ObjectHeaterSettings,
as?: string
) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>;
getObjectHeater: (key: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
getObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
listObjectHeaters: (
limit: number,
offset: number,
@ -24,19 +25,20 @@ export interface IObjectHeaterAPIContext {
types?: string[],
numerical?: boolean
) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>;
removeObjectHeater: (key: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
removeObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
updateObjectHeater: (
key: string,
name: string,
settings: pond.ObjectHeaterSettings,
asRoot?: true
as?: string
) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>;
updateLink: (
parentKey: string,
parentType: string,
objectID: string,
objectType: string,
permissions: string[]
permissions: string[],
as?: string
) => Promise<any>;
listObjectHeatersPageData: (
limit: number,
@ -58,9 +60,9 @@ interface Props {}
export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState();
//const [{ as }] = useGlobalState();
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings) => {
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
if (as)
return post<pond.AddObjectHeaterResponse>(
pondURL("/objectHeaters?name=" + name + "&as=" + as),
@ -69,14 +71,14 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings);
};
const getObjectHeater = (key: string) => {
const getObjectHeater = (key: string, as?: string) => {
if (as) {
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
}
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
};
const removeObjectHeater = (key: string) => {
const removeObjectHeater = (key: string, as?: string) => {
if (as)
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
@ -113,7 +115,7 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
);
};
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings) => {
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
if (as) {
return put<pond.UpdateObjectHeaterResponse>(
pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name),
@ -131,7 +133,8 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
parentType: string,
objectID: string,
objectType: string,
permissions: string[]
permissions: string[],
as?: string
) => {
if (as)
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), {