Kundenansicht P6b: Team-Weg der Analyse im Abo-Modell (WOMS)
POST/GET /api/admin/analyse/:projectId kennt jetzt das Abo-Modell: - Gilt aboModellFuerKunde, prüft das Einschalten das Abo über aboDeckt (Hosting und Wartung decken die Analyse); fehlt es, 409 mit code abo_fehlt, grund, wechsel (und ab) wie bei der Team-Aktivierung der anderen Funktionen, bevor etwas geschrieben wird. Lesefehler: 503. - Das neu eingeschaltete Dokument trägt den Abo-Marker (unlockedBy und einrichtungAbrechnung 'abo', istAboModell); activateAnalyse nimmt dazu den Parameter abrechnung, setzt ihn im selben Schritt wie den Zustand und stellt ihn bei der Rücknahme wieder her. - GET: Eignung und Text folgen dem Abo-Modell (Hosting-oder-Wartungs-Text). - Alle anderen Kunden und das Ausschalten laufen unverändert. Tests: test/adminAnalyseAboModell.test.js (9 Fälle). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72c5fa9fea
commit
4473a746ee
3 files changed
+235
-9
No files matched your search
@@ -3,7 +3,9 @@ import { Router } from 'express'
|
||||
import { config } from '../../config.js'
|
||||
import { getDocument } from '../../services/appwriteAdmin.js'
|
||||
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
|
||||
import { activateAnalyse, analyseEligibility, controllerView, deactivateAnalyse, ELIGIBILITY_MESSAGES, validateTextform } from '../../services/analyse.js'
|
||||
import { activateAnalyse, analyseEligibility, controllerView, deactivateAnalyse, eligibilityMessage, validateTextform } from '../../services/analyse.js'
|
||||
import { aboModellFuerKunde } from '../../services/aboFunktionen.js'
|
||||
import { pruefeAboDeckung } from '../../services/funktionEinschalten.js'
|
||||
import { getFeatureDoc } from '../../services/siteFeatures.js'
|
||||
|
||||
const router = Router()
|
||||
@@ -13,7 +15,9 @@ router.use(requireAppwriteTeam)
|
||||
function sendError(res, err) {
|
||||
const status = [400, 403, 404, 409, 503].includes(err.status) && !err.type ? err.status : 500
|
||||
if (status === 500) console.error('[admin-analyse]', err.message)
|
||||
res.status(status).json({ error: status === 500 ? 'Die Analyse konnte nicht geändert werden' : err.message })
|
||||
// Abo-Modell: code, grund, wechsel (und ab) der 409 abo_fehlt gehen flach in die Antwort, wie bei der Team-Aktivierung der Funktionen
|
||||
const zusatz = status === 409 && err.code === 'abo_fehlt' && err.body && typeof err.body === 'object' ? err.body : {}
|
||||
res.status(status).json({ ...zusatz, error: status === 500 ? 'Die Analyse konnte nicht geändert werden' : err.message })
|
||||
}
|
||||
|
||||
// Lesezugriff fuer das WOMS: Zustand + AVV-Angaben (nie siteKey oder Geheimnisse)
|
||||
@@ -27,9 +31,11 @@ router.get('/:projectId', async (req, res) => {
|
||||
throw err
|
||||
}
|
||||
const customerId = project.customerId || ''
|
||||
// Abo-Modell (Kundenansicht neu): Hosting oder Wartung genuegt; fuer alle anderen Kunden gilt die Wartungs-Regel wie bisher
|
||||
const aboModell = await aboModellFuerKunde(customerId)
|
||||
const [doc, eligibility, controller] = await Promise.all([
|
||||
customerId ? getFeatureDoc(customerId, project.$id, 'analyse') : null,
|
||||
analyseEligibility(customerId, project.$id),
|
||||
analyseEligibility(customerId, project.$id, { aboModell }),
|
||||
controllerView(customerId),
|
||||
])
|
||||
res.json({
|
||||
@@ -45,7 +51,7 @@ router.get('/:projectId', async (req, res) => {
|
||||
activatedAt: doc?.activatedAt || null,
|
||||
offSince: doc?.offSince || null,
|
||||
eligible: eligibility.ok,
|
||||
reasonText: eligibility.reason ? ELIGIBILITY_MESSAGES[eligibility.reason] : null,
|
||||
reasonText: eligibility.reason ? eligibilityMessage(eligibility.reason, { aboModell }) : null,
|
||||
})
|
||||
} catch (err) {
|
||||
sendError(res, err)
|
||||
@@ -75,6 +81,10 @@ router.post('/:projectId', async (req, res) => {
|
||||
const customerId = project.customerId
|
||||
if (!customerId) return res.status(400).json({ error: 'Projekt hat keinen Kunden' })
|
||||
const by = String(req.appwriteUser?.name || req.appwriteUser?.email || 'Mitarbeiter').slice(0, 100)
|
||||
// Abo-Modell (Kundenansicht neu, V10): das Abo muss die Analyse decken (409 abo_fehlt mit grund, bevor etwas geschrieben wird); das
|
||||
// Dokument bekommt den Abo-Marker. Ausschalten braucht kein Abo. Alle anderen Kunden: alles wie bisher.
|
||||
const aboModell = on && (await aboModellFuerKunde(customerId))
|
||||
if (aboModell) await pruefeAboDeckung(customerId, 'analyse')
|
||||
const { doc } = on
|
||||
? await activateAnalyse({
|
||||
customerId,
|
||||
@@ -83,6 +93,7 @@ router.post('/:projectId', async (req, res) => {
|
||||
by,
|
||||
textform,
|
||||
audienceConfirmed,
|
||||
...(aboModell ? { aboModell: true, abrechnung: 'abo' } : {}),
|
||||
})
|
||||
: await deactivateAnalyse({ customerId, projectId: project.$id, by })
|
||||
res.json({ ok: true, state: doc?.state || 'off' })
|
||||
|
||||
Reference in new issue
Block a user