Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// searchFields.
const fieldsSimpleNotFound = _.xor(
searchFields,
_.map(fields, (field) => field.field),
);
const fieldsAssociationNotFound = _.xor(
_.map(searchAssociationFields, (association) => association.split('.')[0]),
_.keys(associations),
);
if (fieldsSimpleNotFound.length) {
Interface.logger.warn(`Cannot find the fields [${fieldsSimpleNotFound}] while searching records in model ${model.name}.`);
}
if (fieldsAssociationNotFound.length) {
Interface.logger.warn(`Cannot find the associations [${fieldsAssociationNotFound}] while searching records in model ${model.name}.`);
}
}
const promise = new Promise(async (resolve) => {
try {
const condition = await Promise.resolve(field.search(params.search));
if (condition) {
pushCondition(condition, field.field);
}
this.hasSmartFieldSearch = true;
} catch (error) {
Interface.logger.error(`Cannot search properly on Smart Field ${field.field}`, error);
}
resolve();
});
promises.push(promise);
.catch((error) => {
if (error.message.indexOf('Cast to') > -1 && error.message.indexOf('failed for value') > -1) {
Interface.logger.warn(`Cannot update the ${modelName} #${recordId} because of a "type" key usage (which is a reserved keyword in Mongoose).`);
} else {
Interface.logger.error(`Cannot update the ${modelName} #${recordId} because of an unexpected issue: ${error}`);
}
return model.findByIdAndUpdate(recordId);
});
}
.each(_.values(model.associations), (association) => {
try {
const schema = getSchemaForAssociation(association);
fields.push(schema);
} catch (error) {
Interface.logger.error(`Cannot fetch properly association ${association.associationAccessor} of model ${model.name}`, error);
}
});
function formatRef(ref) {
const models = mongooseUtils.getModels(opts);
if (models[ref]) {
return utils.getModelName(models[ref]);
}
Interface.logger.warn(`Cannot find the reference "${ref}" on the model "${model.modelName}".`);
return null;
}