From a66a389d81ca83c0c0c79ed74d95b57349aff220 Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Thu, 2 Jan 2025 19:29:25 +0700 Subject: [PATCH] add function handler filter from to and etc --- src/helpers/common.ts | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/helpers/common.ts b/src/helpers/common.ts index 8f77db8..c1b725a 100644 --- a/src/helpers/common.ts +++ b/src/helpers/common.ts @@ -106,16 +106,32 @@ export default class CommonHelper { for (let p in param.filter) { let f = String(param.filter[p]) + let fr = param.filter[p] if (p != 'any') { if (!validate(f)) { - whereAttrPre.push("LOWER(" + p + ") = :" + p); - f = f.toLowerCase(); - } else { - whereAttrPre.push(p + " = :" + p); - } + let found = false; + if (fr['from']) { + whereAttrPre.push(p + " >= :" + p + '_from'); + whereVal[p + '_from'] = fr['from']; + found = true; + } + if (fr['to']) { + whereAttrPre.push(p + " <= :" + p + '_to'); + whereVal[p + '_to'] = fr['to']; + found = true; + } - whereVal[p] = f; + if (!found) { + whereAttrPre.push("LOWER(" + p + ") = :" + p); + f = f.toLowerCase(); + + whereVal[p] = f; + } + } else {//uuid only + whereAttrPre.push(p + " = :" + p); + whereVal[p] = f; + } } else { filter_any = true; filter_any_val = f; @@ -149,10 +165,10 @@ export default class CommonHelper { } if (param.col_any_eq.length > 0) { - whereVal['filter_eq'] = filter_any_val.toLowerCase(); + whereVal['filter_eq'] = filter_any_val; } if (param.col_any_like.length > 0) { - whereVal['filter_like'] = '%' + filter_any_val.toLowerCase() + '%'; + whereVal['filter_like'] = '%' + filter_any_val + '%'; } } } catch (e: any) { @@ -186,7 +202,7 @@ export default class CommonHelper { whereVal['filter_eq'] = param.filter.toLowerCase(); } if (param.col_any_like.length > 0) { - whereVal['filter_like'] = '%' + param.filter.toLowerCase() + '%'; + whereVal['filter_like'] = '%' + param.filter + '%'; } }