Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var model = app.models[key];
model.clientModelName = key;
model.clientPlural = model.pluralModelName;
util.attachOverrideModelFunction(model);
model.disableRemoteMethod('createChangeStream', true);
app.locals.modelNames[key.toLowerCase()] = model.modelName;
app.locals.modelNames[key] = model.modelName;
if (key !== model.modelName) {
return callback();
}
var modelDefinitionObject = util.getFileBasedModelSettings(model);
// add the 'name' member
modelDefinitionObject.name = key;
// to avoid crash due to max event listener check
DataSource.super_.defaultMaxListeners = DataSource.super_.defaultMaxListeners + 1;
modelDefinition.findOne({ 'where': { 'name': key } }, util.bootContext(), function modelDefinitionFindOneFn(err, modelDef) {
if (err) {
log.error(util.bootContext(), 'modelDefinition.findOne name="', key, '" Error: ', err);
return callback(err);
}
if (!modelDef) {
modelDefinition.create(modelDefinitionObject, util.bootContext(), function modelDefinitionCreateFn(err, res) {
if (err) {
log.error(util.bootContext(), 'modelDefinition.create obj=', modelDefinitionObject, ' Error: ', err);
return callback(err);
}
callback();
});
} else {
callback();
}