CoreID/app/routing/middleware/util/Setting.middleware.js
2020-05-20 09:56:03 -05:00

20 lines
494 B
JavaScript

const { Middleware, HTTPError } = require('libflitter')
class SettingMiddleware extends Middleware {
static get services() {
return [...super.services, 'models']
}
async test(req, res, next, { key, value = true }) {
const Setting = this.models.get('Setting')
const actual_value = await Setting.get(key)
if ( actual_value !== value )
throw new HTTPError(404)
return next()
}
}
module.exports = exports = SettingMiddleware