From 18f5dadb0604599687a77b366a3747dac693158e Mon Sep 17 00:00:00 2001 From: Alex <$(pass /github/email)> Date: Thu, 10 Apr 2025 15:40:22 +0200 Subject: [PATCH] wip --- frontend/src/app.d.ts | 20 +- .../src/lib/components/CarEditForm.svelte | 526 ++++++++++++++++-- frontend/src/lib/components/InputField.svelte | 4 +- .../components/SubscriptionEditForm.svelte | 14 +- .../src/lib/components/UserEditForm.svelte | 314 ++++++----- frontend/src/lib/locales/de.js | 13 +- frontend/src/lib/locales/en.js | 2 +- frontend/src/lib/utils/constants.js | 3 - frontend/src/lib/utils/defaults.js | 17 +- frontend/src/lib/utils/helpers.js | 2 +- frontend/src/lib/utils/processing.js | 224 +++++--- .../routes/auth/about/[id]/+page.server.js | 17 +- .../routes/auth/admin/users/+page.server.js | 103 ++-- .../src/routes/auth/admin/users/+page.svelte | 153 ++--- go-backend/internal/config/config.go | 14 + go-backend/internal/constants/constants.go | 14 +- .../internal/controllers/car_controller.go | 6 +- .../internal/controllers/controllers_test.go | 12 +- .../controllers/membershipController.go | 10 +- .../controllers/membershipController_test.go | 46 +- .../internal/controllers/user_Password.go | 6 +- .../controllers/user_Password_test.go | 2 - .../internal/controllers/user_controller.go | 15 +- .../controllers/user_controller_test.go | 65 ++- go-backend/internal/database/db.go | 26 +- go-backend/internal/models/Insurance.go | 45 +- go-backend/internal/models/bank_account.go | 9 + go-backend/internal/models/car.go | 184 +++--- go-backend/internal/models/damage.go | 58 ++ go-backend/internal/models/location.go | 54 ++ go-backend/internal/models/membership.go | 24 +- ...{subscription_model.go => subscription.go} | 18 +- go-backend/internal/models/user.go | 270 ++------- go-backend/internal/models/verification.go | 30 + .../subscription_model_repository.go | 97 ---- .../repositories/subscription_repository.go | 97 ++++ go-backend/internal/server/server.go | 2 +- go-backend/internal/services/car_service.go | 4 +- go-backend/internal/services/email_service.go | 12 +- .../internal/services/membership_service.go | 26 +- go-backend/internal/services/user_service.go | 15 +- go-backend/internal/utils/crypto.go | 4 - go-backend/internal/utils/response_handler.go | 20 +- .../validation/membership_validation.go | 8 +- go-backend/internal/validation/setup.go | 2 +- .../validation/subscription_validation.go | 4 +- .../internal/validation/user_validation.go | 12 +- go-backend/pkg/errors/errors.go | 8 +- 48 files changed, 1650 insertions(+), 981 deletions(-) create mode 100644 go-backend/internal/models/damage.go create mode 100644 go-backend/internal/models/location.go rename go-backend/internal/models/{subscription_model.go => subscription.go} (72%) delete mode 100644 go-backend/internal/repositories/subscription_model_repository.go create mode 100644 go-backend/internal/repositories/subscription_repository.go diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index f6fa3c9..9dcfa69 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -51,7 +51,6 @@ interface User { last_name: string | ''; password: string | ''; phone: string | ''; - notes: string | ''; address: string | ''; zip_code: string | ''; city: string | ''; @@ -60,11 +59,9 @@ interface User { role_id: number | -1; dateofbirth: string | ''; company: string | ''; - profile_picture: string | ''; - payment_status: number | -1; - membership: Membership; - bank_account: BankAccount; - licence: Licence; + membership: Membership | null; + bank_account: BankAccount | null; + licence: Licence | null; notes: string | ''; } @@ -80,9 +77,9 @@ interface Car { end_date: string | ''; color: string | ''; licence_plate: string | ''; - location: Location; - damages: Damage[] | []; - insurances: Insurance[] | []; + location: Location | null; + damages: Damage[] | null; + insurances: Insurance[] | null; notes: string | ''; } @@ -93,8 +90,11 @@ interface Location { interface Damage { id: number | -1; - opponent: User; + name: string | ''; + opponent: User | null; + driver_id: number | -1; insurance: Insurance | null; + date: string | ''; notes: string | ''; } diff --git a/frontend/src/lib/components/CarEditForm.svelte b/frontend/src/lib/components/CarEditForm.svelte index d933d79..5723967 100644 --- a/frontend/src/lib/components/CarEditForm.svelte +++ b/frontend/src/lib/components/CarEditForm.svelte @@ -5,8 +5,10 @@ import { applyAction, enhance } from '$app/forms'; import { hasPrivilige, receive, send } from '$lib/utils/helpers'; import { t } from 'svelte-i18n'; - import { defaultCar } from '$lib/utils/defaults'; + import { defaultDamage, defaultInsurance, defaultOpponent } from '$lib/utils/defaults'; import { PERMISSIONS } from '$lib/utils/constants'; + import Modal from './Modal.svelte'; + import UserEditForm from './UserEditForm.svelte'; const dispatch = createEventDispatcher(); @@ -16,19 +18,54 @@ /** @type {App.Locals['user'] } */ export let editor; - /** @type {App.Types['car'] | null} */ + /** @type {App.Locals['users'] } */ + export let users; + + /** @type {App.Types['car']} */ export let car; - console.log('Opening car modal with:', car); - $: car = car || { ...defaultCar() }; + $: console.log( + 'damage.opponent changed:', + car?.damages.map((d) => d.opponent) + ); + $: console.log( + 'damage.insurance changed:', + car?.damages.map((d) => d.insurance) + ); + // TODO: Remove when working + // $: if (car.damages.length > 0 && !car.damages.every((d) => d.insurance && d.opponent)) { + // car.damages = car.damages.map((damage) => ({ + // ...damage, + // insurance: damage.insurance ?? defaultInsurance(), + // opponent: damage.opponent ?? defaultOpponent() + // })); + // } + let initialized = false; // Prevents infinite loops + + // Ensure damages have default values once `car` is loaded + $: if (car && !initialized) { + car = { + ...car, + damages: + car.damages?.map((damage) => ({ + ...damage, + insurance: damage.insurance ?? defaultInsurance(), + opponent: damage.opponent ?? defaultOpponent() + })) || [] + }; + initialized = true; // Prevents re-running + } $: isLoading = car === undefined || editor === undefined; let isUpdating = false; let readonlyUser = !hasPrivilige(editor, PERMISSIONS.Update); + /** @type {number | null} */ + let editingUserIndex = null; + const TABS = ['car.car', 'insurance', 'car.damages']; let activeTab = TABS[0]; - /** @type {import('../../routes/auth/about/[id]/$types').SubmitFunction} */ + /** @type {import('@sveltejs/kit').SubmitFunction} */ const handleUpdate = async () => { isUpdating = true; return async ({ result }) => { @@ -47,7 +84,7 @@ {:else if editor && car}
- +

{car.id ? $t('car.edit') : $t('car.create')}

@@ -155,48 +192,357 @@ />
- {#each car.insurances as insurance} - - - - - - {/each} +
+ {#each car.insurances as insurance, index} + +
+ + {insurance.company ? insurance.company : ''} + {insurance.reference ? ' (' + insurance.reference + ')' : ''} + +
+ + + + + + {#if hasPrivilige(editor, PERMISSIONS.Delete)} + + {/if} +
+
+ {/each} +
+
+ {#if hasPrivilige(editor, PERMISSIONS.Create)} + + {/if} +
+
+
+
+ {#each car.damages as damage, index (damage.id)} + +
+ + + {damage.name} - + {damage.opponent.first_name} + {damage.opponent.last_name} + + +
+ + + u.role_id > 0) + .map((u) => ({ + value: u.id, + label: `${u.first_name} ${u.last_name}`, + color: '--subtext1' + })) || []} + bind:value={damage.driver_id} + readonly={readonlyUser} + /> +

{$t('user.opponent')}

+ + + + + + + + + + + + + + + + + + + + +
+ + + {#if damage.opponent?.first_name} + {damage.opponent.first_name} {damage.opponent.last_name} + {:else} + {$t('not_set')} + {/if} + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
{$t('email')}{damage.opponent?.email || '-'}
{$t('phone')}{damage.opponent?.phone || '-'}
{$t('address')}{damage.opponent?.address || '-'}
{$t('city')}{damage.opponent?.city || '-'}
{$t('zip_code')}{damage.opponent?.zip_code || '-'}
+
+ +
+
+
+ + + + + + + {#if hasPrivilige(editor, PERMISSIONS.Delete)} + + {/if} +
+
+ {/each} +
+ {#if hasPrivilige(editor, PERMISSIONS.Create)} + + {/if}
{#if isUpdating} @@ -211,7 +557,81 @@ {/if} +{#if editingUserIndex !== null} + + (editingUserIndex = null)} + on:close={() => { + car.damages = car.damages; + editingUserIndex = null; + }} + /> + +{/if} +