diff --git a/src/lib/db.js b/src/lib/db.js index b5dbd5e..0b6a26c 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -11,6 +11,14 @@ export async function setAccountInTotal(accountId, total) { ` } +export async function setAccountHide(accountId, hide) { + return await db` + update account + set hide = ${hide} + where id = ${accountId} + ` +} + export async function deleteBudget(id) { return await db` UPDATE budget @@ -148,9 +156,31 @@ export async function getAccounts(age) { org.name as org_name, balance, available_balance, - balance_date + balance_date, + hide, + in_total from account left join org on org.id = account.org_id + where account.hide is false + ` + // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...] + return accounts +} + +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 + 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 }, ...] return accounts diff --git a/src/routes/account/[slug]/+page.server.js b/src/routes/account/[slug]/+page.server.js index c2967e4..3c75a40 100644 --- a/src/routes/account/[slug]/+page.server.js +++ b/src/routes/account/[slug]/+page.server.js @@ -4,10 +4,11 @@ import { getTransactions } from '$lib/db'; /** @type {import('./$types').PageServerLoad} */ export async function load({ params }) { const transactions = await getTransactions(params.slug); - + const slug = params.slug; if (transactions) { - return {transactions}; + return {transactions, slug}; } error(404, 'Not found'); -} \ No newline at end of file +} + diff --git a/src/routes/account/[slug]/+page.svelte b/src/routes/account/[slug]/+page.svelte index a04f8ba..5efb640 100644 --- a/src/routes/account/[slug]/+page.svelte +++ b/src/routes/account/[slug]/+page.svelte @@ -1,74 +1,148 @@ - -
-

Account: {data.account.name}

-
+
+

{account?.name}

+
{account?.amount}
+
+ 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"> + + + + + + + +
+

Transcations

- - - - - - - - - - {#each trans as transaction} - editNotes(transaction)}> - - - - - - {/each} - + + + + + + + + + + {#each trans as transaction} + editNotes(transaction)}> + + + + + + {/each} +
DateDescriptionAmountNotes
{transaction.date.toDateString()}{transaction.description}{transaction.amount}{transaction.notes}
DateDescriptionAmountNotes
{transaction.date.toDateString()}{transaction.description}{transaction.amount}{transaction.notes}
- - - \ No newline at end of file + + + + + + diff --git a/src/routes/api/account/[slug]/+server.js b/src/routes/api/account/[slug]/+server.js index cb43f82..b694b17 100644 --- a/src/routes/api/account/[slug]/+server.js +++ b/src/routes/api/account/[slug]/+server.js @@ -1,13 +1,14 @@ -import { setAccountInTotal } from "$lib/db"; +import { setAccountInTotal, setAccountHide } from "$lib/db"; -export async function POST({ request }) { +export async function POST({ request, params }) { const body = await request.json(); - const { slug, total } = body; + const { hide, in_total } = body; + const { slug } = params; - console.log(`Setting account ${slug} in total to ${total}`); + console.log(`Setting account ${slug} in total to ${in_total} and hide to ${hide}`); try { - const res = await setAccountInTotal(slug, total); + const res = await setAccountInTotal(slug, in_total) && await setAccountHide(slug, body.hide); return new Response(JSON.stringify({ success: true, data: res }), { headers: { 'Content-Type': 'application/json' diff --git a/src/routes/budget/[slug]/+page.svelte b/src/routes/budget/[slug]/+page.svelte index 64ef87e..2d2cc1b 100644 --- a/src/routes/budget/[slug]/+page.svelte +++ b/src/routes/budget/[slug]/+page.svelte @@ -37,7 +37,7 @@ class="cursor-pointer hover:scale-110 transition" onclick={()=> DeleteBudgetModal.showModal()} > - +