let express = require('express')
let router = express.Router()
const auth = require('../lib/auth')

const Errors = require('../lib/errors')
let { Settings, Ban, Sequelize } = require('../models')

router.get('/', async(req, res, next) => {
	try {
		let settings = await Settings.findOne({
			where: {
				id: 1
			},
			attributes: { exclude: ['id', 'createdAt', 'updatedAt'] }
		})

		if(!settings) throw Errors.noSettings

		res.json(settings.toJSON())
	} catch (e) { next(e) }

})

router.all('*', auth, (req, res, next) => {
	if(req.userData.admin) {
		next()
	} else {
		res.status(401)
		res.json({
			errors: [Errors.requestNotAuthorized]
		})
	}
})

module.exports = router
