Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
RED.httpAdmin.get("/getDecisionTables", RED.auth.needsPermission(''), function(req,res) {
var decisionTableModel = loopback.findModel('DecisionTable');
if(decisionTableModel) {
// Firing the Find query to get results from DB.
// TODO: Query to retrieve only property 'name' from DB.
decisionTableModel.find({}, req.callContext, function(err, data){
var result = [];
if(data.length > 0){
data.forEach(function(elem){
// Retrieving only 'name' from the DB result.
result.push({name:elem.name});
})
}
// Sending result JSON.
res.json(result);
});
} else {
console.error("Unable to find Model DecisionTable.")
var itemType = propDetails.type[0];
if (typeof itemType === 'function') {
/* Array of another model */
if (itemType.name === 'ModelConstructor') {
associations.push(itemType);
propDetails.itemtype = 'model';
propDetails.modeltype = itemType.definition.name;
} else {
/* Array of primitive */
propDetails.itemtype = itemType.name.toLowerCase();
}
}
propDetails.type = 'array';
}
if (propDetails.refcodetype) {
associations.push(loopback.findModel(propDetails.refcodetype, options));
}
if (propDetails.enumtype) {
var enumModel = model.app.models[propDetails.enumtype];
if (enumModel) {
// enumtype is pointing to model
propDetails.listdata = enumModel.settings.enumList;
} else {
// enumtype is not pointing to model
log.error(options, 'error finding enumtype ', propDetails.enumtype);
}
}
properties[propName] = propDetails;
}
});
function attachBeforeRemoteHookToModel(modelName, options) {
var model = loopback.findModel(modelName, options);
// Checking the flag that DataACL exists and attaching the hook
if (!model.settings._dataACLExists) {
model.settings._dataACLExists = true;
// Attaching beforeRemote hook to model to do the DataACL applyFilter
model.beforeRemote('**', function (ctx, modelInstance, next) {
var proxyKey = appinstance.get('evproxyInternalKey') || '97b62fa8-2a77-458b-87dd-ef64ff67f847';
if (ctx.req && ctx.req.headers && proxyKey) {
if (ctx.req.headers['x-evproxy-internal-key'] === proxyKey) {
return next();
}
}
dataACLModel.applyFilter(ctx, next);
});
}
}
function getOrCreateLoopBackConfigModel() {
let LoopBackConfigFile = loopback.findModel('LoopBackConfigFile');
if (LoopBackConfigFile) return LoopBackConfigFile;
LoopBackConfigFile = ConfigFile.extend('LoopBackConfigFile');
// Override `getWorkspaceDir` to return node_modules/loopback
LoopBackConfigFile.getWorkspaceDir = function() {
const workspaceDir = LoopBackConfigFile.base.getWorkspaceDir();
return path.join(workspaceDir, 'node_modules', 'loopback');
};
// Override `isReadOnly` to be always `true`
Object.defineProperty(LoopBackConfigFile.prototype, 'isReadOnly', {
value: true,
});
return LoopBackConfigFile;
before('create test models', function createModels(done) {
var modelDefinition = loopback.findModel('ModelDefinition');
var data = {
'name': 'TestAccount',
'base': 'BaseActorEntity',
'options': {
stateThreshold: 1
}
};
modelDefinition.create(data, bootstrap.defaultContext, createTransferModel);
function createTransferModel() {
var data = {
'name': 'TestTransfer',
'base': 'BaseJournalEntity'
};
modelDefinition.create(data, bootstrap.defaultContext, addAllFunctions);
this.on('input', function (msg) {
var filter;
node.status({});
var modelName = config.modelname || msg.modelName;
if (config.filter && typeof config.filter === 'string') filter = JSON.parse(config.filter);
if (config.filter && typeof config.filter === 'object') filter = config.filter;
if (!filter) filter = msg.filter;
if (!filter) filter = {};
var Model;
if (modelName && modelName.trim().length > 0) {
Model = loopback.findModel(modelName, node.callContext);
if (Model) {
Model.find(filter, msg.callContext, function (err, response) {
if (err) {
console.log(err);
node.status({
"fill": "red",
"shape": "dot",
"text": "An error occurred"
});
msg.payload = err;
node.send([null, msg]);
} else {
node.status({
"fill": "green",
"shape": "dot",
"text": "Found " + response.length + " records"
redNodes.setFlows(flowArray).then(function setFlowsFn() {
callback();
}).otherwise(function setFlowsOtherwiseFn(err) {
console.log('node red error');
callback(err);
});
}
});
});
} else {
console.log(' *** NODE-RED : RELOADING FLOWS *** ');
var flowArray = [];
var options = {};
options.ignoreAutoScope = true;
options.fetchAllScopes = true;
var flowModel = loopback.findModel('NodeRedFlow');
flowModel.find({}, options, function findCb(err, results) {
if (err) {
callback(err);
}
results.forEach(function resultsForEach(r) {
r.flow.forEach(function prepareFlowArrayFn(f) {
flowArray.push(f);
});
});
if (flowArray.length > 0) {
redNodes.setFlows(flowArray).then(function setFlowsFn() {
callback();
}).otherwise(function setFlowsOtherwiseFn(err) {
console.log('node red error');
callback(err);
});
return new Promise(function (resolve, reject) {
var model = loopback.findModel(modelName, options);
model.findOne({ where: data }, options, function (err, res) {
if (err) {
reject(err);
} else if (!res) {
model.create(data, options, function (err, res) {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
} else {
resolve(true);
}
});
});
function doMigrate(appinstance, option, cb) {
var appVer = buildAppVersion(appinstance, option);
var SystemConfig = loopback.findModel('SystemConfig');
SystemConfig.find({
where: {
key: 'version'
}
}, util.bootContext(), function systemConfigFindCbFn(err, data) {
var versionMisMatch = true;
if (err) {
cb(err);
}
if (data.length) {
curDbVer = data[0].value;
curSysVerData = data[0];
versionMisMatch = appVerGreaterThanDBVer(appVer, curDbVer);
}
if (versionMisMatch) {
var dbMig = getListOfMigrations(appinstance, option);
messaging.subscribe('evictCache', function (msg) {
var modelName = msg.modelName;
var evictCtx = msg.evictCtx;
var model = loopback.findModel(modelName);
if (model) {
model.evictCache(true, evictCtx);
}
});
/**