CoreID/app/routing/middleware/util/Setting.middleware.js

20 lines
494 B
JavaScript
Raw Permalink Normal View History

2020-05-20 14:56:03 +00:00
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