UNPKG

n8n-nodes-arubacentralnextgen

Version:

n8n community node for Aruba Central NextGen API integration with modern monitoring and management capabilities

58 lines (57 loc) 2.45 kB
"use strict"; // helpers/filterBuilder.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.buildODataFilter = buildODataFilter; /** * Builds an OData filter string from a key-value object * @param filters Object containing filter field-value pairs * @returns OData-compatible filter string */ function buildODataFilter(filters) { const expressions = []; for (const [field, value] of Object.entries(filters)) { if (value === undefined || value === '') continue; if (Array.isArray(value)) { if (value.length === 0) continue; // Handle arrays with 'in' operator const values = value.map((v) => (typeof v === 'string' ? `'${v}'` : v)); expressions.push(`${field} in (${values.join(',')})`); } else if (typeof value === 'object' && value !== null) { // Handle complex operators like 'contains', 'startswith', etc. const operator = value.operator || 'eq'; const operatorValue = value.value; if (operatorValue === undefined || operatorValue === '') continue; switch (operator) { case 'contains': expressions.push(`contains(${field}, '${operatorValue}')`); break; case 'startswith': expressions.push(`startswith(${field}, '${operatorValue}')`); break; case 'endswith': expressions.push(`endswith(${field}, '${operatorValue}')`); break; case 'gt': case 'ge': case 'lt': case 'le': expressions.push(`${field} ${operator} ${operatorValue}`); break; case 'ne': expressions.push(`${field} ne ${typeof operatorValue === 'string' ? `'${operatorValue}'` : operatorValue}`); break; default: expressions.push(`${field} eq ${typeof operatorValue === 'string' ? `'${operatorValue}'` : operatorValue}`); } } else { // Handle simple equality for strings and other types expressions.push(`${field} eq ${typeof value === 'string' ? `'${value}'` : value}`); } } return expressions.length ? expressions.join(' and ') : ''; }