-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fetch data for user's overview page (#4)
* refactor: get email on server side * feat: get data for the current month
- Loading branch information
1 parent
cb2f1ab
commit 5892317
Showing
4 changed files
with
96 additions
and
11 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { fail } from '@sveltejs/kit'; | ||
|
||
export const load = async ({ locals: { supabase } }) => { | ||
try { | ||
const now = new Date(); | ||
const year = now.getFullYear(); | ||
const month = now.getMonth(); | ||
const { data: expenses } = await supabase | ||
.from('expenses') | ||
.select('id,date,category,description,amount') | ||
.gte('date', new Date(year, month, 1).toDateString()); | ||
|
||
const { data: income } = await supabase | ||
.from('income') | ||
.select('id,date,category,description,amount') | ||
.gte('date', new Date(year, month, 1).toDateString()); | ||
|
||
const { data: savings } = await supabase | ||
.from('savings') | ||
.select('id,date,category,description,amount') | ||
.gte('date', new Date(year, month, 1).toDateString()); | ||
|
||
const { data: debt } = await supabase | ||
.from('debt') | ||
.select('id,date,category,description,amount,interest_rate,minimum_payment') | ||
.gte('date', new Date(year, month, 1).toDateString()); | ||
|
||
return { | ||
expenses, | ||
income, | ||
savings, | ||
debt, | ||
}; | ||
} catch (error) { | ||
return fail(500, { message: 'Server error. Try again later.', success: false }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script> | ||
export let data; | ||
</script> | ||
|
||
<h1>Overview</h1> | ||
|
||
<h2>Expenses</h2> | ||
{#if data.expenses.length} | ||
<ul> | ||
{#each data.expenses as expense} | ||
<li>{expense.description}: {expense.amount}</li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<p>No expenses found.</p> | ||
{/if} | ||
|
||
<h2>Income</h2> | ||
{#if data.income.length} | ||
<ul> | ||
{#each data.income as incomeEntry} | ||
<li>{incomeEntry.description}: {incomeEntry.amount}</li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<p>No income found.</p> | ||
{/if} | ||
|
||
<h2>Savings</h2> | ||
{#if data.savings.length} | ||
<ul> | ||
{#each data.savings as savingsEntry} | ||
<li>{savingsEntry.description}: {savingsEntry.amount}</li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<p>No savings found.</p> | ||
{/if} | ||
|
||
<h2>Debt</h2> | ||
{#if data.debt.length} | ||
<ul> | ||
{#each data.debt as debtEntry} | ||
<li>{debtEntry.description}: {debtEntry.amount}</li> | ||
{/each} | ||
</ul> | ||
{:else} | ||
<p>No debt found.</p> | ||
{/if} |