semantic refactor

This commit is contained in:
Daniel Herrero 2018-03-07 14:13:30 +01:00
parent 43bfbf3f4b
commit f82a616940
1 changed files with 7 additions and 6 deletions

View File

@ -40,16 +40,17 @@ module.exports = function(Client) {
delete params.phone;
}
let keys = Object.keys(params);
if (keys.length) {
keys.forEach(
key => {
let properties = Object.keys(params);
if (properties.length) {
properties.forEach(
property => {
let propertyToBeEqual = (property === 'postcode' || property === 'fi' || property === 'id');
if (filters.where.and) {
let filter = {};
filter[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]};
filter[property] = propertyToBeEqual ? params[property] : {regexp: params[property]};
filters.where.and.push(filter);
} else {
filters.where[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]};
filters.where[property] = propertyToBeEqual ? params[property] : {regexp: params[property]};
}
}
);