@konplit-services/common 1.7.5 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,9 @@ export interface FilterOptions {
30
30
  merchantId?: string;
31
31
  accountId?: string;
32
32
  dateField?: string;
33
+ amountField?: string;
34
+ min_amount?: string;
35
+ max_amount?: string;
33
36
  [key: string]: any;
34
37
  }
35
38
  export declare const generateQueryObject: (filters: FilterOptions, searchesFieldNames?: string[], select?: string | Record<string, any>, populate?: (string | PopulateOptions)[]) => {
@@ -50,4 +53,6 @@ export interface DefaultFilterOptions {
50
53
  order?: "asc" | "desc";
51
54
  from?: string;
52
55
  to?: string;
56
+ min_amount?: string;
57
+ max_amount?: string;
53
58
  }
@@ -55,7 +55,7 @@ function paginate(model_1) {
55
55
  });
56
56
  }
57
57
  const generateQueryObject = (filters, searchesFieldNames = [], select = "", populate = []) => {
58
- const { status, limit, page, sort_by = "createdAt", order = "desc", merchantId, accountId, dateField, } = filters;
58
+ const { status, limit, page, sort_by = "createdAt", order = "desc", merchantId, accountId, dateField, amountField, } = filters;
59
59
  const excludes = [
60
60
  "status",
61
61
  "from",
@@ -67,7 +67,10 @@ const generateQueryObject = (filters, searchesFieldNames = [], select = "", popu
67
67
  "accountId",
68
68
  "merchantId",
69
69
  "order",
70
- "dateField"
70
+ "dateField",
71
+ "amountField",
72
+ "min_amount",
73
+ "max_amount",
71
74
  ];
72
75
  const query = {};
73
76
  let sort = {};
@@ -110,6 +113,17 @@ const generateQueryObject = (filters, searchesFieldNames = [], select = "", popu
110
113
  $gte: (0, date_processing_1.convertDateToUTC)(filters.from),
111
114
  };
112
115
  }
116
+ // for dynamic amount range filter
117
+ const fieldAmountFilter = amountField || "amount";
118
+ const min = Number(filters.min_amount);
119
+ const max = Number(filters.max_amount);
120
+ if (!isNaN(min) || !isNaN(max)) {
121
+ query[fieldAmountFilter] = {};
122
+ if (!isNaN(min))
123
+ query[fieldAmountFilter]["$gte"] = min;
124
+ if (!isNaN(max))
125
+ query[fieldAmountFilter]["$lte"] = max;
126
+ }
113
127
  if (filters.sort_by && filters.order) {
114
128
  const newSory = {
115
129
  [sort_by]: order === "asc" ? "asc" : "desc",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.7.5",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",