From 8c24ab2b0d62f7dbe14409dc4fc47240bf5d5ca3 Mon Sep 17 00:00:00 2001 From: Priyanka Pradeep Date: Fri, 11 Mar 2022 17:16:12 +0530 Subject: [PATCH] search in parent entity --- controllers/v1/observationsController.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/controllers/v1/observationsController.js b/controllers/v1/observationsController.js index 9de58237..b6f69b62 100644 --- a/controllers/v1/observationsController.js +++ b/controllers/v1/observationsController.js @@ -634,9 +634,21 @@ module.exports = class Observations extends Abstract { let entityType = entitiesHelper.entitiesSchemaData().SCHEMA_ENTITY_GROUP+"."+result.entityType; - let entitiesData = await entitiesHelper.entityDocuments({ - _id:req.query.parentEntityId - }, [ + let queryObject = { + _id : req.query.parentEntityId + }; + + if ( req.searchText && req.searchText != "" ) { + + queryObject["$or"] = [ + { "metaInformation.name": new RegExp(req.searchText, 'i') }, + { "metaInformation.externalId": new RegExp("^" + req.searchText, 'm') }, + { "metaInformation.addressLine1": new RegExp(req.searchText, 'i') }, + { "metaInformation.addressLine2": new RegExp(req.searchText, 'i') } + ]; + } + + let entitiesData = await entitiesHelper.entityDocuments(queryObject, [ entityType, "entityType", "metaInformation.name",