const express = require('express');
const router = express.Router();

const authMiddleware = require('../middleware/authMiddleware');

const Setting = require('../models/Setting');
const Logs = require('../libs/logs');

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);
  });
});

module.exports = router;