import { Router } from 'express' import { config } from '../config.js' import { listDocuments, Query } from '../services/appwriteAdmin.js' import { getSessionCustomerId, requireSession } from '../middleware/session.js' const router = Router() router.get('/', requireSession, async (req, res) => { const customerId = getSessionCustomerId(req) if (!customerId) { return res.status(401).json({ error: 'Nicht angemeldet' }) } try { const projects = await listDocuments(config.collections.websiteProjects, [ Query.equal('customerId', customerId), Query.orderDesc('$createdAt'), ]) const sanitized = projects.map((p) => ({ id: p.$id, projectName: p.projectName || '', subdomain: p.subdomain || '', previewUrl: p.previewUrl || '', liveDomain: p.liveDomain || '', status: p.status || '', provisioningStatus: p.provisioningStatus || '', templateName: p.templateName || '', giteaRepoUrl: p.giteaRepoUrl || '', repoFullName: p.repoFullName || '', })) return res.json({ projects: sanitized }) } catch (err) { return res.status(500).json({ error: err.message || 'Projekte konnten nicht geladen werden' }) } }) export default router