【发布时间】:2019-01-08 23:24:42
【问题描述】:
我有一个将 userId 映射到 roleId 的角色映射模型,我需要角色映射模型上的远程方法来检索给定 userId 的 role-mappingId。
这是 remoteMethod 的代码
'use strict';
module.exports = function(Rolemapping) {
Rolemapping.getRolesByUser = async function (id, cb) {
const roleMappings = await Rolemapping.find({ where: { principalId: id
} })
cb(null, roleMappings);
};
Rolemapping.remoteMethod("getRolesByUser", {
http: {
path: "/getRolesByUser",
verb: "get"
},
accepts: [
{ arg: "userId", type: "string", http: { source: "query" } }
],
returns: {
arg: "result",
type: "string"
},
description: "Cvs "
});
};
这是角色映射 json 文件:
{
"name": "roleMapping",
"base": "RoleMapping",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"role": {
"type": "belongsTo",
"model": "role",
"foreignKey": "roleId"
}
},
"acls": [],
"methods": {}
}
上述远程方法未显示在环回 API 资源管理器中。
【问题讨论】:
标签: javascript node.js loopbackjs