Explorar o código

rtk_tree_view_clear_

Gennadysht hai 1 ano
pai
achega
21a4d4fb37
Modificáronse 1 ficheiros con 30 adicións e 0 borrados
  1. 30 0
      src/utills/gqlUtils.js

+ 30 - 0
src/utills/gqlUtils.js

@@ -0,0 +1,30 @@
+const createQuery = (searchStr, searchFieldNames) => {
+    let result = [];
+    if (searchStr) {
+        for (let searchFieldName of searchFieldNames) {
+            result.push({ [searchFieldName]: searchFieldName === '_id' ? searchStr : `/${searchStr}/` });
+        }
+    }
+    return result.length === 0 ? {} :  { $or: result };
+}
+
+const createQueryExt = (searchQuery = {}, queryExt = {}) => {
+    if (!queryExt)
+        return searchQuery;
+    return { $and: [searchQuery, queryExt] };
+}
+
+const createQueryPaging = (fromPage, pageSize, sort) => {
+    let result = {};
+    if (fromPage !== undefined && pageSize !== undefined) {
+        result["skip"] = [fromPage * pageSize];
+        result["limit"] = [pageSize];
+    }
+    if (sort)
+        result["sort"] = [sort];
+    return result;
+}
+
+export const createFullQuery = ({ searchStr, searchFieldNames, queryExt = {} }, { fromPage, pageSize, sort } = {}) => {
+    return { q: JSON.stringify([createQueryExt(createQuery(searchStr, searchFieldNames), queryExt), createQueryPaging(fromPage, pageSize, sort)]) };
+}