updated the bin yard api with as fix

This commit is contained in:
csawatzky 2025-04-17 14:35:24 -06:00
parent e2f5eb0557
commit 76744c1b6f
5 changed files with 26 additions and 22 deletions

View file

@ -7,14 +7,15 @@ import { AxiosResponse } from "axios";
import { useGlobalState } from "providers";
export interface IBinYardAPIContext {
addBinYard: (bin: pond.BinYardSettings) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
updateBinYard: (
key: string,
binYard: pond.BinYardSettings,
asRoot?: true
asRoot?: true,
as?: string
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
removeBinYard: (key: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
getBinYard: (key: string) => Promise<AxiosResponse<pond.BinYard>>;
removeBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
getBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.BinYard>>;
listBinYards: (
limit: number,
offset: number,
@ -22,7 +23,8 @@ export interface IBinYardAPIContext {
orderBy?: string,
search?: string,
asRoot?: boolean,
specificUser?: string
specificUser?: string,
as?: string
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
}
@ -33,14 +35,14 @@ interface Props {}
export default function BinYardProvider(props: PropsWithChildren<Props>) {
const { children } = props;
const { get, post, put, del } = useHTTP();
const [{ as }] = useGlobalState();
//const [{ as }] = useGlobalState();
const addBinYard = (binYard: pond.BinYardSettings) => {
const addBinYard = (binYard: pond.BinYardSettings, as?: string) => {
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${as}`), binYard);
return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard);
};
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean) => {
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => {
if (as) {
if (asRoot) {
return put<pond.UpdateBinYardResponse>(
@ -58,12 +60,12 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
);
};
const removeBinYard = (key: string) => {
const removeBinYard = (key: string, as?: string) => {
if (as) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + as));
return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key));
};
const getBinYard = (key: string) => {
const getBinYard = (key: string, as?: string) => {
if (as) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + as));
return get<pond.BinYard>(pondURL("/binYard/" + key));
};
@ -75,7 +77,8 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
orderBy?: string,
search?: string,
asRoot?: boolean,
specificUser?: string
specificUser?: string,
as?: string
) => {
let asText = "";
if (as) asText = "&as=" + as;