diff --git a/src/routes/auth/confirm/+page.js b/src/routes/auth/confirm/+page.js deleted file mode 100644 index ea86737..0000000 --- a/src/routes/auth/confirm/+page.js +++ /dev/null @@ -1,10 +0,0 @@ -import { redirect } from '@sveltejs/kit'; - -export const load = async ({ url }) => { - const email = url.searchParams.get('email') ?? ''; - if (!email) { - throw redirect(303, '/auth/login'); - } - - return { email }; -}; diff --git a/src/routes/auth/confirm/+page.server.js b/src/routes/auth/confirm/+page.server.js index 4bb81ee..72eeb74 100644 --- a/src/routes/auth/confirm/+page.server.js +++ b/src/routes/auth/confirm/+page.server.js @@ -11,6 +11,15 @@ export const actions = { return fail(500, { message: 'Server error. Try again later.', success: false, email }); } - throw redirect(303, '/'); + throw redirect(303, '/overview'); }, }; + +export const load = async ({ url }) => { + const email = url.searchParams.get('email') ?? ''; + if (!email) { + throw redirect(303, '/auth/login'); + } + + return { email }; +}; diff --git a/src/routes/overview/+page.server.js b/src/routes/overview/+page.server.js new file mode 100644 index 0000000..2de7241 --- /dev/null +++ b/src/routes/overview/+page.server.js @@ -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 }); + } +}; diff --git a/src/routes/overview/+page.svelte b/src/routes/overview/+page.svelte new file mode 100644 index 0000000..ab666b0 --- /dev/null +++ b/src/routes/overview/+page.svelte @@ -0,0 +1,49 @@ + + +

Overview

+ +

Expenses

+{#if data.expenses.length} + +{:else} +

No expenses found.

+{/if} + +

Income

+{#if data.income.length} + +{:else} +

No income found.

+{/if} + +

Savings

+{#if data.savings.length} + +{:else} +

No savings found.

+{/if} + +

Debt

+{#if data.debt.length} + +{:else} +

No debt found.

+{/if}