-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for spending, budgets, categories and movements
- Loading branch information
Showing
10 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
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,36 @@ | ||
import { error, fail } from '@sveltejs/kit'; | ||
import type { Actions } from './$types'; | ||
import { post } from '$lib/api'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
let budget: Budget = { id: 0, amount: 0 }; | ||
const id = params.id; | ||
if (id) { | ||
// TODO: load real budget | ||
} | ||
return { budget }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async ({ cookies, request, params }) => { | ||
const data = await request.formData(); | ||
const amount = data.get('amount'); | ||
|
||
if (!amount) { | ||
throw error(400, 'Amount is required'); | ||
} | ||
|
||
const token = cookies.get('jwt')!; | ||
const path = ''; // TODO: Replace with real path | ||
const body = await post(path, { amount }, { 'x-user': token }); | ||
|
||
if (body.errors) { | ||
throw fail(400, body); | ||
} | ||
|
||
const value = body.id; | ||
|
||
return { success: true }; | ||
} | ||
}; |
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,19 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Nuevo Presupuesto</title> | ||
</svelte:head> | ||
|
||
<h2>Nuevo Presupuesto</h2> | ||
<form method="POST"> | ||
<fieldset> | ||
<label> | ||
Ingrese un monto para el presupuesto | ||
<input type="number" name="amount" placeholder="Monto" required /> | ||
</label> | ||
<button>Crear</button> | ||
<button type="button" class="outline" on:click={() => history.back()}>Cancelar</button> | ||
</fieldset> | ||
</form> |
36 changes: 36 additions & 0 deletions
36
my-app/src/routes/categories/[[id=integer]]/+page.server.ts
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,36 @@ | ||
import { error, fail } from '@sveltejs/kit'; | ||
import type { Actions } from './$types'; | ||
import { post } from '$lib/api'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
let category: Category = { id: 0, name: '' }; | ||
const id = params.id; | ||
if (id) { | ||
// TODO: load real category | ||
} | ||
return { category }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async ({ cookies, request, params }) => { | ||
const data = await request.formData(); | ||
const name = data.get('name'); | ||
|
||
if (!name) { | ||
throw error(400, 'Name is required'); | ||
} | ||
|
||
const token = cookies.get('jwt')!; | ||
const path = ''; // TODO: replace with real path | ||
const body = await post(path, { name }, { 'x-user': token }); | ||
|
||
if (body.errors) { | ||
throw fail(400, body); | ||
} | ||
|
||
const value = body.id; | ||
|
||
return { success: true }; | ||
} | ||
}; |
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,19 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Nueva Categoría</title> | ||
</svelte:head> | ||
|
||
<h2>Nueva Categoría</h2> | ||
<form method="POST"> | ||
<fieldset> | ||
<label> | ||
Ingrese un nombre para la categoría | ||
<input type="text" name="name" placeholder="Nombre" required /> | ||
</label> | ||
<button>Crear</button> | ||
<button type="button" class="outline" on:click={() => history.back()}>Cancelar</button> | ||
</fieldset> | ||
</form> |
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
34 changes: 34 additions & 0 deletions
34
my-app/src/routes/groups/movements/[id=integer]/+page.server.ts
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,34 @@ | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
const id = Number(params.id); | ||
// TODO: load real group | ||
const group: Group = { | ||
id, | ||
name: 'Grupo de Prueba', | ||
description: 'Este es un grupo de prueba', | ||
owner_id: 0 | ||
}; | ||
// TODO: load real spendings | ||
const spendings: Spending[] = [ | ||
{ | ||
id: 1, | ||
description: 'Entradas de Taylor Swift', | ||
amount: 100_000, | ||
date: new Date() | ||
}, | ||
{ | ||
id: 2, | ||
description: 'Entradas de Tan Biónica', | ||
amount: 20_000, | ||
date: new Date() | ||
}, | ||
{ | ||
id: 3, | ||
description: 'Entradas de Boca-River', | ||
amount: 180_000, | ||
date: new Date() | ||
} | ||
]; | ||
return { group, spendings }; | ||
}; |
32 changes: 32 additions & 0 deletions
32
my-app/src/routes/groups/movements/[id=integer]/+page.svelte
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,32 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
import type { PageServerData } from './$types'; | ||
export let data: PageServerData; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - {data.group.name}</title> | ||
</svelte:head> | ||
|
||
<header> | ||
<h2>{data.group.name}</h2> | ||
<p>{data.group.description}</p> | ||
</header> | ||
{#each data.spendings as spending} | ||
<article> | ||
<header class="row"> | ||
<p>{spending.description}</p> | ||
<p>$ {spending.amount.toLocaleString()}</p> | ||
</header> | ||
{spending.date.toLocaleString()} | ||
</article> | ||
{/each} | ||
|
||
<style> | ||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
</style> |
41 changes: 41 additions & 0 deletions
41
my-app/src/routes/spendings/[[id=integer]]/+page.server.ts
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,41 @@ | ||
import { error, fail } from '@sveltejs/kit'; | ||
import type { Actions } from './$types'; | ||
import { post } from '$lib/api'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
let spending: Spending = { id: 0, description: '', amount: 0 }; | ||
const id = params.id; | ||
if (id) { | ||
// TODO: load real spending | ||
} | ||
return { spending }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async ({ cookies, request, params }) => { | ||
const data = await request.formData(); | ||
const description = data.get('description'); | ||
const amount = data.get('amount'); | ||
|
||
if (!description) { | ||
throw error(400, 'Description is required'); | ||
} | ||
|
||
if (!amount) { | ||
throw error(400, 'Amount is required'); | ||
} | ||
|
||
const token = cookies.get('jwt')!; | ||
const path = ''; // TODO: replace with real path | ||
const body = await post(path, { description, amount }, { 'x-user': token }); | ||
|
||
if (body.errors) { | ||
throw fail(400, body); | ||
} | ||
|
||
const value = body.id; | ||
|
||
return { success: true }; | ||
} | ||
}; |
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,23 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Nuevo Gasto</title> | ||
</svelte:head> | ||
|
||
<h2>Nuevo Gasto</h2> | ||
<form method="POST"> | ||
<fieldset> | ||
<label> | ||
Ingrese una descripción para el gasto | ||
<input type="text" name="description" placeholder="Descripcion" required /> | ||
</label> | ||
<label> | ||
Ingrese un monto para el gasto | ||
<input type="text" name="amount" placeholder="Monto" required /> | ||
</label> | ||
<button>Crear</button> | ||
<button type="button" class="outline" on:click={() => history.back()}>Cancelar</button> | ||
</fieldset> | ||
</form> |
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