首页 > 解决方案 > 环回中每个 API 调用中的 Where 子句

问题描述

我想要一种可以添加“where”子句的方法,该子句将在 Get、Update、Delete 的所有 API 调用中都有一个 Id。

我正在使用中间件来实现这一点。下面是我的代码:

module.exports = function(){
    return function parse(req, res, next) {
        // Add an 'and' filter that specifies the tenant in all requests. 
        req.query.filter = ({
            where: { tenantCompanyKey: '1a4f7513147aefc2a93ac7153df458fd' }
        });
        next();
    }
}

所以当查询被执行时,它应该看起来像:

SELECT * FROM tbl_accounts
         WHERE tenant_company_key = '1a4f7513147aefc2a93ac7153df458fd'

标签: javascriptnode.jsloopbackjs

解决方案


推荐阅读