-
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.
Merge pull request #49 from VaquitApp/feature/Registrar-Pago-Personal
Registrar Pago Personal [5]
- Loading branch information
Showing
10 changed files
with
203 additions
and
31 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
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,8 @@ | ||
import { groupService } from '$lib/server/api'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET: RequestHandler = async ({ url, cookies }) => { | ||
const groupId = url.searchParams.get('groupId') || 0; | ||
const body = await groupService.listAllMembers(+groupId, cookies); | ||
return new Response(JSON.stringify(body)); | ||
}; |
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
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
33 changes: 33 additions & 0 deletions
33
my-app/src/routes/payments/details/[[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,33 @@ | ||
import { error, redirect } from '@sveltejs/kit'; | ||
import type { Actions, PageServerLoad } from './$types'; | ||
import { groupService, paymentService } from '$lib/server/api'; | ||
import { getUserId } from '$lib/auth'; | ||
|
||
export const load: PageServerLoad = async ({ params, url, cookies }) => { | ||
const groupId = url.searchParams.get('groupId') || ''; | ||
// const id = Number(params.id) || 0; | ||
const groups: Group[] = await groupService.list(cookies); | ||
const userId = getUserId(cookies); | ||
return { userId, groupId, groups }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
default: async ({ cookies, request, params }) => { | ||
const id = Number(params.id) || 0; | ||
const data = await request.formData(); | ||
|
||
const group_id = Number(data.get('groupId')); | ||
const to_id = Number(data.get('payeeId')); | ||
const from_id = getUserId(cookies); | ||
const amount = Number(data.get('amount')); | ||
|
||
if (!group_id) { | ||
throw error(400, 'Group is required'); | ||
} | ||
|
||
const payment: Payment = { id, group_id, from_id, to_id, amount }; | ||
await paymentService.save(payment, cookies); | ||
|
||
redirect(302, `/groups/movements/${group_id}`); | ||
} | ||
}; |
62 changes: 62 additions & 0 deletions
62
my-app/src/routes/payments/details/[[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,62 @@ | ||
<script lang="ts"> | ||
import { title } from '$lib'; | ||
import { onMount } from 'svelte'; | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
export let members: User[] = []; | ||
async function updateMembers(groupId: number) { | ||
members = []; | ||
if (groupId != 0) { | ||
try { | ||
const response = await fetch(`/api/members?groupId=${groupId}`); | ||
members = await response.json(); | ||
} catch {} | ||
} | ||
} | ||
onMount(async () => { | ||
await updateMembers(data.groupId); | ||
}); | ||
</script> | ||
|
||
<svelte:head> | ||
<title>{title} - Nuevo Pago</title> | ||
</svelte:head> | ||
|
||
<nav aria-label="breadcrumb"> | ||
<ul> | ||
<li><a href="/groups">Grupos</a></li> | ||
<li>Pagos</li> | ||
</ul> | ||
</nav> | ||
|
||
<h2>Registrando Pago</h2> | ||
<form method="POST"> | ||
<fieldset> | ||
<label> | ||
Ingrese un grupo para el pago | ||
<select name="groupId" required value={data.groupId}> | ||
{#each data.groups as group} | ||
<option value={group.id}>{group.name}</option> | ||
{/each} | ||
</select> | ||
</label> | ||
<label> | ||
Ingrese el receptor del pago | ||
<select name="payeeId" required> | ||
{#each members as member} | ||
<option disabled={member.id === data.userId} value={member.id}>{member.email}</option> | ||
{/each} | ||
</select> | ||
</label> | ||
<label> | ||
Ingrese el monto del pago | ||
<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> |
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