From 13e5b816236236ce2bf73a7179f0ea5b51ae6703 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Fri, 27 Nov 2020 10:10:06 +0100
Subject: [PATCH] fix: search issue

---
 src/structures/structures.service.ts | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/structures/structures.service.ts b/src/structures/structures.service.ts
index 477324a4d..7c9b02198 100644
--- a/src/structures/structures.service.ts
+++ b/src/structures/structures.service.ts
@@ -20,15 +20,15 @@ export class StructuresService {
   }
 
   public async search(searchString: string, filters?: Array<any>): Promise<Structure[]> {
-    let query: any;
     if (searchString && filters) {
-      query = [...this.parseFilter(filters), { $text: { $search: searchString } }];
+      return this.structureModel
+        .find({ $and: [...this.parseFilter(filters), { $text: { $search: searchString } }] })
+        .exec();
     } else if (filters) {
-      query = this.parseFilter(filters);
+      return this.structureModel.find({ $or: this.parseFilter(filters) }).exec();
     } else {
-      query = [{ $text: { $search: searchString } }];
+      return this.structureModel.find({ $or: [{ $text: { $search: searchString } }] }).exec();
     }
-    return this.structureModel.find({ $or: query }).exec();
   }
 
   /**
-- 
GitLab