41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import type { ConfigResponse, ImportOptions, PrepareResponse, SubmitResponse, Transaction } from "../types/api";
|
|
|
|
export async function fetchConfig(): Promise<ConfigResponse> {
|
|
const response = await fetch("/config")
|
|
const data = await response.json();
|
|
return data as ConfigResponse;
|
|
}
|
|
|
|
export async function loadTransactions(csvFile: File, profile: string, server: string): Promise<PrepareResponse> {
|
|
const payload = new FormData();
|
|
payload.append("file", csvFile);
|
|
payload.append("profile", profile);
|
|
payload.append("server", server);
|
|
|
|
const response = await fetch("/prepare", {
|
|
method: "POST",
|
|
body: payload
|
|
});
|
|
|
|
const data = await response.json();
|
|
return data as PrepareResponse;
|
|
}
|
|
|
|
export async function submitTransactions(transactions: Transaction[], server: string, opts: ImportOptions): Promise<SubmitResponse> {
|
|
const payload = {
|
|
transactions,
|
|
server,
|
|
opts
|
|
};
|
|
|
|
const response = await fetch("/submit", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
return data as SubmitResponse;
|
|
} |