const fs = require('fs'); const path = require('path'); const BANNER_FILE = path.join(__dirname, '../../data/banner.json'); function readBanner() { try { const raw = fs.readFileSync(BANNER_FILE, 'utf8'); return JSON.parse(raw); } catch { return { message: '', type: 'info', liveFrom: null, liveTill: null }; } } function writeBanner(data) { fs.writeFileSync(BANNER_FILE, JSON.stringify(data, null, 2), 'utf8'); } // @desc Get the current banner // @route GET /api/banner // @access Public const getBanner = (req, res) => { res.json(readBanner()); }; // @desc Set the banner // @route POST /api/banner // @access Supervisor / Admin const setBanner = (req, res) => { const { message, type, liveFrom, liveTill } = req.body; const allowed = ['info', 'warning', 'success', 'danger']; const banner = { message: typeof message === 'string' ? message.trim() : '', type: allowed.includes(type) ? type : 'info', liveFrom: liveFrom || null, liveTill: liveTill || null, }; writeBanner(banner); res.json(banner); }; module.exports = { getBanner, setBanner };