Skip to content

Commit

Permalink
[*] Filters - Fix potential chart / records retrieval errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbesnier committed Jun 21, 2019
1 parent e40e0cf commit b1c0d9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log

## [Unreleased]
### Fixed
- Filters - Fix potential chart / records retrieval errors (Regression introduced in v3.2.2).

## RELEASE 3.2.2 - 2019-06-20
### Changed
Expand Down
44 changes: 20 additions & 24 deletions src/services/operator-value-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { Schemas } from 'forest-express';
import Operators from '../utils/operators';
import OperatorDateIntervalParser from './operator-date-interval-parser';

class OperatorValueParser {
constructor(options) {
this.OPERATORS = new Operators(options);
this.options = options;
}
function OperatorValueParser(options) {
const OPERATORS = new Operators(options);

perform(model, fieldName, value, timezone) {
this.perform = (model, fieldName, value, timezone) => {
const operatorDateIntervalParser = new OperatorDateIntervalParser(
value,
timezone,
this.options,
options,
);

// NOTICE: Handle boolean for MySQL database
let modelName;
let field;
Expand Down Expand Up @@ -47,39 +45,37 @@ class OperatorValueParser {
if (value[0] === '!' && value[1] !== '*') {
value = value.substring(1);
if (fieldBoolean) {
condition[this.OPERATORS.NOT] = _.isUndefined(valueBoolean) ? null :
valueBoolean;
condition[OPERATORS.NOT] = _.isUndefined(valueBoolean) ? null : valueBoolean;
} else {
condition[this.OPERATORS.NE] = value;
condition[OPERATORS.NE] = value;
}
} else if (value[0] === '>') {
condition[this.OPERATORS.GT] = value.substring(1);
condition[OPERATORS.GT] = value.substring(1);
} else if (value[0] === '<') {
condition[this.OPERATORS.LT] = value.substring(1);
condition[OPERATORS.LT] = value.substring(1);
} else if (value[0] === '*' && value[value.length - 1] === '*') {
condition[this.OPERATORS.LIKE] = `%${value.substring(1, value.length - 1)}%`;
} else if (value[0] === '!' && value[1] === '*' &&
value[value.length - 1] === '*') {
condition[OPERATORS.LIKE] = `%${value.substring(1, value.length - 1)}%`;
} else if (value[0] === '!' && value[1] === '*' && value[value.length - 1] === '*') {
// TODO : Include null values
// return { $or: { $notLike: '%' + value + '%', $eq: null } };
condition[this.OPERATORS.NOT_LIKE] = `%${value.substring(2, value.length - 1)}%`;
condition[OPERATORS.NOT_LIKE] = `%${value.substring(2, value.length - 1)}%`;
} else if (value[0] === '*') {
condition[this.OPERATORS.LIKE] = `%${value.substring(1)}`;
condition[OPERATORS.LIKE] = `%${value.substring(1)}`;
} else if (value[value.length - 1] === '*') {
condition[this.OPERATORS.LIKE] = `${value.substring(0, value.length - 1)}%`;
condition[OPERATORS.LIKE] = `${value.substring(0, value.length - 1)}%`;
} else if (value === '$present') {
condition[this.OPERATORS.NE] = null;
condition[OPERATORS.NE] = null;
} else if (value === '$blank') {
condition[this.OPERATORS.EQ] = null;
condition[OPERATORS.EQ] = null;
} else if (operatorDateIntervalParser.isIntervalDateValue()) {
return operatorDateIntervalParser.getIntervalDateFilter();
} else if (fieldBoolean) {
condition[this.OPERATORS.EQ] = _.isUndefined(valueBoolean) ? null : valueBoolean;
condition[OPERATORS.EQ] = _.isUndefined(valueBoolean) ? null : valueBoolean;
} else {
condition[this.OPERATORS.EQ] = value;
condition[OPERATORS.EQ] = value;
}
return condition;
}
};
}

export default OperatorValueParser;
module.exports = OperatorValueParser;

0 comments on commit b1c0d9c

Please sign in to comment.