forked from Neil-UWA/loopback-remote-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote-routing.js
More file actions
39 lines (31 loc) · 1006 Bytes
/
Copy pathremote-routing.js
File metadata and controls
39 lines (31 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var _ = require('lodash');
var utils = require('./lib/utils.js');
var RemoteMethods = require('./lib/remote-methods.js');
module.exports = function(Model, options) {
Model.on('attached', function() {
RemoteRouting(Model, options);
});
};
//options : {only: [], except: []}
//only: only expose specified methods, disable others
//except: expose all methods, except specified ones
//symbol @ donates the method is static
function RemoteRouting(Model, options) {
options = options || {};
var methods = RemoteMethods(Model);
if (options.only && options.only.length) {
methods = _.difference(methods, options.only);
}
if (options.except && options.except.length) {
methods = _.filter(methods, function(method){
return _.includes(options.except, method);
});
}
methods.forEach(function(method){
if (/^@/.test(method)) {
Model.disableRemoteMethod(method.replace(/^@/, ''), true);
} else {
Model.disableRemoteMethod(method, false);
}
});
}