From 877115545a07e9675d528c0a63b1a4e4db5a2d24 Mon Sep 17 00:00:00 2001 From: Leonardo Viva Date: Mon, 15 Apr 2024 11:23:32 -0300 Subject: [PATCH] fix: find by lookup --- src/imports/data/data.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/imports/data/data.js b/src/imports/data/data.js index 030bd79..afdcc12 100644 --- a/src/imports/data/data.js +++ b/src/imports/data/data.js @@ -502,7 +502,7 @@ export async function findById({ authTokenId, document, fields, dataId, withDeta @param useChangeUserFilter */ -export async function findByLookup({ authTokenId, document, field, search, extraFilter, start, limit, useChangeUserFilter }) { +export async function findByLookup({ authTokenId, document, field: fieldName, search, extraFilter, start, limit, useChangeUserFilter }) { const { success, data: user, errors } = await getUserSafe(authTokenId); if (success === false) { return errorReturn(errors); @@ -518,21 +518,21 @@ export async function findByLookup({ authTokenId, document, field, search, extra return errorReturn(`[${document}] Document not found`); } - const fieldObject = metaObject.fields[field]; - if (fieldObject == null) { + const field = metaObject.fields[fieldName]; + if (field == null) { return errorReturn(`[${document}] Field not found`); } - if (fieldObject.type !== 'lookup') { + if (field.type !== 'lookup') { return errorReturn(`[${document}] Field is not a lookup`); } - const lookupMetaObject = MetaObject.Meta[fieldObject.document]; + const lookupMetaObject = MetaObject.Meta[field.document]; if (lookupMetaObject == null) { return errorReturn(`[${document}] Lookup document not found`); } - const lookupCollection = MetaObject.Collections[fieldObject.document]; + const lookupCollection = MetaObject.Collections[field.document]; if (lookupCollection == null) { return errorReturn(`[${document}] Lookup collection not found`); } @@ -543,8 +543,8 @@ export async function findByLookup({ authTokenId, document, field, search, extra const lookupSort = {}; const descriptionFieldsQuery = {}; - if (isArray(fieldObject.descriptionFields)) { - const descriptionFields = fieldObject.descriptionFields.concat(fieldObject.searchableFields ?? []); + if (isArray(field.descriptionFields)) { + const descriptionFields = field.descriptionFields.concat(field.searchableFields ?? []); let sortArrayField = false;