diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index 8e22a90..ffa1ef8 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -33,7 +33,7 @@ interface BankAccount { interface Licence { id: number | -1; status: number | -1; - licence_number: string | ''; + number: string | ''; issued_date: string | ''; expiration_date: string | ''; country: string | ''; @@ -49,6 +49,7 @@ interface User { email: string | ''; first_name: string | ''; last_name: string | ''; + password: string | ''; phone: string | ''; notes: string | ''; address: string | ''; diff --git a/frontend/src/lib/components/UserEditForm.svelte b/frontend/src/lib/components/UserEditForm.svelte index 58e1e43..6eb1b95 100644 --- a/frontend/src/lib/components/UserEditForm.svelte +++ b/frontend/src/lib/components/UserEditForm.svelte @@ -18,6 +18,7 @@ email: '', first_name: '', last_name: '', + password: '', phone: '', address: '', zip_code: '', @@ -43,7 +44,7 @@ licence: { id: 0, status: 1, - licence_number: '', + number: '', issued_date: '', expiration_date: '', country: '', @@ -83,14 +84,6 @@ // $: isNewUser = user === null; $: isLoading = user === undefined; - $: { - console.log('incomingUser:', user); - } - - // Add debug logging for user - $: { - console.log('processed user:', user); - } /** @type {App.Locals['licence_categories']} */ export let licence_categories; @@ -345,7 +338,7 @@ name="user[licence][number]" type="text" label={$t('licence_number')} - bind:value={localUser.licence.licence_number} + bind:value={localUser.licence.number} placeholder={$t('placeholder.licence_number')} toUpperCase={true} /> diff --git a/frontend/src/lib/utils/processing.js b/frontend/src/lib/utils/processing.js index bfb9cf5..2f75822 100644 --- a/frontend/src/lib/utils/processing.js +++ b/frontend/src/lib/utils/processing.js @@ -3,17 +3,20 @@ import { toRFC3339 } from './helpers'; /** * Converts FormData to a nested object structure * @param {FormData} formData - The FormData object to convert - * @returns {{ user: Partial }} Nested object representation of the form data + * @returns {{ user: Partial,password2: string }} Nested object representation of the form data */ export function formDataToObject(formData) { /** @type { Partial } */ const object = {}; + let password2 = ''; console.log('Form data entries:'); for (const [key, value] of formData.entries()) { console.log('Key:', key, 'Value:', value); - } - for (const [key, value] of formData.entries()) { + if (key == 'password2') { + password2 = String(value); + continue; + } /** @type {string[]} */ const keys = key.match(/\[([^\]]+)\]/g)?.map((k) => k.slice(1, -1)) || [key]; console.log('Processed keys:', keys); @@ -51,17 +54,17 @@ export function formDataToObject(formData) { } } - return { user: object }; + return { user: object, password2: password2 }; } /** * Processes the raw form data into the expected user data structure - * @param {{ user: Partial } } rawData - The raw form data object + * @param {{ user: Partial, password2: string} } rawData - The raw form data object * @returns {{ user: Partial }} Processed user data */ export function processFormData(rawData) { /** @type {{ user: Partial }} */ - const processedData = { + let processedData = { user: { id: Number(rawData.user.id) || 0, status: Number(rawData.user.status), @@ -93,7 +96,7 @@ export function processFormData(rawData) { licence: { id: Number(rawData.user.licence?.id) || 0, status: Number(rawData.user.licence?.status), - licence_number: String(rawData.user.licence?.licence_number || ''), + number: String(rawData.user.licence?.number || ''), issued_date: toRFC3339(rawData.user.licence?.issued_date), expiration_date: toRFC3339(rawData.user.licence?.expiration_date), country: String(rawData.user.licence?.country || ''), @@ -112,6 +115,15 @@ export function processFormData(rawData) { } }; + if ( + rawData.user.password && + rawData.password2 && + rawData.user.password === rawData.password2 && + rawData.user.password.trim() !== '' + ) { + processedData.user.password = rawData.user.password; + } + // Remove undefined or null properties const cleanUpdateData = JSON.parse(JSON.stringify(processedData), (key, value) => value !== null && value !== '' ? value : undefined diff --git a/frontend/src/routes/auth/about/[id]/+page.server.js b/frontend/src/routes/auth/about/[id]/+page.server.js index 0f25201..f0d267a 100644 --- a/frontend/src/routes/auth/about/[id]/+page.server.js +++ b/frontend/src/routes/auth/about/[id]/+page.server.js @@ -36,7 +36,7 @@ export const actions = { console.log('Is creating: ', isCreating); // console.dir(formData); console.dir(processedData.user.membership); - const apiURL = `${BASE_API_URI}/backend/users/update/`; + const apiURL = `${BASE_API_URI}/backend/users/upsert/`; /** @type {RequestInit} */ const requestUpdateOptions = { diff --git a/frontend/src/routes/auth/admin/users/+page.server.js b/frontend/src/routes/auth/admin/users/+page.server.js index d9057ea..3e6553a 100644 --- a/frontend/src/routes/auth/admin/users/+page.server.js +++ b/frontend/src/routes/auth/admin/users/+page.server.js @@ -34,7 +34,7 @@ export const actions = { console.dir(processedData.user.membership); const isCreating = !processedData.user.id || processedData.user.id === 0; console.log('Is creating: ', isCreating); - const apiURL = `${BASE_API_URI}/backend/users/update`; + const apiURL = `${BASE_API_URI}/backend/users/upsert`; /** @type {RequestInit} */ const requestOptions = { @@ -59,6 +59,6 @@ export const actions = { console.log('Server success response:', response); locals.user = response; userDatesFromRFC3339(locals.user); - throw redirect(303, `/auth/about/${response.id}`); + throw redirect(303, `/auth/admin/users`); } }; diff --git a/frontend/src/routes/auth/admin/users/+page.svelte b/frontend/src/routes/auth/admin/users/+page.svelte index 26aba61..f76c4e8 100644 --- a/frontend/src/routes/auth/admin/users/+page.svelte +++ b/frontend/src/routes/auth/admin/users/+page.svelte @@ -223,6 +223,7 @@ {subscriptions} {licence_categories} on:cancel={close} + on:close={close} /> {/if}