From db134cc5ae17ed8d3c5c836a37750b6803c46c95 Mon Sep 17 00:00:00 2001 From: gutembergsa Date: Tue, 17 Sep 2024 21:44:11 -0300 Subject: [PATCH 1/2] fix: filter reference to pointer fields --- src/lib/Filters.js | 31 +++++++++++++++++++++---------- src/lib/queryFromFilters.js | 25 +++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/lib/Filters.js b/src/lib/Filters.js index 9b394e467d..fe0013938c 100644 --- a/src/lib/Filters.js +++ b/src/lib/Filters.js @@ -233,7 +233,7 @@ export function availableFilters(schema, currentFilters, blacklist) { return available; } -export function findRelatedClasses(referClass , allClasses, blacklist, currentFilters) { +export function findRelatedClasses(referClass, allClasses, blacklist, currentFilters) { const relatedClasses = {}; if (allClasses[referClass]) { const availableForRefer = availableFilters(allClasses[referClass], currentFilters, blacklist); @@ -243,31 +243,42 @@ export function findRelatedClasses(referClass , allClasses, blacklist, currentFi } for (const className in allClasses) { - if (className === referClass){ + if (className === referClass) { continue; } - if (!checkRelation(referClass, allClasses[className])) { + if (!checkRelation(referClass, allClasses, className)) { continue; } + const schema = allClasses[className]; const available = availableFilters(schema, currentFilters, blacklist); if (Object.keys(available).length > 0) { relatedClasses[className] = available; } } - return relatedClasses; } -function checkRelation(classname,schema){ - for (const col in schema) { - if (schema[col].type === 'Pointer' && schema[col].targetClass === classname) { - return true; +const checkRelationHelper = (schema, col, className) => + schema[col].type === 'Pointer' && schema[col].targetClass === className; + +function checkRelation(currentClassname, schemas, classToReferName) { + const currentClassSchema = schemas[currentClassname]; + const classSchemaBeingCheckedToRefer = schemas[classToReferName]; + let flag = false; + + for (const col in currentClassSchema) { + if (checkRelationHelper(currentClassSchema, col, classToReferName)) { + flag = true; } } - return false; - + for (const col in classSchemaBeingCheckedToRefer) { + if (checkRelationHelper(classSchemaBeingCheckedToRefer, col, currentClassname)) { + flag = true; + } + } + return flag; } export const BLACKLISTED_FILTERS = ['containsAny', 'doesNotContainAny']; diff --git a/src/lib/queryFromFilters.js b/src/lib/queryFromFilters.js index 17772cd831..d6b46ffc40 100644 --- a/src/lib/queryFromFilters.js +++ b/src/lib/queryFromFilters.js @@ -8,6 +8,8 @@ import Parse from 'parse'; export default async function queryFromFilters(className, filters) { + // // eslint-disable-next-line no-debugger + // debugger; let primaryQuery; const querieslist = []; if (typeof className === 'string') { @@ -42,17 +44,20 @@ export default async function queryFromFilters(className, filters) { } const reversePointerField = getPointerField(allClassesSchema, filterClassName, className); const pointerField = getPointerField(allClassesSchema, className, filterClassName); - if (pointerField) { - tempquery.matchesQuery(pointerField, queries[filterClassName]); - } else if (reversePointerField) { - await tempquery.matchesKeyInQuery( - 'objectId', - `${reversePointerField}.objectId`, - queries[filterClassName] - ) - querieslist.push(tempquery); - } else { + if (!pointerField && !reversePointerField) { console.warn(`No relationship found between ${className} and ${filterClassName}`); + } else { + if (pointerField) { + tempquery.matchesQuery(pointerField, queries[filterClassName]); + } + if (!pointerField && reversePointerField) { + await tempquery.matchesKeyInQuery( + 'objectId', + `${reversePointerField}.objectId`, + queries[filterClassName] + ); + } + querieslist.push(tempquery); } }) ); From 510f2d8b1b31ccd9e51f6256a6212a189c267192 Mon Sep 17 00:00:00 2001 From: gutembergsa Date: Wed, 18 Sep 2024 10:24:17 -0300 Subject: [PATCH 2/2] chore: remove comments --- src/lib/queryFromFilters.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/queryFromFilters.js b/src/lib/queryFromFilters.js index d6b46ffc40..047d69cad2 100644 --- a/src/lib/queryFromFilters.js +++ b/src/lib/queryFromFilters.js @@ -8,8 +8,6 @@ import Parse from 'parse'; export default async function queryFromFilters(className, filters) { - // // eslint-disable-next-line no-debugger - // debugger; let primaryQuery; const querieslist = []; if (typeof className === 'string') {