2 Commits

Author SHA1 Message Date
schreifuchs 4475879330 feat: implement limit for the dashboard (resolves #6)
Commit / ci (push) Has been cancelled
PullRequest / publish (pull_request) Failing after 2m10s
2026-04-03 13:06:11 +02:00
schreifuchs 2e16cf9d51 docs: add TODO.md with project review and refactoring tasks
Commit / ci (push) Successful in 10m32s
2026-04-03 12:31:11 +02:00
2 changed files with 67 additions and 1 deletions
+65
View File
@@ -0,0 +1,65 @@
# Project Review & Refactoring TODOs
This document contains the prioritized list of refactoring tasks, architectural improvements, and testing strategies for the Aktiteil project.
## 🚨 Must do (Security & Critical Best Practices)
- [ ] **Fix Critical XSS Vulnerability (`{@html}` without sanitization)**
- **Where:** `src/routes/akti/[aktiId]/+page.svelte`
- **Why:** Rendering user input via `{@html data.akti.body}` without sanitization allows malicious scripts to be injected.
- **Fix:** Use the already installed `sanitize-html` library on the server to sanitize `changeRequest.body` before updating/inserting into the database.
- [ ] **Move Server-Only Code to `$lib/server`**
- **Where:** `src/lib/auth.ts`
- **Why:** It imports from `./server/db`. Keeping server-side dependencies in the general `$lib` folder risks accidental imports by client components, breaking the Vite build and potentially leaking server logic.
- **Fix:** Move and rename it to `src/lib/server/session.ts` (or `authUtils.ts`) and update imports in `.server.ts` files.
- [ ] **Fix Action Validation Error Handling**
- **Where:** `src/routes/akti/[aktiId]/+page.server.ts` and `src/routes/akti/[aktiId]/comment/+page.server.ts`
- **Why:** Currently returning `error(400)` on validation failure, which wipes form data and shows a generic error page.
- **Fix:** Use SvelteKit's `fail(400, { message: 'Invalid data' })` to keep the user on the page and preserve their input.
- [ ] **Fix Hacky Fallback in Auth Query**
- **Where:** `src/lib/auth.ts` -> `getSession()`
- **Why:** Querying the DB with a fallback UUID (`eaf930...`) when email is missing is an anti-pattern.
- **Fix:** Implement an early return (`if (!session?.user?.email) return null;`) before hitting the database.
## 🛠️ Should do (Performance & Architecture)
- [ ] **Parallelize Database Queries**
- **Where:** `src/routes/akti/[aktiId]/+page.server.ts` (load function)
- **Why:** Queries are running sequentially.
- **Fix:** Use `Promise.all([ db.query.aktis.findFirst(...), db.query.ratings.findMany(...) ])` to run concurrently.
- [ ] **Implement Pagination / Limit for the Dashboard**
- **Where:** `src/routes/+page.server.ts`
- **Why:** Querying all records joined with ratings will scale poorly.
- **Fix:** Add a `.limit()` clause and consider basic pagination or infinite scrolling.
- [ ] **Extend Auth.js Types Globally**
- **Where:** `src/app.d.ts`
- **Why:** TypeScript doesn't inherently know `session.user.id` exists, leading to hacky workarounds.
- **Fix:** Override `@auth/sveltekit` Session types in `app.d.ts` to include `id` and `email` strictly.
- [ ] **Consider Adopting a Form Library**
- **Where:** `src/lib/extractFormData.ts`
- **Why:** Custom form extractors lack instant client-side validation and seamless server-side error mapping.
- **Fix:** Consider switching to `sveltekit-superforms` which integrates well with Valibot.
## ✨ Nice to have (UX & Polish)
- [ ] **Clarify File Naming (`auth.ts` vs `auth.ts`)**
- Rename `src/lib/auth.ts` to `session.ts` or similar to distinguish from `src/auth.ts` (Auth.js setup).
- [ ] **Abstract Heavy Database Queries**
- Move complex aggregations (like computing averages in `src/routes/+page.server.ts`) into a dedicated `src/lib/server/db/queries.ts` file to keep routes clean.
- [ ] **Clean up Redundant Imports**
- In `src/routes/+layout.server.ts`, change `import { getSession as getSession }` to `import { getSession }`.
## 🧪 Testing Plan
- [ ] **Add Playwright (End-to-End Testing)**
- Install Playwright to test SvelteKit server actions, DB integration, and Flowbite forms holistically.
- [ ] **Add Vitest + Svelte Testing Library (Unit/Component Testing)**
- Set up Vitest to test UI components (`AktiCard`, `AktiEditor`) and utility functions (`extractFormData`) in isolation.
+2 -1
View File
@@ -13,7 +13,8 @@ export const load: PageServerLoad = async () => {
})
.from(aktis)
.leftJoin(ratings, eq(aktis.id, ratings.aktiId))
.groupBy(aktis.id, aktis.title, aktis.summary);
.groupBy(aktis.id, aktis.title, aktis.summary)
.limit(50);
return {
aktis: a.map((a) => ({ ...a, rating: a.rating ? parseFloat(a.rating) : undefined }))