Sichert den bisher uncommitteten Produktionsstand des Kundenbereich-Servers, damit kuenftige Deploys (git reset --hard) nichts mehr verwerfen. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { Router } from 'express'
|
|
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
|
|
import {
|
|
createCustomerWithPortalAccess,
|
|
deleteCustomerWithPortalAccess,
|
|
listCustomersForAdmin,
|
|
updateCustomerWithPortalAccess,
|
|
} from '../../services/customerAdmin.js'
|
|
|
|
const router = Router()
|
|
|
|
router.use(requireAppwriteStaff)
|
|
|
|
router.get('/', async (_req, res) => {
|
|
try {
|
|
const customers = await listCustomersForAdmin()
|
|
return res.json({ customers })
|
|
} catch (err) {
|
|
const status = err.status || 500
|
|
return res.status(status).json({ error: err.message || 'Kunden konnten nicht geladen werden' })
|
|
}
|
|
})
|
|
|
|
router.post('/', async (req, res) => {
|
|
try {
|
|
const result = await createCustomerWithPortalAccess(req.body || {})
|
|
return res.status(201).json(result)
|
|
} catch (err) {
|
|
const status = err.status || 500
|
|
return res.status(status).json({ error: err.message || 'Kunde konnte nicht angelegt werden' })
|
|
}
|
|
})
|
|
|
|
router.patch('/:customerId', async (req, res) => {
|
|
try {
|
|
const result = await updateCustomerWithPortalAccess(req.params.customerId, req.body || {})
|
|
return res.json(result)
|
|
} catch (err) {
|
|
const status = err.status || 500
|
|
return res.status(status).json({ error: err.message || 'Kunde konnte nicht aktualisiert werden' })
|
|
}
|
|
})
|
|
|
|
router.delete('/:customerId', async (req, res) => {
|
|
try {
|
|
return res.json(await deleteCustomerWithPortalAccess(req.params.customerId))
|
|
} catch (err) {
|
|
const status = err.status || 500
|
|
return res.status(status).json({ error: err.message || 'Kunde konnte nicht gelöscht werden' })
|
|
}
|
|
})
|
|
|
|
export default router
|