Selaa lähdekoodia

rtk_tree_view_clear_

Gennadysht 1 vuosi sitten
vanhempi
commit
21a4d4fb37
1 muutettua tiedostoa jossa 30 lisäystä ja 0 poistoa
  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)]) };
+}