tractatus/src/routes/publications.routes.js
TheFlow 925065ecdc fix(submissions): extract data from API response wrappers
CRITICAL FIX: Economist submission package was showing no data because
the frontend was storing the entire API response wrapper instead of
extracting the actual post and submission data.

Changes:
- submission-modal-enhanced.js: Extract .post from blog API response
- submission-modal-enhanced.js: Extract .data from submissions API response
- publications.routes.js: Restore original routes and add /targets endpoint
- Cache version bumped to force browser updates

Fixes: #economist-submission-data-missing
2025-10-24 16:35:10 +13:00

62 lines
1.7 KiB
JavaScript

/**
* Publications Routes
* API endpoints for publication targets
*/
const express = require('express');
const router = express.Router();
const publicationsController = require('../controllers/publications.controller');
const publicationTargets = require('../config/publication-targets.config');
const { authenticateToken, requireAdmin } = require('../middleware/auth.middleware');
/**
* GET /api/publications
* Get all publications with optional filtering
* Query params: type, tier, culture, minRank, maxRank, language
* Public endpoint
*/
router.get('/', publicationsController.getPublications);
/**
* GET /api/publications/summary
* Get publication summary statistics
* Public endpoint
*/
router.get('/summary', publicationsController.getPublicationsSummary);
/**
* GET /api/publications/targets
* Returns all publication targets with editorial guidelines
* Used by Editorial Guidelines Manager admin page
*/
router.get('/targets', (req, res) => {
try {
// Convert to array and enrich with metadata
const targets = Object.entries(publicationTargets.PUBLICATION_TARGETS).map(([key, target]) => ({
...target,
key
}));
res.json({
success: true,
total: targets.length,
targets
});
} catch (error) {
console.error('Error fetching publication targets:', error);
res.status(500).json({
success: false,
error: 'Failed to fetch publication targets'
});
}
});
/**
* GET /api/publications/:id
* Get specific publication by ID
* Public endpoint
* NOTE: This must come LAST as it's a parameterized route
*/
router.get('/:id', publicationsController.getPublicationById);
module.exports = router;