Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
qb.where(column, '>=', typeValue);
}
}
});
}
}
// If the value is an equality filter
else {
// If the key is in the like filter, ignore the filter
if (!_hasIn(filterValues.like, key)){
let [column, jsonColumn, dataType] = key.split(':');
// Remove all but the last table name, need to get number of dots
column = internals.formatRelation(internals.formatColumnNames([column])[0]);
if (!_isArray(value)){
value = split(String(value), { keepQuotes: true, sep: ',' });
}
if (jsonColumn) {
jsonFields.buildFilterWithType(qb, Bookshelf.knex, 'equal', value, column, jsonColumn, dataType);
}
else {
internals.equalityFilter(qb, column, value);
}
}
}
});
});
column
})
);
// Change to orWhere after the first where
if (where === 'where'){
where = 'orWhere';
}
});
// If the key is in the top level filter, filter on orWhereIn
if (_hasIn(filterValues, typeKey)){
// Determine if there are multiple filters to be applied
let equalityValue = filterValues[typeKey];
if (!_isArray(equalityValue)){
equalityValue = split(String(equalityValue), { keepQuotes: true, sep: ',' });
}
internals.equalityFilter(qbWhere, column, equalityValue, 'orWhere');
}
});
}
_forEach(filterTypeValues, (typeValue, typeKey) => {
let [column, jsonColumn, dataType] = typeKey.split(':');
// Remove all but the last table name, need to get number of dots
column = internals.formatRelation(internals.formatColumnNames([column])[0]);
// Determine if there are multiple filters to be applied
let valueArray = split(String(typeValue), { keepQuotes: true, sep: ',' });
if (jsonColumn) {
// Pass in the an equality filter for the same column name as last parameter for OR filtering with `like` and `equals`
let extraEqualityFilter = filterValues[typeKey];
if (extraEqualityFilter) {
extraEqualityFilter = split(String(extraEqualityFilter), { keepQuotes: true, sep: ',' });
}
jsonFields.buildFilterWithType(qb, Bookshelf.knex, key, valueArray, column, jsonColumn, dataType, extraEqualityFilter);
}
else {
// Attach different query for each type
if (key === 'like'){
qb.where((qbWhere) => {
let where = 'where';
let textType = 'text';
if (internals.client === 'mysql' || internals.client === 'mssql'){
textType = 'char';
}
_forEach(valueArray, (val) => {
let likeQuery = `LOWER(CAST(:column: AS ${textType})) like LOWER(:value)`;
_forEach(filterTypeValues, (typeValue, typeKey) => {
let [column, jsonColumn, dataType] = typeKey.split(':');
// Remove all but the last table name, need to get number of dots
column = internals.formatRelation(internals.formatColumnNames([column])[0]);
// Determine if there are multiple filters to be applied
let valueArray = split(String(typeValue), { keepQuotes: true, sep: ',' });
if (jsonColumn) {
// Pass in the an equality filter for the same column name as last parameter for OR filtering with `like` and `equals`
let extraEqualityFilter = filterValues[typeKey];
if (extraEqualityFilter) {
extraEqualityFilter = split(String(extraEqualityFilter), { keepQuotes: true, sep: ',' });
}
jsonFields.buildFilterWithType(qb, Bookshelf.knex, key, valueArray, column, jsonColumn, dataType, extraEqualityFilter);
}
else {
// Attach different query for each type
if (key === 'like'){
qb.where((qbWhere) => {
let where = 'where';
let textType = 'text';