Projektarten: Services-Uebersicht fuer WOMS
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e6f35f836
commit
08958dee77
3 files changed
+128
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { Router } from 'express'
|
||||
import { config } from '../../config.js'
|
||||
import { listDocuments, Query } from '../../services/appwriteAdmin.js'
|
||||
import { servicesCatalog } from '../../services/projectKinds.js'
|
||||
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.use(requireAppwriteStaff)
|
||||
|
||||
const CHUNK = 100
|
||||
|
||||
// Lädt Dokumente per $id in Blöcken (ein Request je 100 IDs statt je Projekt)
|
||||
async function loadByIds(collectionId, ids) {
|
||||
const map = new Map()
|
||||
const unique = [...new Set(ids.filter(Boolean))]
|
||||
for (let i = 0; i < unique.length; i += CHUNK) {
|
||||
const part = unique.slice(i, i + CHUNK)
|
||||
const res = await listDocuments(collectionId, [Query.equal('$id', part), Query.limit(CHUNK)])
|
||||
for (const doc of res || []) map.set(doc.$id, doc)
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
function previewUrlFor(p) {
|
||||
if (p.liveDomain) return `https://${p.liveDomain}`
|
||||
if (p.subdomain) return `https://${p.subdomain}.project.webklar.com`
|
||||
return ''
|
||||
}
|
||||
|
||||
router.get('/', async (_req, res) => {
|
||||
try {
|
||||
const { kinds, features } = servicesCatalog()
|
||||
const projRes = await listDocuments(config.collections.websiteProjects, [Query.limit(5000)])
|
||||
const projects = (projRes || []).filter((p) => !p.archived && !p.isTemplate)
|
||||
|
||||
const [customers, tickets] = await Promise.all([
|
||||
loadByIds(config.collections.customers, projects.map((p) => p.customerId)),
|
||||
loadByIds(config.collections.workorders, projects.map((p) => p.ticketId)),
|
||||
])
|
||||
|
||||
const groups = {}
|
||||
for (const p of projects) {
|
||||
const key = kinds.some((k) => k.key === p.kind) ? p.kind : 'missing'
|
||||
;(groups[key] ||= []).push({
|
||||
id: p.$id,
|
||||
projectName: p.projectName || '',
|
||||
repoFullName: p.repoFullName || '',
|
||||
customerId: p.customerId || '',
|
||||
customerName: customers.get(p.customerId)?.name || '',
|
||||
ticketId: p.ticketId || '',
|
||||
woid: tickets.get(p.ticketId)?.woid || '',
|
||||
previewUrl: previewUrlFor(p),
|
||||
features: {},
|
||||
})
|
||||
}
|
||||
|
||||
return res.json({ kinds, features, groups })
|
||||
} catch (err) {
|
||||
return res.status(err.status || 500).json({ error: err.message || 'Services konnten nicht geladen werden' })
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user