import { Router } from 'express' import { requireAuth, requireRole } from '../auth/authMiddleware.js' import { getRegistrationSettings, updateRegistrationSettings, getAllSettings, } from './settingsService.js' const router = Router() router.use(requireAuth) router.use(requireRole('ADMIN')) // GET /api/settings — 전체 설정 조회 router.get('/', async (_req, res) => { try { const settings = await getAllSettings() res.json(settings) } catch (err) { console.error('[settings] 조회 오류:', err) res.status(500).json({ error: '설정 조회 중 오류가 발생했습니다.' }) } }) // GET /api/settings/registration — 가입 설정 조회 router.get('/registration', async (_req, res) => { try { const settings = await getRegistrationSettings() res.json(settings) } catch (err) { console.error('[settings] 가입 설정 조회 오류:', err) res.status(500).json({ error: '가입 설정 조회 중 오류가 발생했습니다.' }) } }) // PUT /api/settings/registration — 가입 설정 수정 router.put('/registration', async (req, res) => { try { const { autoApprove, defaultRole } = req.body await updateRegistrationSettings({ autoApprove, defaultRole }) const updated = await getRegistrationSettings() res.json(updated) } catch (err) { console.error('[settings] 가입 설정 수정 오류:', err) res.status(500).json({ error: '가입 설정 수정 중 오류가 발생했습니다.' }) } }) export default router