Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ValueStatGetter(model, params, options) {
const OPERATORS = new Operators(options);
this.operatorDateParser = new BaseOperatorDateParser({
operators: OPERATORS,
timezone: params.timezone,
});
const schema = Schemas.schemas[model.name];
function getAggregate() {
return params.aggregate.toLowerCase();
}
function getAggregateField() {
// NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
const fieldName = params.aggregate_field
|| schema.primaryKeys[0]
|| schema.fields[0].field;
return `${schema.name}.${Orm.getColumnName(schema, fieldName)}`;
}
if (value === 'false') { return false; }
return typeof value === 'boolean' ? value : null;
};
const parseString = (value) => {
// NOTICE: Check if the value is a real ObjectID. By default, the isValid method returns true
// for a random string with length 12 (example: 'Black Friday').
const { ObjectId } = options.mongoose.Types;
if (ObjectId.isValid(value) && ObjectId(value).toString() === value) {
return ObjectId(value);
}
return value;
};
const parseArray = (value) => ({ $size: value });
const parseOther = (value) => value;
this.operatorDateParser = new BaseOperatorDateParser({
operators: { GTE: '$gte', LTE: '$lte' },
timezone,
});
this.perform = async (filtersString) => BaseFiltersParser
.perform(filtersString, this.formatAggregation, this.formatCondition);
this.formatAggregation = async (aggregator, formatedConditions) => {
const aggregatorOperator = this.formatAggregatorOperator(aggregator);
return { [aggregatorOperator]: formatedConditions };
};
this.formatCondition = async (condition) => {
if (_.isEmpty(condition)) {
throw new InvalidFiltersFormatError('Empty condition in filter');
}
function FiltersParser(modelSchema, timezone, options) {
this.OPERATORS = new Operators(options);
this.operatorDateParser = new BaseOperatorDateParser({ operators: this.OPERATORS, timezone });
this.perform = async (filtersString) =>
BaseFiltersParser.perform(filtersString, this.formatAggregation, this.formatCondition);
this.formatAggregation = async (aggregator, formatedConditions) => {
const aggregatorOperator = this.formatAggregatorOperator(aggregator);
return { [aggregatorOperator]: formatedConditions };
};
this.formatCondition = async (condition) => {
const formatedField = this.formatField(condition.field);
if (this.operatorDateParser.isDateOperator(condition.operator)) {
return {
[formatedField]: this.operatorDateParser
.getDateFilter(condition.operator, condition.value),