Express-Server für Appwrite-Auth, Session, Projekt-Dashboard und Gitea-Webhook; statisches Frontend und Schema-Dokumentation für woms-database. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { Router } from 'express'
|
|
import { Query } from 'node-appwrite'
|
|
import { config } from '../config.js'
|
|
import { listDocuments } 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 features = await listDocuments(config.collections.portalFeatures, [
|
|
Query.equal('customerId', customerId),
|
|
Query.equal('enabled', true),
|
|
])
|
|
|
|
const sanitized = features.map((f) => ({
|
|
id: f.$id,
|
|
projectId: f.projectId || '',
|
|
featureKey: f.featureKey || '',
|
|
enabled: Boolean(f.enabled),
|
|
unlockedByPurchase: Boolean(f.unlockedByPurchase),
|
|
purchaseStatus: f.purchaseStatus || '',
|
|
}))
|
|
|
|
return res.json({ features: sanitized })
|
|
} catch (err) {
|
|
return res.status(500).json({ error: err.message || 'Features konnten nicht geladen werden' })
|
|
}
|
|
})
|
|
|
|
export default router
|