From 493bd9b976a0cfb1035c6b0350188932d84a89f0 Mon Sep 17 00:00:00 2001 From: Borja Robert Date: Mon, 10 Oct 2022 14:30:25 +0200 Subject: [PATCH] crea los ficheros donde tiene que funcionar el login --- src/lib/api.js | 9 ++--- src/routes/admin/+page.server.js | 38 +++++++++++++++++++++ src/routes/admin/+page.svelte | 3 ++ src/routes/admin/auth/login/+page.server.js | 0 src/routes/admin/auth/login/+page.svelte | 0 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/routes/admin/+page.server.js create mode 100644 src/routes/admin/+page.svelte create mode 100644 src/routes/admin/auth/login/+page.server.js create mode 100644 src/routes/admin/auth/login/+page.svelte diff --git a/src/lib/api.js b/src/lib/api.js index 1e7a2cb..aa01f75 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -1,8 +1,9 @@ /** - * - * @param {*} form - * @returns {Promise<*>} - */ +* @async +* @function send +* @param {HTMLFormElement} form +* @returns {Promise} +*/ export const send = async (form) => { const response = await fetch(form.action, { method: form.method, diff --git a/src/routes/admin/+page.server.js b/src/routes/admin/+page.server.js new file mode 100644 index 0000000..3b7fb48 --- /dev/null +++ b/src/routes/admin/+page.server.js @@ -0,0 +1,38 @@ +import { error } from '@sveltejs/kit'; + +/** @type {import('./$types').PageServerLoad} */ +export const load = async ({ locals }) => { + + + throw error(404, "error"); +}; + +/** @type {import('./$types').Actions} */ +export const actions = { + add: async ({ request, locals }) => { + const form = await request.formData(); + + await api('POST', `todos/${locals.userid}`, { + text: form.get('text') + }); + }, + edit: async ({ request, locals }) => { + const form = await request.formData(); + + await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, { + text: form.get('text') + }); + }, + toggle: async ({ request, locals }) => { + const form = await request.formData(); + + await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, { + done: !!form.get('done') + }); + }, + delete: async ({ request, locals }) => { + const form = await request.formData(); + + await api('DELETE', `todos/${locals.userid}/${form.get('uid')}`); + } +}; diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte new file mode 100644 index 0000000..e6e9ef8 --- /dev/null +++ b/src/routes/admin/+page.svelte @@ -0,0 +1,3 @@ + diff --git a/src/routes/admin/auth/login/+page.server.js b/src/routes/admin/auth/login/+page.server.js new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/admin/auth/login/+page.svelte b/src/routes/admin/auth/login/+page.svelte new file mode 100644 index 0000000..e69de29