Socket
Socket
Sign inDemoInstall

ag-grid-mongo-query-builder

Package Overview
Dependencies
0
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.6

6

index.js

@@ -1,5 +0,9 @@

const {buildQuery} = require('./queryBuilder.js');
const {buildQuery, buildCountQuery} = require('./queryBuilder.js');
module.exports.buildQuery = function(params){
return buildQuery(params);
}
module.exports.buildCountQuery = function(params) {
return buildCountQuery(params);
}

2

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

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

//const mongoose = require('mongoose');
// const ObjectID = require('mongodb').ObjectID;
const moment = require('moment');
const buildQuery = function (reqBody) {

@@ -49,2 +51,38 @@ let {

const buildCountQuery = function (reqBody) {
let {
groupKeys = [], // holds the ID of the expanded node and the ID's of all its parent/grandparent node
rowGroupCols = [],
filterModel = {}, //values being filtered in UI
valueCols = [] , // required for aggregation
pivotCols= [],
pivotMode
} = reqBody;
console.log('params in count API :', { groupKeys, rowGroupCols, pivotCols, pivotMode, filterModel, valueCols});
const isFiltering = Object.keys(filterModel).length > 0;
const isGrouping = rowGroupCols.length > 0 || 0;
const isAggregation = valueCols.length > 0 || 0;
const filterQuery = isFiltering ? buildFilterQuery(filterModel) : [];
const groupQuery = isGrouping ? buildGroupingQuery(groupKeys, rowGroupCols, valueCols, pivotCols,pivotMode) : [];
const aggregationQuery = isAggregation ? buildAggregationQuery(valueCols) : [];
const countQuery = {$count: "totalRows"};
console.log('filter query :', JSON.stringify(filterQuery));
console.log('Group query:',JSON.stringify(groupQuery));
const aggregationPipeline = [
...filterQuery,
...groupQuery,
...aggregationQuery,
countQuery
].filter(stage => !!stage)
console.log('Final pipeline: ', JSON.stringify(aggregationPipeline))
return aggregationPipeline;
}
function buildFilterQuery(filterModel) {

@@ -117,8 +155,15 @@ const columns = Object.keys(filterModel);

if(obj.dateFrom) {
obj.dateFrom = new Date(obj.dateFrom);
}
if(obj.dateTo) {
obj.dateTo = new Date(obj.dateTo);
}
switch (obj.type) {
case "equals": return { [key]: obj.filter };
case "notEqual": return { "$not": [{ [key]: obj.filter }] };
case "lessThan": return { [key]: { "$lt": obj.filter } };
case "greaterThan": return { [key]: { "$gt": obj.filter } };
case "inRange": return { "$and": [{ [key]: { "$lt": obj.lt } }, { [key]: { "$gt": obj.gt } }] };
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 "lessThan": return { [key]: { "$lte": obj.dateFrom } };
case "greaterThan": return { [key]: { "$gte": obj.dateFrom } };
case "inRange": return { "$and": [{ [key]: { "$gte": obj.dateFrom } }, { [key]: { "$lte": obj.dateTo } }] };
default: return { [key]: obj };

@@ -350,4 +395,5 @@ }

module.exports.buildQuery=buildQuery;
module.exports.buildCountQuery=buildCountQuery;
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc