Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ag-grid-mongo-query-builder

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ag-grid-mongo-query-builder - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

2

package.json
{
"name": "ag-grid-mongo-query-builder",
"version": "0.1.6",
"version": "0.1.7",
"description": "Utility to generate Mongo DB aggregation pipeline queries starting from AgGrid server side params",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,5 @@ //const mongoose = require('mongoose');

startRow,
endRow
endRow,
column=[],
quickFilter
} = reqBody;

@@ -23,2 +25,3 @@

const isFiltering = Object.keys(filterModel).length > 0;
const isQuickSearch = Object.keys(column).length > 0;
const isGrouping = rowGroupCols.length > 0 || 0;

@@ -30,2 +33,14 @@ const isSorting = sortModel.length > 0;

const filterQuery = isFiltering ? buildFilterQuery(filterModel) : [];
const quickSearchQuery = isQuickSearch && quickFilter ? buildQuickSearchQuery(column, quickFilter) : [];
let finalFilterQuery = [];
if(filterQuery.length > 0 && quickSearchQuery.length > 0) {
const quickSearch = {"$match" : { "$or" :[...quickSearchQuery] } };
finalFilterQuery = [quickSearch, ...filterQuery];
} else if(filterQuery.length > 0) {
finalFilterQuery = [...filterQuery];
} else if(quickSearchQuery.length > 0) {
finalFilterQuery = [{"$match" : {"$or" : [...quickSearchQuery]}}];
}
const groupQuery = isGrouping ? buildGroupingQuery(groupKeys, rowGroupCols, valueCols, pivotCols,pivotMode) : [];

@@ -38,5 +53,7 @@ const aggregationQuery = isAggregation ? buildAggregationQuery(valueCols) : [];

console.log('filter query :', JSON.stringify(filterQuery));
console.log('search query :', JSON.stringify(quickSearchQuery));
console.log('Group query:',JSON.stringify(groupQuery));
console.log('final filter query', JSON.stringify(finalFilterQuery));
const aggregationPipeline = [
...filterQuery,
...finalFilterQuery,
...groupQuery,

@@ -97,2 +114,20 @@ ...aggregationQuery,

function buildQuickSearchQuery(columns, searchVal) {
finalQuery = [];
columns.map(column => {
if(column.filter && column.filter == "agTextColumnFilter") {
finalQuery.push( { [column.field]: { "$regex": searchVal, "$options": "i" } });
} else if(column.filter && column.filter == "agSetColumnFilter") {
finalQuery.push( { [column.field]: { "$eq": searchVal}});
} else if(column.filter && column.filter == "agNumberColumnFilter") {
finalQuery.push( { [column.field]: { "$eq": parseInt(searchVal)}});
} else if(column.filter && column.filter == "agDateColumnFilter") {
if(moment(searchVal).isValid()) {
finalQuery.push({ "$and": [{ [column.field]: { "$gte": new Date(moment(searchVal).startOf('day')) } }, { [key]: { "$lte": new Date(moment(searchVal).endOf('day')) } }] });
}
}
});
return finalQuery;
}
function buildColumnQuery(columnModel, column){

@@ -168,3 +203,3 @@ const paramsKeys = Object.keys(columnModel);

case "equals": return { "$and": [{ [key]: { "$gte": new Date(moment(obj.dateFrom).startOf('day')) } }, { [key]: { "$lte": new Date(moment(obj.dateFrom).endOf('day')) } }] };
case "notEqual": return { "$not": [{ [key]: obj.dateFrom }] };
case "notEqual": return { "$ne": [{ [key]: obj.dateFrom }] };
case "lessThan": return { [key]: { "$lte": obj.dateFrom } };

@@ -171,0 +206,0 @@ case "greaterThan": return { [key]: { "$gte": obj.dateFrom } };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc