Browse Source

fix(nocodb): attachment filter logic

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
27f8e22e8d
  1. 27
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

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

@ -357,9 +357,16 @@ const parseConditionV2 = async (
break; break;
case 'like': case 'like':
if (!val) { if (!val) {
if (column.uidt === UITypes.Attachment) {
qb = qb
.orWhereNull(field)
.orWhere(field, '[]')
.orWhere(field, 'null');
} else {
// val is empty -> all values including empty strings but NULL // val is empty -> all values including empty strings but NULL
qb.where(field, ''); qb.where(field, '');
qb.orWhereNotNull(field); qb.orWhereNotNull(field);
}
} else { } else {
if (column.uidt === UITypes.Formula) { if (column.uidt === UITypes.Formula) {
[field, val] = [val, field]; [field, val] = [val, field];
@ -377,9 +384,15 @@ const parseConditionV2 = async (
break; break;
case 'nlike': case 'nlike':
if (!val) { if (!val) {
if (column.uidt === UITypes.Attachment) {
qb.whereNot(field, '')
.whereNot(field, 'null')
.whereNot(field, '[]');
} else {
// val is empty -> all values including NULL but empty strings // val is empty -> all values including NULL but empty strings
qb.whereNot(field, ''); qb.whereNot(field, '');
qb.orWhereNull(field); qb.orWhereNull(field);
}
} else { } else {
if (column.uidt === UITypes.Formula) { if (column.uidt === UITypes.Formula) {
[field, val] = [val, field]; [field, val] = [val, field];
@ -540,12 +553,26 @@ const parseConditionV2 = async (
qb = qb.whereNotNull(customWhereClause || field); qb = qb.whereNotNull(customWhereClause || field);
break; break;
case 'blank': case 'blank':
if (column.uidt === UITypes.Attachment) {
qb = qb
.whereNull(customWhereClause || field)
.orWhere(field, '[]')
.orWhere(field, 'null');
} else {
qb = qb.whereNull(customWhereClause || field).orWhere(field, ''); qb = qb.whereNull(customWhereClause || field).orWhere(field, '');
}
break; break;
case 'notblank': case 'notblank':
if (column.uidt === UITypes.Attachment) {
qb = qb
.whereNotNull(customWhereClause || field)
.whereNot(field, '[]')
.whereNot(field, 'null');
} else {
qb = qb qb = qb
.whereNotNull(customWhereClause || field) .whereNotNull(customWhereClause || field)
.whereNot(field, ''); .whereNot(field, '');
}
break; break;
case 'checked': case 'checked':
qb = qb.where(customWhereClause || field, true); qb = qb.where(customWhereClause || field, true);

Loading…
Cancel
Save