This commit is contained in:
Narul Hidayah
2026-01-02 17:50:45 +07:00
parent 35f24c2a5d
commit 80d26905d5
4 changed files with 77 additions and 44 deletions

View File

@ -81,32 +81,41 @@ export default class CommonHelper {
let fr = param.filter[p]
if (p != 'any') {
// Map property names to database column names
// TypeORM uses camelCase for property names, but database uses snake_case
// For foreign keys, we need to use the actual database column name
let columnName = p;
// If it contains underscore, it's already snake_case, use it with quotes for PostgreSQL
if (p.includes('_')) {
columnName = '"' + p + '"';
}
if (!validate(f)) {
let found = false;
if (fr['from']) {
whereAttrPre.push(p + " >= :" + p + '_from');
whereAttrPre.push(columnName + " >= :" + p + '_from');
whereVal[p + '_from'] = fr['from'];
found = true;
}
if (fr['to']) {
whereAttrPre.push(p + " <= :" + p + '_to');
whereAttrPre.push(columnName + " <= :" + p + '_to');
whereVal[p + '_to'] = fr['to'];
found = true;
}
if (fr['like']) {
whereAttrPre.push('LOWER(' + p + ') like :' + p + '_like');
whereAttrPre.push('LOWER(' + columnName + ') like :' + p + '_like');
whereVal[p + '_like'] = '%' + fr['like'].toLowerCase() + '%';;
found = true;
}
if (!found) {
whereAttrPre.push("LOWER(" + p + ") = :" + p);
whereAttrPre.push("LOWER(" + columnName + ") = :" + p);
f = f.toLowerCase();
whereVal[p] = f;
}
} else {//uuid only
whereAttrPre.push(p + " = :" + p);
whereAttrPre.push(columnName + " = :" + p);
whereVal[p] = f;
}
} else {