feat: add getPublic route to fetch news item by slug

This commit is contained in:
seaznCode 2026-01-28 20:13:09 +01:00
parent 1825310280
commit fb3d3c410c
2 changed files with 24 additions and 0 deletions

View File

@ -60,6 +60,29 @@ exports.listActive = async (req, res) => {
}
}
exports.getPublic = async (req, res) => {
try {
const { slug } = req.params || {}
if (!slug) return res.status(400).json({ error: 'slug is required' })
const r = await NewsService.get(slug)
if (!r || !r.is_active) return res.status(404).json({ error: 'Not found' })
const data = {
id: r.id,
title: r.title,
summary: r.summary,
content: r.content,
slug: r.slug,
category: r.category,
published_at: r.published_at,
imageUrl: r.object_storage_id ? buildImageUrlFromKey(r.object_storage_id) : ''
}
res.json({ success: true, data })
} catch (e) {
logger.error('[NewsController.getPublic] error', { msg: e.message })
res.status(500).json({ error: 'Failed to load news item' })
}
}
exports.create = async (req, res) => {
try {
const { title, summary, content, slug, category, isActive, publishedAt } = req.body

View File

@ -158,6 +158,7 @@ router.get('/admin/abonements', authMiddleware, adminOnly, AbonemmentController.
// News Manager Routes
router.get('/admin/news', authMiddleware, adminOnly, NewsController.list);
router.get('/news/active', NewsController.listActive);
router.get('/news/:slug', NewsController.getPublic);
// NEW: Invoice GETs
router.get('/invoices/mine', authMiddleware, InvoiceController.listMine);