import express from 'express';
const router = express.Router();

import authMiddleware from '../middleware/authMiddleware.js';

import Setting from '../models/Setting.js';
import Logs from '../libs/logs.js';

router.get('/get_setting', authMiddleware, (req, res) => {
  Setting.get()
  .then(setting => {
    res.sendSuccess(setting);
  })
  .catch(err => {
    Logs.errDev('获取参数设置失败:', err);
    res.badRequest(err.message);
  });
});

router.post('/update_setting', authMiddleware, (req, res) => {
  Setting.update(req.body)
  .then(setting => {
    res.sendSuccess(setting);
  })
  .catch(err => {
    Logs.errDev('更新参数设置失败:', err);
    res.badRequest(err.message);
  });
});

export default router;
