Add getAccount function and update account data retrieval in the account page
This commit is contained in:
@ -166,20 +166,39 @@ export async function getDeletedBudgets() {
|
||||
return budgets
|
||||
}
|
||||
|
||||
export async function getAccount(id) {
|
||||
const account = await db`
|
||||
select
|
||||
account.id as id,
|
||||
account.name as name,
|
||||
account.balance as balance,
|
||||
account.available_balance as available_balance,
|
||||
account.balance_date as balance_date,
|
||||
account.in_total as in_total,
|
||||
account.hide as hide,
|
||||
org.id as org_id,
|
||||
org.name as org_name,
|
||||
org.domain as org_domain,
|
||||
org.sfin_url as org_sfin_url,
|
||||
org.url as org_url
|
||||
from account
|
||||
left join org on account.org_id = org.id
|
||||
where account.id = ${id}
|
||||
`
|
||||
if (!account || account.length === 0) {
|
||||
return null
|
||||
}
|
||||
return account[0];
|
||||
}
|
||||
|
||||
export async function getAccounts(age) {
|
||||
const accounts = await db`
|
||||
select
|
||||
account.id as id,
|
||||
account.name as name,
|
||||
org.name as org_name,
|
||||
balance,
|
||||
available_balance,
|
||||
balance_date,
|
||||
hide,
|
||||
in_total
|
||||
balance
|
||||
from account
|
||||
left join org on org.id = account.org_id
|
||||
where account.hide is false
|
||||
where hide is false
|
||||
`
|
||||
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
||||
return accounts
|
||||
@ -189,15 +208,8 @@ export async function getHiddenAccounts(age) {
|
||||
const accounts = await db`
|
||||
select
|
||||
account.id as id,
|
||||
account.name as name,
|
||||
org.name as org_name,
|
||||
balance,
|
||||
available_balance,
|
||||
balance_date,
|
||||
hide,
|
||||
in_total
|
||||
account.name as name
|
||||
from account
|
||||
left join org on org.id = account.org_id
|
||||
where account.hide is true
|
||||
`
|
||||
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { getTransactions } from '$lib/db';
|
||||
import { getAccount, getTransactions } from '$lib/db';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export async function load({ params }) {
|
||||
const transactions = await getTransactions(params.slug);
|
||||
const account = await getAccount(params.slug);
|
||||
const slug = params.slug;
|
||||
if (transactions) {
|
||||
return {transactions, slug};
|
||||
return {transactions, account};
|
||||
}
|
||||
|
||||
error(404, 'Not found');
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
let trans = $derived(data.transactions);
|
||||
let notes = $state('');
|
||||
let currentTransaction = $state(null);
|
||||
let account = $derived(data.accounts.find((a) => a.id == data.slug) || {});
|
||||
let account = $derived(data.account);
|
||||
let hide = $derived(account?.hide || false);
|
||||
let inTotal = $derived(account?.in_total || false);
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
|
||||
<div class="flex mb-4">
|
||||
<div class="w-128 flex-none justify-bottom"><h1 class="text-xl font-bold">{account?.name}</h1></div>
|
||||
<div class="w-64 grow">{account?.amount}</div>
|
||||
<div class="w-64 grow">{account?.balance}</div>
|
||||
<div class="w-14 flex-none text-right">
|
||||
<svg onclick={()=>settings_modal.showModal()} fill="#000000" height="20px" width="20px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
viewBox="0 0 478.703 478.703" xml:space="preserve">
|
||||
|
||||
Reference in New Issue
Block a user