feat: refactor if statements

This commit is contained in:
Caio Carvalho 2024-11-21 00:41:11 -03:00
parent 5ca87ddab8
commit d99b8227c9

View File

@ -70,25 +70,18 @@ async function relationalQuery(
(pv, cv, i) => { (pv, cv, i) => {
const levelNumber = i + 1; const levelNumber = i + 1;
const startSum = i > 0 ? 'union ' : ''; const startSum = i > 0 ? 'union ' : '';
const column = cv.type === 'url' ? 'url_path' : 'event_name'; const isURL = cv.type === 'url';
const column = isURL ? 'url_path' : 'event_name';
let operator: string; let operator = '=';
let paramValue: string; let paramValue = cv.value;
if (cv.type === 'url') { if (isURL && cv.value.includes('*')) {
if (cv.value.includes('*')) {
operator = '~'; operator = '~';
paramValue = cv.value.replace(/\*/g, '.*'); paramValue = cv.value.replace(/\*/g, '.*');
} else if (cv.value.endsWith('*')) { } else if (isURL && cv.value.endsWith('*')) {
operator = 'like'; operator = 'like';
paramValue = cv.value.replace('*', '%'); paramValue = cv.value.replace('*', '%');
} else {
operator = '=';
paramValue = cv.value;
}
} else {
operator = '=';
paramValue = cv.value;
} }
if (levelNumber === 1) { if (levelNumber === 1) {