Analyse: Lesezugriff fuer WOMS

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-01 10:37:25 +00:00
1 parent 821e947275
commit 0b59dac2be
4 files changed
+91 -4

No files matched your search

+34 -1
View File
@@ -3,7 +3,8 @@ import { Router } from 'express'
import { config } from '../../config.js'
import { getDocument } from '../../services/appwriteAdmin.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { activateAnalyse, deactivateAnalyse } from '../../services/analyse.js'
import { activateAnalyse, analyseEligibility, deactivateAnalyse, ELIGIBILITY_MESSAGES } from '../../services/analyse.js'
import { getFeatureDoc } from '../../services/siteFeatures.js'
const router = Router()
router.use(requireAppwriteStaff)
@@ -14,6 +15,38 @@ function sendError(res, err) {
res.status(status).json({ error: status === 500 ? 'Die Analyse konnte nicht geändert werden' : err.message })
}
// Lesezugriff fuer das WOMS: Zustand + AVV-Angaben (nie siteKey oder Geheimnisse)
router.get('/:projectId', async (req, res) => {
try {
let project
try {
project = await getDocument(config.collections.websiteProjects, req.params.projectId)
} catch (err) {
if (err.status === 404) return res.status(404).json({ error: 'Projekt nicht gefunden' })
throw err
}
const customerId = project.customerId || ''
const [doc, eligibility] = await Promise.all([
customerId ? getFeatureDoc(customerId, project.$id, 'analyse') : null,
analyseEligibility(customerId, project.$id),
])
res.json({
enabled: config.analyse.enabled,
state: doc ? doc.state || 'off' : null,
accentColor: doc?.accentColor || '#111111',
avvVersion: config.analyse.avvVersion,
avvAcceptedAt: doc?.avvAcceptedAt || null,
avvAcceptedBy: doc?.avvAcceptedBy || null,
activatedAt: doc?.activatedAt || null,
offSince: doc?.offSince || null,
eligible: eligibility.ok,
reasonText: eligibility.reason ? ELIGIBILITY_MESSAGES[eligibility.reason] : null,
})
} catch (err) {
sendError(res, err)
}
})
router.post('/:projectId', async (req, res) => {
try {
if (!config.analyse.enabled) return res.status(409).json({ error: 'Website-Analyse ist noch nicht freigeschaltet' })