|
|
@ -35,15 +35,6 @@ function getLogicalOpMethod(filter: Filter) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function parseDateOrDateTimeCondition( |
|
|
|
|
|
|
|
qb: Knex.QueryBuilder, |
|
|
|
|
|
|
|
op: '>' | '<' | '>=' | '<=' | '=' | '!=', |
|
|
|
|
|
|
|
val: any |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
console.log(qb, op, val); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parseConditionV2 = async ( |
|
|
|
const parseConditionV2 = async ( |
|
|
|
_filter: Filter | Filter[], |
|
|
|
_filter: Filter | Filter[], |
|
|
|
knex: XKnex, |
|
|
|
knex: XKnex, |
|
|
@ -280,10 +271,14 @@ const parseConditionV2 = async ( |
|
|
|
|
|
|
|
|
|
|
|
return (qb: Knex.QueryBuilder) => { |
|
|
|
return (qb: Knex.QueryBuilder) => { |
|
|
|
let [field, val] = [_field, _val]; |
|
|
|
let [field, val] = [_field, _val]; |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt) && !val) { |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
if (!val) { |
|
|
|
// for date & datetime, val cannot be empty for all filters
|
|
|
|
// for date & datetime, val cannot be empty for all filters
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// handle sub operation
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isNumericCol(column.uidt) && typeof val === 'string') { |
|
|
|
if (isNumericCol(column.uidt) && typeof val === 'string') { |
|
|
|
// convert to number
|
|
|
|
// convert to number
|
|
|
@ -292,9 +287,6 @@ const parseConditionV2 = async ( |
|
|
|
|
|
|
|
|
|
|
|
switch (filter.comparison_op) { |
|
|
|
switch (filter.comparison_op) { |
|
|
|
case 'eq': |
|
|
|
case 'eq': |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, '=', val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (qb?.client?.config?.client === 'mysql2') { |
|
|
|
if (qb?.client?.config?.client === 'mysql2') { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
[ |
|
|
|
[ |
|
|
@ -319,13 +311,9 @@ const parseConditionV2 = async ( |
|
|
|
// unset rating is considered as NULL
|
|
|
|
// unset rating is considered as NULL
|
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'neq': |
|
|
|
case 'neq': |
|
|
|
case 'not': |
|
|
|
case 'not': |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, '!=', val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (qb?.client?.config?.client === 'mysql2') { |
|
|
|
if (qb?.client?.config?.client === 'mysql2') { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
[ |
|
|
|
[ |
|
|
@ -365,7 +353,6 @@ const parseConditionV2 = async ( |
|
|
|
.orWhereNull(customWhereClause ? _val : _field); |
|
|
|
.orWhereNull(customWhereClause ? _val : _field); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'like': |
|
|
|
case 'like': |
|
|
|
if (!val) { |
|
|
|
if (!val) { |
|
|
@ -474,9 +461,6 @@ const parseConditionV2 = async ( |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'gt': |
|
|
|
case 'gt': |
|
|
|
const gt_op = customWhereClause ? '<' : '>'; |
|
|
|
const gt_op = customWhereClause ? '<' : '>'; |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, gt_op, val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qb = qb.where(field, gt_op, val); |
|
|
|
qb = qb.where(field, gt_op, val); |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
// unset rating is considered as NULL
|
|
|
|
// unset rating is considered as NULL
|
|
|
@ -484,14 +468,10 @@ const parseConditionV2 = async ( |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'ge': |
|
|
|
case 'ge': |
|
|
|
case 'gte': |
|
|
|
case 'gte': |
|
|
|
const ge_op = customWhereClause ? '<=' : '>='; |
|
|
|
const ge_op = customWhereClause ? '<=' : '>='; |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, ge_op, val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qb = qb.where(field, ge_op, val); |
|
|
|
qb = qb.where(field, ge_op, val); |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
// unset rating is considered as NULL
|
|
|
|
// unset rating is considered as NULL
|
|
|
@ -499,13 +479,9 @@ const parseConditionV2 = async ( |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'lt': |
|
|
|
case 'lt': |
|
|
|
const lt_op = customWhereClause ? '>' : '<'; |
|
|
|
const lt_op = customWhereClause ? '>' : '<'; |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, lt_op, val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qb = qb.where(field, lt_op, val); |
|
|
|
qb = qb.where(field, lt_op, val); |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
// unset number is considered as NULL
|
|
|
|
// unset number is considered as NULL
|
|
|
@ -513,14 +489,10 @@ const parseConditionV2 = async ( |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'le': |
|
|
|
case 'le': |
|
|
|
case 'lte': |
|
|
|
case 'lte': |
|
|
|
const le_op = customWhereClause ? '>=' : '<='; |
|
|
|
const le_op = customWhereClause ? '>=' : '<='; |
|
|
|
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) { |
|
|
|
|
|
|
|
parseDateOrDateTimeCondition(qb, le_op, val); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qb = qb.where(field, le_op, val); |
|
|
|
qb = qb.where(field, le_op, val); |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
if (column.uidt === UITypes.Rating) { |
|
|
|
// unset number is considered as NULL
|
|
|
|
// unset number is considered as NULL
|
|
|
@ -528,7 +500,6 @@ const parseConditionV2 = async ( |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
qb = qb.orWhereNull(field); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'in': |
|
|
|
case 'in': |
|
|
|
qb = qb.whereIn( |
|
|
|
qb = qb.whereIn( |
|
|
|