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
|
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) {
|
export async function getAccounts(age) {
|
||||||
const accounts = await db`
|
const accounts = await db`
|
||||||
select
|
select
|
||||||
account.id as id,
|
account.id as id,
|
||||||
account.name as name,
|
account.name as name,
|
||||||
org.name as org_name,
|
balance
|
||||||
balance,
|
|
||||||
available_balance,
|
|
||||||
balance_date,
|
|
||||||
hide,
|
|
||||||
in_total
|
|
||||||
from account
|
from account
|
||||||
left join org on org.id = account.org_id
|
where hide is false
|
||||||
where account.hide is false
|
|
||||||
`
|
`
|
||||||
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
||||||
return accounts
|
return accounts
|
||||||
@ -189,15 +208,8 @@ export async function getHiddenAccounts(age) {
|
|||||||
const accounts = await db`
|
const accounts = await db`
|
||||||
select
|
select
|
||||||
account.id as id,
|
account.id as id,
|
||||||
account.name as name,
|
account.name as name
|
||||||
org.name as org_name,
|
|
||||||
balance,
|
|
||||||
available_balance,
|
|
||||||
balance_date,
|
|
||||||
hide,
|
|
||||||
in_total
|
|
||||||
from account
|
from account
|
||||||
left join org on org.id = account.org_id
|
|
||||||
where account.hide is true
|
where account.hide is true
|
||||||
`
|
`
|
||||||
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { getTransactions } from '$lib/db';
|
import { getAccount, getTransactions } from '$lib/db';
|
||||||
|
|
||||||
/** @type {import('./$types').PageServerLoad} */
|
/** @type {import('./$types').PageServerLoad} */
|
||||||
export async function load({ params }) {
|
export async function load({ params }) {
|
||||||
const transactions = await getTransactions(params.slug);
|
const transactions = await getTransactions(params.slug);
|
||||||
|
const account = await getAccount(params.slug);
|
||||||
const slug = params.slug;
|
const slug = params.slug;
|
||||||
if (transactions) {
|
if (transactions) {
|
||||||
return {transactions, slug};
|
return {transactions, account};
|
||||||
}
|
}
|
||||||
|
|
||||||
error(404, 'Not found');
|
error(404, 'Not found');
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
let trans = $derived(data.transactions);
|
let trans = $derived(data.transactions);
|
||||||
let notes = $state('');
|
let notes = $state('');
|
||||||
let currentTransaction = $state(null);
|
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 hide = $derived(account?.hide || false);
|
||||||
let inTotal = $derived(account?.in_total || false);
|
let inTotal = $derived(account?.in_total || false);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
<div class="flex mb-4">
|
<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-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">
|
<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"
|
<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">
|
viewBox="0 0 478.703 478.703" xml:space="preserve">
|
||||||
|
|||||||
Reference in New Issue
Block a user