update as in the transaction api

This commit is contained in:
csawatzky 2025-04-21 15:10:18 -06:00
parent ae458c3fca
commit 4912d319ff
4 changed files with 21 additions and 15 deletions

View file

@ -144,7 +144,7 @@ export default function ContractTransactionTable(props: Props) {
//use the transaction api to revoke the transaction //use the transaction api to revoke the transaction
//--moved all the functionality for adjusting the objects involved to the backend so this can be handled with a single call-- //--moved all the functionality for adjusting the objects involved to the backend so this can be handled with a single call--
transactionAPI transactionAPI
.revokeTransaction(activeTransaction.transaction.key) .revokeTransaction(activeTransaction.transaction.key, as)
.then(resp => { .then(resp => {
openSnack("Transaction revoked and inventory moved back"); openSnack("Transaction revoked and inventory moved back");
transactionRevokedCallback(activeTransaction.transaction.key); transactionRevokedCallback(activeTransaction.transaction.key);

View file

@ -248,7 +248,7 @@ export default function GrainTransaction(props: Props) {
grainTransaction.subtype = obj.subtype(); grainTransaction.subtype = obj.subtype();
} }
} }
transactionAPI.addTransaction(newTransaction, imageIDs).then(resp => { transactionAPI.addTransaction(newTransaction, imageIDs, as).then(resp => {
newTransaction.key = resp.data.key; newTransaction.key = resp.data.key;
closeDialogs(true, newTransaction); closeDialogs(true, newTransaction);
}); });

View file

@ -8,7 +8,7 @@ import TransactionViewer from "transactions/transactionViewer";
import { TransactionOptions } from "objects/ObjectDescriber"; import { TransactionOptions } from "objects/ObjectDescriber";
import { GetDefaultDateRange } from "common/time/DateRange"; import { GetDefaultDateRange } from "common/time/DateRange";
import TimeBar from "common/time/TimeBar"; import TimeBar from "common/time/TimeBar";
import { useTransactionAPI } from "providers"; import { useGlobalState, useTransactionAPI } from "providers";
import { Transaction } from "models/Transaction"; import { Transaction } from "models/Transaction";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
@ -40,6 +40,7 @@ export default function Transactions() {
const [objectNames, setObjectNames] = useState<Map<string, string>>(new Map()); const [objectNames, setObjectNames] = useState<Map<string, string>>(new Map());
const [fromName, setFromName] = useState(""); const [fromName, setFromName] = useState("");
const [toName, setToName] = useState(""); const [toName, setToName] = useState("");
const [{as}] = useGlobalState();
const updateDateRange = (newStartDate: any, newEndDate: any) => { const updateDateRange = (newStartDate: any, newEndDate: any) => {
let range = GetDefaultDateRange(); let range = GetDefaultDateRange();
@ -78,7 +79,7 @@ export default function Transactions() {
if (!isLoading) { if (!isLoading) {
setIsLoading(true); setIsLoading(true);
transactionAPI transactionAPI
.transactionPageData(startDate.toISOString(), endDate.toISOString()) .transactionPageData(startDate.toISOString(), endDate.toISOString(), as)
.then(resp => { .then(resp => {
setTotalTransactions( setTotalTransactions(
resp.data.transactions.map((t: pond.Transaction) => Transaction.create(t)) resp.data.transactions.map((t: pond.Transaction) => Transaction.create(t))

View file

@ -8,11 +8,13 @@ import { useGlobalState } from "providers";
export interface ITransactionAPIContext { export interface ITransactionAPIContext {
addTransaction: ( addTransaction: (
transaction: pond.Transaction, transaction: pond.Transaction,
fileIDs?: string[] fileIDs?: string[],
as?: string
) => Promise<AxiosResponse<pond.AddTransactionResponse>>; ) => Promise<AxiosResponse<pond.AddTransactionResponse>>;
transactionPageData: ( transactionPageData: (
start: string, start: string,
end: string end: string,
as?: string
) => Promise<AxiosResponse<pond.TransactionPageDataResponse>>; ) => Promise<AxiosResponse<pond.TransactionPageDataResponse>>;
listTransactions: ( listTransactions: (
start: string, start: string,
@ -20,12 +22,14 @@ export interface ITransactionAPIContext {
fromObject?: pond.ObjectType, fromObject?: pond.ObjectType,
toObject?: pond.ObjectType, toObject?: pond.ObjectType,
fromKey?: string, fromKey?: string,
toKey?: string toKey?: string,
as?: string
) => Promise<AxiosResponse<pond.ListTransactionsResponse>>; ) => Promise<AxiosResponse<pond.ListTransactionsResponse>>;
revokeTransaction: (key: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>; revokeTransaction: (key: string, as?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>;
updateTransaction: ( updateTransaction: (
key: string, key: string,
data: pond.TransactionData data: pond.TransactionData,
as?: string
) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>; ) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>;
} }
@ -38,9 +42,9 @@ interface Props {}
export default function TransactionProvider(props: PropsWithChildren<Props>) { export default function TransactionProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put } = useHTTP(); const { get, post, put } = useHTTP();
const [{ as }] = useGlobalState(); //const [{ as }] = useGlobalState();
const addTransaction = (transaction: pond.Transaction, fileIDs?: string[]) => { const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], as?: string) => {
if (as) if (as)
return post<pond.AddTransactionResponse>( return post<pond.AddTransactionResponse>(
pondURL( pondURL(
@ -60,7 +64,8 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
fromObject?: pond.ObjectType, fromObject?: pond.ObjectType,
toObject?: pond.ObjectType, toObject?: pond.ObjectType,
fromKey?: string, fromKey?: string,
toKey?: string toKey?: string,
as?: string
) => { ) => {
if (as) { if (as) {
return get<pond.ListTransactionsResponse>( return get<pond.ListTransactionsResponse>(
@ -81,7 +86,7 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateTransaction = (key: string, data: pond.TransactionData) => { const updateTransaction = (key: string, data: pond.TransactionData, as?: string) => {
if (as) if (as)
return post<pond.UpdateTransactionResponse>( return post<pond.UpdateTransactionResponse>(
pondURL("/transactions/" + key + "/update?as=" + as), pondURL("/transactions/" + key + "/update?as=" + as),
@ -90,7 +95,7 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
return post<pond.UpdateTransactionResponse>(pondURL("/transactions/" + key + "/update"), data); return post<pond.UpdateTransactionResponse>(pondURL("/transactions/" + key + "/update"), data);
}; };
const transactionPageData = (start: string, end: string) => { const transactionPageData = (start: string, end: string, as?: string) => {
if (as) { if (as) {
return get<pond.TransactionPageDataResponse>( return get<pond.TransactionPageDataResponse>(
pondURL("/transactionsPage?as=" + as + "&start=" + start + "&end=" + end) pondURL("/transactionsPage?as=" + as + "&start=" + start + "&end=" + end)
@ -101,7 +106,7 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
); );
}; };
const revokeTransaction = (key: string) => { const revokeTransaction = (key: string, as?: string) => {
if (as) { if (as) {
return put<pond.RevokeTransactionResponse>( return put<pond.RevokeTransactionResponse>(
pondURL("/transactions/" + key + "/revoke?as=" + as) pondURL("/transactions/" + key + "/revoke?as=" + as)