@ptc-org/nestjs-query-core
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
{ | ||
"name": "@ptc-org/nestjs-query-core", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"description": "Base query package", | ||
@@ -5,0 +5,0 @@ "author": "doug-martin <doug@dougamartin.com>", |
@@ -74,3 +74,7 @@ "use strict"; | ||
const getFilterComparisons = (filter, key) => { | ||
let results = []; | ||
const results = []; | ||
if (filter.and || filter.or) { | ||
const filters = [...(filter.and ?? []), ...(filter.or ?? [])]; | ||
filters.forEach((f) => (0, exports.getFilterComparisons)(f, key).forEach((comparison) => results.push(comparison))); | ||
} | ||
const comparison = (0, exports.getFilterFieldComparison)(filter, key); | ||
@@ -80,23 +84,41 @@ if ((0, exports.isComparison)(comparison)) { | ||
} | ||
else if (Array.isArray(filter)) { | ||
filter.forEach((f) => { | ||
results = results.concat((0, exports.getFilterComparisons)(f, key)); | ||
}); | ||
} | ||
if (typeof filter === 'object') { | ||
Object.keys(filter).forEach((subFilterKey) => { | ||
const subFilter = filter[subFilterKey]; | ||
if (subFilterKey === key) { | ||
results.push(subFilter); | ||
} | ||
else { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
results = results.concat((0, exports.getFilterComparisons)(subFilter, key)); | ||
} | ||
}); | ||
} | ||
return [...results]; | ||
}; | ||
exports.getFilterComparisons = getFilterComparisons; | ||
/* | ||
getFilterComparisons only returns the first layer, this one will return everything, it only returns the same | ||
item multiple times, that needs to be fixed first | ||
*/ | ||
// export const getDeepFilterComparisons = <DTO, K extends keyof FilterComparisons<DTO>>( | ||
// filter: Filter<DTO>, | ||
// key: K | ||
// ): FilterFieldComparison<DTO[K]>[] => { | ||
// let results: FilterFieldComparison<DTO[K]>[] = []; | ||
// | ||
// const comparison = getFilterFieldComparison(filter as FilterComparisons<DTO>, key); | ||
// if (isComparison(comparison)) { | ||
// results.push(comparison); | ||
// | ||
// } else if (Array.isArray(filter)) { | ||
// filter.forEach((f: Filter<DTO>) => { | ||
// results = results.concat(getFilterComparisons(f, key)); | ||
// }); | ||
// } | ||
// | ||
// if (typeof filter === 'object') { | ||
// Object.keys(filter).forEach((subFilterKey) => { | ||
// const subFilter = filter[subFilterKey] as FilterFieldComparison<DTO[K]>; | ||
// | ||
// if (subFilterKey === key) { | ||
// results.push(subFilter); | ||
// } else { | ||
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// // @ts-ignore | ||
// results = results.concat(getFilterComparisons(subFilter, key)); | ||
// } | ||
// }); | ||
// } | ||
// | ||
// return [...results]; | ||
// }; | ||
const getFilterOmitting = (filter, ...keys) => Object.keys(filter).reduce((f, next) => { | ||
@@ -103,0 +125,0 @@ const omitted = { ...f }; |
Sorry, the diff of this file is not supported yet
194579
2797