Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.perform = (model, key, value) => {
const schema = Interface.Schemas.schemas[utils.getModelName(model)];
let parseFct = val => val;
let ret = null;
const fieldValues = key.split(':');
const fieldName = fieldValues[0];
const subfieldName = fieldValues[1];
// Mongoose Aggregate don't parse the value automatically.
let field = _.find(schema.fields, { field: fieldName });
const isEmbeddedField = !!field.type.fields;
if (isEmbeddedField) {
field = _.find(field.type.fields, { field: subfieldName });
}
if (field) {
function HasManyGetter(model, association, opts, params) {
const queryBuilder = new QueryBuilder(model, opts, params);
const schema = Interface.Schemas.schemas[association.name];
const primaryKeyModel = _.keys(model.primaryKeys)[0];
function getFieldNamesRequested() {
if (!params.fields || !params.fields[association.name]) { return null; }
// NOTICE: Force the primaryKey retrieval to store the records properly in
// the client.
const primaryKeyArray = [_.keys(association.primaryKeys)[0]];
return _.union(primaryKeyArray, params.fields[association.name].split(','));
}
const fieldNamesRequested = getFieldNamesRequested();
const searchBuilder = new SearchBuilder(association, opts, params, fieldNamesRequested);
const where = searchBuilder.perform(params.associationName);
const include = queryBuilder.getIncludes(association, fieldNamesRequested);
// NOTICE: Sequelize version previous to 4.4.2 generate a bad MSSQL query
// if users sort the collection on the primary key, so we prevent
// that.
const idField = _.keys(model.primaryKeys)[0];
if (Database.isMSSQL(opts) && _.includes([idField, `-${idField}`], params.sort)) {
const sequelizeVersion = opts.sequelize.version;
if (sequelizeVersion !== '4.4.2-forest') {
return null;
}
}
if (params.sort.indexOf('.') !== -1) {
// NOTICE: Sort on the belongsTo displayed field
const [associationName, fieldName] = params.sort.split('.');
const column = getReferenceField(
Schemas.schemas,
(aliasSchema || schema),
associationName,
fieldName,
);
return [[opts.sequelize.col(column), order]];
}
if (aliasName) {
return [[opts.sequelize.col(`${aliasName}.${Orm.getColumnName(aliasSchema, params.sort)}`), order]];
}
return [[params.sort, order]];
}
return null;
};
}
// NOTICE: Handle boolean for MySQL database
let modelName;
let field;
let fieldSplit;
let valueBoolean;
let fieldBoolean = false;
if (fieldName.indexOf(':') === -1) {
modelName = model.name;
} else {
fieldSplit = fieldName.split(':');
modelName = fieldSplit[0];
fieldName = fieldSplit[1];
}
const schema = Schemas.schemas[modelName];
if (schema) {
field = _.find(schema.fields, currentField => currentField.field === fieldName);
if (field && field.type === 'Boolean') {
fieldBoolean = true;
if (value.indexOf('true') > -1) {
valueBoolean = true;
} else if (value.indexOf('false') > -1) {
valueBoolean = false;
}
}
}
const condition = {};
if (value[0] === '!' && value[1] !== '*') {
value = value.substring(1);
if (fieldBoolean) {
// 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}.`);
}
}
exports.ResourceSerializer = Interface.ResourceSerializer;
exports.ResourceDeserializer = Interface.ResourceDeserializer;
exports.Schemas = Interface.Schemas;
exports.ResourcesRoute = Interface.ResourcesRoute;
exports.PermissionMiddlewareCreator = Interface.PermissionMiddlewareCreator;
exports.RecordsCounter = Interface.RecordsCounter;
exports.RecordsExporter = Interface.RecordsExporter;
exports.RecordsGetter = Interface.RecordsGetter;
exports.RecordGetter = Interface.RecordGetter;
exports.RecordUpdater = Interface.RecordUpdater;
exports.RecordCreator = Interface.RecordCreator;
exports.RecordRemover = Interface.RecordRemover;
exports.RecordSerializer = Interface.RecordSerializer;
exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
exports.init = function init(opts) {
exports.opts = opts;
// NOTICE: Ensure compatibility with the old middleware configuration.
if (opts.sequelize && !('connections' in opts)) {
opts.connections = [opts.sequelize];
opts.sequelize = opts.sequelize.Sequelize;
}
exports.getLianaName = function getLianaName() {
return 'forest-express-sequelize';
};
exports.getLianaVersion = function getLianaVersion() {
const lianaVersion = lianaPackage.version.match(REGEX_VERSION);
const LeaderboardStatGetter = require('./services/leaderboard-stat-getter');
const QueryStatGetter = require('./services/query-stat-getter');
const RecordsDecorator = require('./utils/records-decorator');
const REGEX_VERSION = /(\d+\.)?(\d+\.)?(\*|\d+)/;
exports.collection = Interface.collection;
exports.ensureAuthenticated = Interface.ensureAuthenticated;
exports.StatSerializer = Interface.StatSerializer;
exports.ResourceSerializer = Interface.ResourceSerializer;
exports.ResourceDeserializer = Interface.ResourceDeserializer;
exports.Schemas = Interface.Schemas;
exports.ResourcesRoute = Interface.ResourcesRoute;
exports.PermissionMiddlewareCreator = Interface.PermissionMiddlewareCreator;
exports.RecordsCounter = Interface.RecordsCounter;
exports.RecordsExporter = Interface.RecordsExporter;
exports.RecordsGetter = Interface.RecordsGetter;
exports.RecordGetter = Interface.RecordGetter;
exports.RecordUpdater = Interface.RecordUpdater;
exports.RecordCreator = Interface.RecordCreator;
exports.RecordRemover = Interface.RecordRemover;
exports.RecordSerializer = Interface.RecordSerializer;
exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
exports.init = function init(opts) {
exports.opts = opts;
// NOTICE: Ensure compatibility with the old middleware configuration.
if (opts.sequelize && !('connections' in opts)) {
exports.collection = Interface.collection;
exports.ensureAuthenticated = Interface.ensureAuthenticated;
exports.StatSerializer = Interface.StatSerializer;
exports.ResourceSerializer = Interface.ResourceSerializer;
exports.ResourceDeserializer = Interface.ResourceDeserializer;
exports.Schemas = Interface.Schemas;
exports.ResourcesRoute = Interface.ResourcesRoute;
exports.PermissionMiddlewareCreator = Interface.PermissionMiddlewareCreator;
exports.RecordsCounter = Interface.RecordsCounter;
exports.RecordsExporter = Interface.RecordsExporter;
exports.RecordsGetter = Interface.RecordsGetter;
exports.RecordGetter = Interface.RecordGetter;
exports.RecordUpdater = Interface.RecordUpdater;
exports.RecordCreator = Interface.RecordCreator;
exports.RecordRemover = Interface.RecordRemover;
exports.RecordSerializer = Interface.RecordSerializer;
exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
exports.init = function init(opts) {
exports.opts = opts;
// NOTICE: Ensure compatibility with the old middleware configuration.
if (opts.sequelize && !('connections' in opts)) {
opts.connections = [opts.sequelize];
opts.sequelize = opts.sequelize.Sequelize;
}
exports.getLianaName = function getLianaName() {
return 'forest-express-sequelize';
const REGEX_VERSION = /(\d+\.)?(\d+\.)?(\*|\d+)/;
exports.collection = Interface.collection;
exports.ensureAuthenticated = Interface.ensureAuthenticated;
exports.StatSerializer = Interface.StatSerializer;
exports.ResourceSerializer = Interface.ResourceSerializer;
exports.ResourceDeserializer = Interface.ResourceDeserializer;
exports.Schemas = Interface.Schemas;
exports.ResourcesRoute = Interface.ResourcesRoute;
exports.PermissionMiddlewareCreator = Interface.PermissionMiddlewareCreator;
exports.RecordsCounter = Interface.RecordsCounter;
exports.RecordsExporter = Interface.RecordsExporter;
exports.RecordsGetter = Interface.RecordsGetter;
exports.RecordGetter = Interface.RecordGetter;
exports.RecordUpdater = Interface.RecordUpdater;
exports.RecordCreator = Interface.RecordCreator;
exports.RecordRemover = Interface.RecordRemover;
exports.RecordSerializer = Interface.RecordSerializer;
exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
exports.init = function init(opts) {
exports.opts = opts;
// NOTICE: Ensure compatibility with the old middleware configuration.
if (opts.sequelize && !('connections' in opts)) {
opts.connections = [opts.sequelize];
opts.sequelize = opts.sequelize.Sequelize;
}
exports.collection = Interface.collection;
exports.ensureAuthenticated = Interface.ensureAuthenticated;
exports.StatSerializer = Interface.StatSerializer;
exports.ResourceSerializer = Interface.ResourceSerializer;
exports.ResourceDeserializer = Interface.ResourceDeserializer;
exports.Schemas = Interface.Schemas;
exports.ResourcesRoute = Interface.ResourcesRoute;
exports.PermissionMiddlewareCreator = Interface.PermissionMiddlewareCreator;
exports.RecordsCounter = Interface.RecordsCounter;
exports.RecordsExporter = Interface.RecordsExporter;
exports.RecordsGetter = Interface.RecordsGetter;
exports.RecordGetter = Interface.RecordGetter;
exports.RecordUpdater = Interface.RecordUpdater;
exports.RecordCreator = Interface.RecordCreator;
exports.RecordRemover = Interface.RecordRemover;
exports.RecordSerializer = Interface.RecordSerializer;
exports.PUBLIC_ROUTES = Interface.PUBLIC_ROUTES;
exports.init = function init(opts) {
exports.opts = opts;
// NOTICE: Ensure compatibility with the old middleware configuration.
if (opts.sequelize && !('connections' in opts)) {
opts.connections = [opts.sequelize];
opts.sequelize = opts.sequelize.Sequelize;
}
exports.getLianaName = function getLianaName() {
return 'forest-express-sequelize';
};