'use strict'; const _ = require('lodash'); const { BusinessError, ErrorCode } = require('naf-core').Error; const tenantIsUse = async ctx => { const _tenant = ctx.tenant; const res = await ctx.model.System.Tenant.findOne({ _tenant }); if (!res) throw new BusinessError(ErrorCode.SERVICE_FAULT, '该分站未开通!'); if (!res.is_use) throw new BusinessError(ErrorCode.SERVICE_FAULT, '该分站处于关闭状态!'); return true; }; module.exports = options => { return async function tenantUse(ctx, next) { console.log('function in tenant-use middleware'); // await this.tenantIsUse(ctx); await next(); }; };