-
Jed Fox authored
* Make it easier to build the bundle.api.js for the API * Remove budgetId parameter, move config to top level of API * that’s a breaking change * Add support for signing into the server in init() * Add api.downloadBudget(syncId, { password }) method * Fix lint errors * Refactor: extract out getSyncError * api/download-budget: sync if possible instead of downloading * Don’t bother with fetching remote files and installing key if the file is local * *groupId * FIx lint issues * Remove extra close+reopen * Refactor out duplicate load-budget logic * Trailing commas
Jed Fox authored* Make it easier to build the bundle.api.js for the API * Remove budgetId parameter, move config to top level of API * that’s a breaking change * Add support for signing into the server in init() * Add api.downloadBudget(syncId, { password }) method * Fix lint errors * Refactor: extract out getSyncError * api/download-budget: sync if possible instead of downloading * Don’t bother with fetching remote files and installing key if the file is local * *groupId * FIx lint issues * Remove extra close+reopen * Refactor out duplicate load-budget logic * Trailing commas
methods.js 4.61 KiB
const q = require('./app/query');
const injected = require('./injected');
function send(name, args) {
return injected.send(name, args);
}
async function runImport(name, func) {
await send('api/start-import', { budgetName: name });
try {
await func();
} catch (e) {
await send('api/abort-import');
throw e;
}
await send('api/finish-import');
}
async function loadBudget(budgetId) {
return send('api/load-budget', { id: budgetId });
}
async function downloadBudget(syncId, { password } = {}) {
return send('api/download-budget', { syncId, password });
}
async function batchBudgetUpdates(func) {
await send('api/batch-budget-start');
try {
await func();
} finally {
await send('api/batch-budget-end');
}
}
function runQuery(query) {
return send('api/query', { query: query.serialize() });
}
function getBudgetMonths() {
return send('api/budget-months');
}
function getBudgetMonth(month) {
return send('api/budget-month', { month });
}
function setBudgetAmount(month, categoryId, value) {
return send('api/budget-set-amount', { month, categoryId, amount: value });
}
function setBudgetCarryover(month, categoryId, flag) {
return send('api/budget-set-carryover', { month, categoryId, flag });
}
function addTransactions(accountId, transactions) {
return send('api/transactions-add', { accountId, transactions });
}
function importTransactions(accountId, transactions) {
return send('api/transactions-import', { accountId, transactions });
}
function getTransactions(accountId, startDate, endDate) {
return send('api/transactions-get', { accountId, startDate, endDate });
}
function filterTransactions(accountId, text) {
return send('api/transactions-filter', { accountId, text });
}