(
params: LogFilterParams,
options: BuildFilterConditionsOptions = {}
)
| 266 | * @returns Combined SQL condition or undefined if no filters |
| 267 | */ |
| 268 | export function buildFilterConditions( |
| 269 | params: LogFilterParams, |
| 270 | options: BuildFilterConditionsOptions = {} |
| 271 | ): SQL | undefined { |
| 272 | const { useSimpleLevelFilter = true } = options |
| 273 | const conditions: SQL[] = [] |
| 274 | |
| 275 | if (useSimpleLevelFilter && params.level) { |
| 276 | const levelCondition = buildSimpleLevelCondition(params.level) |
| 277 | if (levelCondition) conditions.push(levelCondition) |
| 278 | } |
| 279 | |
| 280 | if (params.workflowIds) { |
| 281 | const condition = buildWorkflowIdsCondition(params.workflowIds) |
| 282 | if (condition) conditions.push(condition) |
| 283 | } |
| 284 | |
| 285 | if (params.folderIds) { |
| 286 | const condition = buildFolderIdsCondition(params.folderIds) |
| 287 | if (condition) conditions.push(condition) |
| 288 | } |
| 289 | |
| 290 | if (params.triggers) { |
| 291 | const condition = buildTriggersCondition(params.triggers) |
| 292 | if (condition) conditions.push(condition) |
| 293 | } |
| 294 | |
| 295 | const { startCondition, endCondition } = buildDateConditions(params.startDate, params.endDate) |
| 296 | if (startCondition) conditions.push(startCondition) |
| 297 | if (endCondition) conditions.push(endCondition) |
| 298 | |
| 299 | const searchConditions = buildSearchConditions({ |
| 300 | search: params.search, |
| 301 | workflowName: params.workflowName, |
| 302 | folderName: params.folderName, |
| 303 | executionId: params.executionId, |
| 304 | }) |
| 305 | conditions.push(...searchConditions) |
| 306 | |
| 307 | if (params.costOperator && params.costValue !== undefined) { |
| 308 | conditions.push(buildCostCondition(params.costOperator, params.costValue)) |
| 309 | } |
| 310 | |
| 311 | if (params.durationOperator && params.durationValue !== undefined) { |
| 312 | const condition = buildDurationCondition(params.durationOperator, params.durationValue) |
| 313 | if (condition) conditions.push(condition) |
| 314 | } |
| 315 | |
| 316 | if (conditions.length === 0) return undefined |
| 317 | if (conditions.length === 1) return conditions[0] |
| 318 | return and(...conditions) |
| 319 | } |
no test coverage detected