Browse Source

refactor: wrap switch case

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5252/head
Pranav C 2 years ago
parent
commit
1ba4726007
  1. 65
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

65
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -576,49 +576,56 @@ const parseConditionV2 = async (
} }
} }
break; break;
case 'gt': { case 'gt':
const gt_op = customWhereClause ? '<' : '>'; {
qb = qb.where(field, gt_op, val); const gt_op = customWhereClause ? '<' : '>';
if (column.uidt === UITypes.Rating) { qb = qb.where(field, gt_op, val);
// unset rating is considered as NULL if (column.uidt === UITypes.Rating) {
if (gt_op === '<' && val > 0) { // unset rating is considered as NULL
qb = qb.orWhereNull(field); if (gt_op === '<' && val > 0) {
qb = qb.orWhereNull(field);
}
} }
} }
break; break;
} }
case 'ge': case 'ge':
case 'gte': { case 'gte':
const ge_op = customWhereClause ? '<=' : '>='; {
qb = qb.where(field, ge_op, val); const ge_op = customWhereClause ? '<=' : '>=';
if (column.uidt === UITypes.Rating) { qb = qb.where(field, ge_op, val);
// unset rating is considered as NULL if (column.uidt === UITypes.Rating) {
if (ge_op === '<=' || (ge_op === '>=' && val === 0)) { // unset rating is considered as NULL
qb = qb.orWhereNull(field); if (ge_op === '<=' || (ge_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field);
}
} }
} }
break; break;
} }case 'lt':
case 'lt': { {
const lt_op = customWhereClause ? '>' : '<'; const lt_op = customWhereClause ? '>' : '<';
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
if (lt_op === '<' && val > 0) { if (lt_op === '<' && val > 0) {
qb = qb.orWhereNull(field); qb = qb.orWhereNull(field);
}
} }
} }
break; break;
} }
case 'le': case 'le':
case 'lte': { case 'lte':
const le_op = customWhereClause ? '>=' : '<='; {
qb = qb.where(field, le_op, val); const le_op = customWhereClause ? '>=' : '<=';
if (column.uidt === UITypes.Rating) { qb = qb.where(field, le_op, val);
// unset number is considered as NULL if (column.uidt === UITypes.Rating) {
if (le_op === '<=' || (le_op === '>=' && val === 0)) { // unset number is considered as NULL
qb = qb.orWhereNull(field); if (le_op === '<=' || (le_op === '>=' && val === 0)) {
qb = qb.orWhereNull(field);
}
} }
} }
break; break;

Loading…
Cancel
Save